Filter Loot Assistant with coordinates list(s)

DeletedUser107279

Guest
Hello Tribal people,

I am looking for a script or tool that would allow me to filter Loot Assistant's target by using a list of coordinates in order to help with time-based farming. Does such a tool exist? If it does not, would it be legal?

Thanks,
Niko
 

DeletedUser118875

Guest
There is a rule in place about scripts not being allowed allowed to interact with Loot Assistant without prior approval:
From rule #7: "... may not interact with the Farm Assistant without specific approval from the Tribal Wars team."​

However, I cannot imagine filtering would be rejected, especially if it is not interacting with the sending buttons on your behalf.

That said, what in particular are you looking for? Just giving the script a list of allowed or disallowed coordinates and then only showing or hiding the reports for the listed villages? If so, I'd be happy to make that for you real quick. (Shouldn't take long.)
 

DeletedUser107279

Guest
Thanks for the reply my little ghost! :)

That is exactly what I'm looking for! Something along the likes of, I put these coordinates in a text box : 111|222 333|444 555|666 and when I check a checkbox, they are the only 3 barbs I see in the loot assistant. Even better would be to have the ability of saving a few lists and choosing which one to use as a filter, but even one saved setup would be seriously amazing.

Let me know, if you want I can check in with mods about the legality of it, but as you said I don't think it is that different of other LA filters, tho this one would seriously let me step up my farming, I always take a hit on my farming stats when everyone turns into barbs

Thank you so much
Niko
 

DeletedUser118875

Guest
Thanks for the reply my little ghost! :)

That is exactly what I'm looking for! Something along the likes of, I put these coordinates in a text box : 111|222 333|444 555|666 and when I check a checkbox, they are the only 3 barbs I see in the loot assistant. Even better would be to have the ability of saving a few lists and choosing which one to use as a filter, but even one saved setup would be seriously amazing.

Let me know, if you want I can check in with mods about the legality of it, but as you said I don't think it is that different of other LA filters, tho this one would seriously let me step up my farming, I always take a hit on my farming stats when everyone turns into barbs

Thank you so much
Niko

Give the following a try:
Code:
javascript:var mode = 'whitelist';
/*
Modes: whitelist or blacklist.
    Whitelist = only specified coordinates allowed.
    Blacklist = coordinates specified are not allowed, but all others are allowed.
*/
var bOverrideOtherShowAndHides=false;
var iMode;
mode = mode.toLowerCase().trim();
if(mode.indexOf('white')>=0){
    iMode = 1;
}else{
    /* Black list */
    iMode = 0xb1ac;
}
if(game_data.screen !== 'am_farm'){
    UI.ErrorMessage('Script must run from Loot Assistant page!');
    void 0;
}else if(window._FilterIsInitialized){
    void 0;
}
window._FilterIsInitialized=!0;
var filter_coordinates='';
window.LoadAllCoordinates = function(){
    var presets = window.localStorage.getItem("LA_FilterSettings");
    if(presets === null){
        presets = {Default:""};
    }else{
        try{
            presets = JSON.parse(presets);
        }catch(e){
            alert("The saved preset filters are corrupted! Cannot load.");
            presets = {Default: ""};
        }
    }
    return presets;
}
var presetFilters = window.LoadAllCoordinates();
window.ConvertToCombo = function(){
    var optionNames = Object.getOwnPropertyNames(presetFilters),out="";
    for(var i=0;i<optionNames.length;i++){
        var bSelected=!1;
        if(optionNames[i] === 'Default'){
            bSelected=!0;
        }
        var htmlSafeName = $("<div/>").text(optionNames[i]).html();
        out+="<option value='" + htmlSafeName + "'"+(bSelected?" selected":"")+">"+htmlSafeName+"</option>"
    }
    return out;
}

window.UpdateSelectedPreset = function(){
    var presetName = $("#FilterPresets").val();
    filter_coordinates=$("#coordinates").val().trim();
    presetFilters[presetName]=filter_coordinates;
    window.Persist();
}

window.SaveAsPreset=function(){
    var name=prompt("What should we name this preset?", "").trim(),bDoUpdate=false;
    while(presetFilters[name] && !bDoUpdate){
        bDoUpdate = confirm("This name already exists as a preset. Saving using this name will overwrite the existing preset with this name. Continue and overwrite?");
        if(bDoUpdate)
            break;
        else
            name = prompt("What should we name this preset?", "").trim();
    }
    presetFilters[name]=$("#coordinates").val().trim();
    window.Persist();
    $("#FilterPresets").html(window.ConvertToCombo());
}

window.Persist=function(){
    window.localStorage.setItem("LA_FilterSettings", JSON.stringify(presetFilters));
}

window.LoadPreset=function(failQuiet){
    var presetName = $("#FilterPresets").val();
    if(presetName && typeof presetFilters[presetName] == 'string'){
        $("#coordinates").val(presetFilters[presetName]);
    }else if(!failQuiet){
        alert("You must select a preset to load it.");
    }
}

window.DeletePreset=function(){
    var presetName = $("#FilterPresets").val();
    if(presetName !== 'Default'){
        try{
            delete presetFilters[presetName];
        }catch(e){}
    }else{
        presetFilters['Default']='';
    }
    window.Persist();
    $("#FilterPresets").html(window.ConvertToCombo());
}

window.ShowHideBtnCallback = function (){
    filter_coordinates = $("#coordinates").val();
    var allRows = $("tr[id^='village_'][class*='report_'][class*='row_']");
    allRows.each(function() {
        var jq = $(this),
            cells = jq.find('td'),
            cell = null;
        for (var i = 0; i < cells.length; i++) {
            if (cells.eq(i).text().search(/\(\d{2,3}\|\d{2,3}\)/) >= 0) {
                cell = cells.eq(i);
                break;
            }
        }
        if (cell !== null){
            var coordMatch = cell.text().match(/\((\d{2,3}\|\d{2,3})\)/);
            if(!coordMatch || coordMatch.length<2)
                return;
        
            var matchedCoord = coordMatch[1];
            var regSuitableCoord = '(^|\\s)' + matchedCoord.replace(/\|/gm, '\\|') + '(\\s|$)';
            var reggie = new RegExp(regSuitableCoord, 'gmi');
            var bCoordInList = filter_coordinates.search(reggie)>=0;
            if(iMode===1 && !bCoordInList) {
                /* White - only show listed coordinates. */
                jq.hide();
            }else if(bCoordInList && iMode===0xb1ac){
                /* Black - hide coordinates in list. */
                jq.hide();
            }else if(bOverrideOtherShowAndHides){
                jq.show();
            }
        }
    });
}

var htmlInsertBox = "<div class='vis'><h4>Farmable Village Filter List</h4><div style='padding:5px;'><textarea id='coordinates' style='width:90%;height:100px;margin:5px;'></textarea><br><button onclick='window.ShowHideBtnCallback();'>Run List</button>&nbsp;<button onclick='window.SaveAsPreset();'>Save As a New Preset</button>&nbsp;<button onclick='UpdateSelectedPreset();'>Update Selected Preset</button><br><hr><select id='FilterPresets'>" + window.ConvertToCombo(presetFilters) + "</select>&nbsp;<button onclick='window.LoadPreset()'>Load Selected Preset</button>&nbsp;<button onclick='window.DeletePreset();'>Delete Selected Preset</button><span style='float:right;font-style:italic;font-size:0.75em;'>Created By Spencer (Ghost)</span></div></div>";
$(htmlInsertBox).insertAfter("#overview_menu");
window.LoadPreset(true);

Tested in chrome without any issues.

Also, I will go ahead and contact support about approval. I don't think it's necessary, but better safe than sorry.
 

DeletedUser107279

Guest
Hmm can't make it work for me, tried in Chrome and Mozilla. The only thing I changed in the code is this :

var filter_coordinates='472|599 469|601';

These are both villages villages present on my current Loot Assistant
Not sure why it won't work tho, I also don't get the alerts or html box :/

Also tried without changing anything in the code, both in quicklink and bookmark
 
Last edited by a moderator:

DeletedUser118875

Guest
Hmm can't make it work for me, tried in Chrome and Mozilla. The only thing I changed in the code is this :

var filter_coordinates='472|599 469|601';

These are both villages villages present on my current Loot Assistant
Not sure why it won't work tho, I also don't get the alerts or html box :/

Also tried without changing anything in the code, both in quicklink and bookmark

Nothing should be modified in the code. Originally wrote it like a fake script, but "filter_coordinates" is actually just an internal variable. Only thing in the code that should be possible changed is "var mode = 'whitelist';" can be set to 'blacklist' instead.

Anyway, I'll look into it in a few minutes, but just to clarify, I ran it from the quickbar, not as a bookmark.

Also, Jon (Morthy) approved the script:
GpPSo92.png


Ideally, when running the script, you should see something like the following:
Ge7hHns.png

(Ignore the low quality, weird graphic style for the buttons and drop-down. I had to zoom out to get the full screenshot.)

Are you not getting any kind of HTML output/change when you run the script? o_O
 

DeletedUser107279

Guest
Yeah I don't get any html I don't get how is that. Will try again later and check-in with some of my tribe members to give it a shot, given the look of your screenshot it looks just perfect I can't wait to use it ;)

I have no time to try it at the moment but I'll let you know when I did again and had some friends try too, no reason why it would work for you but not others.

Thanks again Spencer,
Niko
 

DeletedUser118875

Guest
Yeah I don't get any html I don't get how is that. Will try again later and check-in with some of my tribe members to give it a shot, given the look of your screenshot it looks just perfect I can't wait to use it ;)

I have no time to try it at the moment but I'll let you know when I did again and had some friends try too, no reason why it would work for you but not others.

Thanks again Spencer,
Niko
Sounds good and no problem. Let me know what they find. My testing was done in Chrome version 55.0.2883.95 (64-bit) on Mac running macOS Sierra. (Not that the operating system should matter, but just including it for reference.) Ultimately, the browser should be the only important aspect, but if you tested on chrome, then I'm not sure what's up. Maybe there is some Tribal Wars parsing issue? If so, I will upload it to one of my servers so it can be ran via "$.getScript(...)", but I think that might be unnecessary seeing as it executed fine for me when running out of my QuickBar.
 

DeletedUser107279

Guest
Darn my reply never leaved my router

It didn't work for my tribemates either unfortunately... I also tried uploading it and running it from a getScript but it didn't work either :/ All we get is a loading dots for like a second and that's it (thru full code or getScrip, in quickbar)

Code:
javascript:$.getScript('https://pastebin.com/raw/EHBD1sHr');void(0);

Do you know if it worked for anyone else?

I tried running it command by command in the web console too, dunno what I should be seeing but all I get is function definitions. Only thing I noticed which might be weird is the HTML table which says it has a length of 0. Makes me so sad it doesn't work it would be the perfect solution, I don't want to abuse you either tho so it's ok if you give up on it. Do you know of someone else's script which would do this?

Niko
 

DeletedUser118875

Guest
Darn my reply never leaved my router

It didn't work for my tribemates either unfortunately... I also tried uploading it and running it from a getScript but it didn't work either :/ All we get is a loading dots for like a second and that's it (thru full code or getScrip, in quickbar)

Code:
javascript:$.getScript('https://pastebin.com/raw/EHBD1sHr');void(0);

Do you know if it worked for anyone else?

I tried running it command by command in the web console too, dunno what I should be seeing but all I get is function definitions. Only thing I noticed which might be weird is the HTML table which says it has a length of 0. Makes me so sad it doesn't work it would be the perfect solution, I don't want to abuse you either tho so it's ok if you give up on it. Do you know of someone else's script which would do this?

Niko
Late reply, but I'll take a look into it. Tried it on one of my accounts and no problems. I'll ask one of my COs to try it.

As for another script, I don't know of any that function as described in your post.


EDIT:

If you are going to load it remotely using "$.getScript(...)", try the following instead:

Code:
javascript:$.ajaxSetup({cache:true});$.getScript('https://pastebin.com/raw/EHBD1sHr');void(0);

Also, are you trying to run this along with any other scripts? (Might have already asked that, if so, my apologies for the redundancy.) I have not tried running this along with other scripts such as LA Enhancer or FA Keypress.
 
Last edited by a moderator:

DeletedUser107279

Guest
It's a fair question! But no I've been running the script straight after opening LA and even matched my checkboxes to your screenshot. The getScript you shared didn't work either. :(

Thanks for trying tho :)
Niko
 

DeletedUser107279

Guest
Just trying my luck again, anyone happens to know how to do this? :)
 

DeletedUser107279

Guest
I am looking for a script or tool that would allow me to filter Loot Assistant's target by using a list of coordinates in order to help with time-based farming. Does such a tool exist?

Spicer had exactly what I was looking for but somehow I never got to make it work on my end..

:)
 
Top