Troop Counter/Vault Modified support packet counter script

iDisbelieve

Active Member
Reaction score
35
Author
Unknown
Contributors
iDisbelieve
Quickbar Entry
javascript: if (document.URL.match(/mode=commands/)) {var troopsArray = new Array(); var numvil = 0; var main = $("#commands_table")[0]; var names = new Array(); var vilCoords = new Array(); var village = new Array(); var CurVill; var units =['Spear', 'Sword', 'Axe', 'Archer', 'Scout', 'LC', 'Mounted Archer', 'HC', 'Ram', 'Cat', 'Paladin', 'Noble']; var farmused =['1', '1', '1', '1', '0', '4', '5', '4', '5', '8', '10', '100']; var rows = main.getElementsByTagName('tr'); for (var j = 1;j < rows.length;j++) {var cells = rows[j].getElementsByTagName('td'); if ($(cells[0]).text().match(/Support/) == "Support") {CurVill = $(cells[0]).text().split(/\(/); CurVill = CurVill[CurVill.length - 1]; CurVill = CurVill.match(/\d+\|\d+/); var val = 0; if (vilCoords[CurVill] == null) {village.push(CurVill); vilCoords[CurVill] = new Array(); var p = 0; for (var k = 3;k <= (cells.length - 1);k++) {val = cells[k].firstChild.nodeValue; if ( ! val) {val = cells[k].firstChild.innerHTML.replace( /<[^>]*>/g, '').replace(/\s+/, '').match(/\d+/)[0]; } vilCoords[CurVill][p] = parseInt(val); p = p + 1; } } else {var p = 0; for (var k = 3;k <= (cells.length - 1);k++) {val = cells[k].firstChild.nodeValue; if ( ! val) {val = cells[k].firstChild.innerHTML.replace( /<[^>]*>/g, '').replace(/\s+/, '').match(/\d+/)[0]; } vilCoords[CurVill][p] += parseInt(val); p = p + 1; } } } } var msg = "Total Support Sent<br>" + "---------------------------------<br>"; for (var g = 0;g < village.length;g++) {msg += "Sent to <b>"+village[g]+"</b> -- "; var villageCoords = village[g]; var troops = vilCoords[villageCoords]; var farmspace = 0; for (var h = 0;h < units.length; h++) {if (troops[h] == 0){} else {msg += units[h] +": " + troops[h] + " "; farmspace += parseInt(troops[h] * farmused[h]); } } msg += " (farm pop: " + farmspace +")<br><br>"; } function openPopup() {var TheNewWin = window.open('', 'name', 'height=255,width=800, toolbar=no,directories=no,status=no,menubar=no'); TheNewWin.document.write( '<html>'); TheNewWin.document.write( '<head><title>Popup<\/title><\/head><body style="overflow:auto; font-family:verdana,arial;font-size:10pt"> <p>' + msg + '<\/p>'); TheNewWin.document.write(' <hr \/> <p align="right"><a href="#" onclick="self.close(); return false;">Close'); TheNewWin.document.write(' Window<\/a><\/p> <\/body><\/html>'); } openPopup(); } else {self.location = "http://" + window.location.hostname + "/game.php?screen=overview_villages&mode=commands&type=support"; } void%200;

//$.getScript("https://dl.dropboxusercontent.com/s/zdabphus5nc2324/supportTracker.js%22);
Public?
Public
I was sent a support packet counter script a little while ago and I made some changes to it so that it would work on a paladin + archer world. I also made some personal preference changes to it which means that scout units are counted as 0 population and Heavy Cavalry units are counted as 4 population. I do not know who the original author is, but I have linked the original script in comments at the end of this modified version.

Please note that the changes I made are minimal effort and this script isn't dynamic at all; it won't work properly on a world without archers/mounted archers/paladins unless modified again.
 
Changelog
02/03/2021:
- added archers, mounted archers, paladin
- changed scout population to 0
- Changed HC population to 4
Upvote 0

Johnny Tapia

Active Member
Reaction score
5
Has anyone managed to run the script?

2.png

And yes, the world I tested has archers / mounted archers / paladins
 

iDisbelieve

Active Member
Reaction score
35
Has anyone managed to run the script?

View attachment 7112

And yes, the world I tested has archers / mounted archers / paladins
To me it looks like you ran the script from the wrong tab. If I run it from anywhere it takes me to the "Troops" tab, not the "Commands" tab in your screenshot.

I'm assuming the script isn't smart enough to recognize that you are on the wrong tab and then tries to read the table data of a table that isn't actually there, hence why you get an empty result. I suggest trying again on the "Troops" tab.
 

Johnny Tapia

Active Member
Reaction score
5
To me it looks like you ran the script from the wrong tab. If I run it from anywhere it takes me to the "Troops" tab, not the "Commands" tab in your screenshot.

I'm assuming the script isn't smart enough to recognize that you are on the wrong tab and then tries to read the table data of a table that isn't actually there, hence why you get an empty result. I suggest trying again on the "Troops" tab.

When I run it on any page in the game, it redirects me to the "Commands" page. Then I run it and the error message that I left in my last message appears.

At the end of the script there is a redirector command for the "/game.php?screen=overview_villages&mode=commands&type=support" page. That's why I can't run it on the "Troops" page, because I run it and it redirects me to the "Commands" page every time. I tried switching to "/game.php?screen=overview_villages&mode=units" but it doesn't work, when I run it it keeps updating the page and that's it.
 

iDisbelieve

Active Member
Reaction score
35
I couldn't run this script either. Also @iDisbelieve I suggest you use a script loader
this post has been made to conform with the new script rules of uploading everything to the forums. I set it to public in case anyone wants to use this modified version as well. Sorry, but I wasn't planning on putting more effort into this.

When I run it on any page in the game, it redirects me to the "Commands" page. Then I run it and the error message that I left in my last message appears.

At the end of the script there is a redirector command for the "/game.php?screen=overview_villages&mode=commands&type=support" page. That's why I can't run it on the "Troops" page, because I run it and it redirects me to the "Commands" page every time. I tried switching to "/game.php?screen=overview_villages&mode=units" but it doesn't work, when I run it it keeps updating the page and that's it.
I honestly don't know how to help you further. All I have to do to have this script functional is to run it twice from any page (first one is navigation, second one is execution). I double-checked if what I uploaded here is the exact same as what I have in my own quickbar, and it is. I misunderstood something earlier and it does indeed take you to the command page, so why it doesn't work for you is a complete mystery to me. Best I can come up with is that it doesn't work for you because your Tribalwars isn't set to English.
1615557763009.png
 

The Quacks

Non-stop Poster
Reaction score
76
this post has been made to conform with the new script rules of uploading everything to the forums. I set it to public in case anyone wants to use this modified version as well. Sorry, but I wasn't planning on putting more effort into this.


I honestly don't know how to help you further. All I have to do to have this script functional is to run it twice from any page (first one is navigation, second one is execution). I double-checked if what I uploaded here is the exact same as what I have in my own quickbar, and it is. I misunderstood something earlier and it does indeed take you to the command page, so why it doesn't work for you is a complete mystery to me. Best I can come up with is that it doesn't work for you because your Tribalwars isn't set to English.
View attachment 7121
The language is probably the why for me, I was trying on the Portuguese server.
 

Johnny Tapia

Active Member
Reaction score
5
I sent the script to the media uploader of the brazilian server and just translated the options for the variable "units" as a test. This did not solve the problem.

JavaScript:
javascript:$.getScript('https://media.innogamescdn.com/com_DS_BR/Scripts/Aprovados/ModifiedSupportPacketCounterScript.js');

If anyone can help...

JavaScript:
 if (document.URL.match(/mode=commands/)) {
    var troopsArray = new Array();
    var numvil = 0;
    var main = $("#commands_table")[0];
    var names = new Array();
    var vilCoords = new Array();
    var village = new Array();
    var CurVill;
    var units = ['Lanceiro', 'Espadachim', 'Bárbaro', 'Arqueiro', 'Explorador', 'Cavalaria leve', 'Arqueiro a cavalo', 'Cavalaria pesada', 'Aríete', 'Catapulta', 'Paladino', 'Nobre'];
    var farmused = ['1', '1', '1', '1', '0', '4', '5', '4', '5', '8', '10', '100'];
    var rows = main.getElementsByTagName('tr');
    for (var j = 1; j < rows.length; j++) {
        var cells = rows[j].getElementsByTagName('td');
        if ($(cells[0]).text().match(/Support/) == "Support") {
            CurVill = $(cells[0]).text().split(/\(/);
            CurVill = CurVill[CurVill.length - 1];
            CurVill = CurVill.match(/\d+\|\d+/);
            var val = 0;
            if (vilCoords[CurVill] == null) {
                village.push(CurVill);
                vilCoords[CurVill] = new Array();
                var p = 0;
                for (var k = 3; k <= (cells.length - 1); k++) {
                    val = cells[k].firstChild.nodeValue;
                    if (!val) {
                        val = cells[k].firstChild.innerHTML.replace(/<[^>]*>/g, '').replace(/\s+/, '').match(/\d+/)[0];
                    }
                    vilCoords[CurVill][p] = parseInt(val);
                    p = p + 1;
                }
            } else {
                var p = 0;
                for (var k = 3; k <= (cells.length - 1); k++) {
                    val = cells[k].firstChild.nodeValue;
                    if (!val) {
                        val = cells[k].firstChild.innerHTML.replace(/<[^>]*>/g, '').replace(/\s+/, '').match(/\d+/)[0];
                    }
                    vilCoords[CurVill][p] += parseInt(val);
                    p = p + 1;
                }
            }
        }
    }
    var msg = "Total de apoio<br>" + "---------------------------------<br>";
    for (var g = 0; g < village.length; g++) {
        msg += "Enviado para <b>" + village[g] + "</b> -- ";
        var villageCoords = village[g];
        var troops = vilCoords[villageCoords];
        var farmspace = 0;
        for (var h = 0; h < units.length; h++) {
            if (troops[h] == 0) {} else {
                msg += units[h] + ": " + troops[h] + " ";
                farmspace += parseInt(troops[h] * farmused[h]);
            }
        }
        msg += " (farm pop: " + farmspace + ")<br><br>";
    }

    function openPopup() {
        var TheNewWin = window.open('', 'name', 'height=255,width=800, toolbar=no,directories=no,status=no,menubar=no');
        TheNewWin.document.write('<html>');
        TheNewWin.document.write('<head><title>Popup<\/title><\/head><body style="overflow:auto; font-family:verdana,arial;font-size:10pt"> <p>' + msg + '<\/p>');
        TheNewWin.document.write(' <hr \/> <p align="right"><a href="#" onclick="self.close(); return false;">Close');
        TheNewWin.document.write(' Window<\/a><\/p> <\/body><\/html>');
    }
    openPopup();
} else {
    self.location = "http://" + window.location.hostname + "/game.php?screen=overview_villages&mode=commands&type=support";
}
 

iDisbelieve

Active Member
Reaction score
35
Johnny Tapia

The translations you made are in code that doesn't interact with Tribalwars, so the behavior wasn't changed. Looking at the code I suggest looking at the following couple lines and see if those should be translated:

the tribalwars URL in your browser, if this "if-statement" doesn't return True then it will try to navigate to it. So you need to verify that "mode=commands" is displayed in your browser URL
JavaScript:
if (document.URL.match(/mode=commands/)) {


The one that looks promising to me, it looks for a textbox somewhere that says "Support" which is something that could be translated. If this textbox is not found, it will not do any counting. It is possible you only need to translate the first "support" in this line or only the second "support", or both of course. So I suggest just trying all 3 different options.
JavaScript:
if ($(cells[0]).text().match(/Support/) == "Support") { {


I'm sorry I can't be of more help. As I mentioned in the original post I didn't write the script and have only set it to public in case others would find it useful.
 

RedAlert

Senior In-Game Staff
Tribal Wars Team
Senior
Team
Script Moderator
Reaction score
623
The problem could or should be here:

It checks for "Support". Probably on Brazilian server you don't even have a table heading named "Support".

If that is the case then this string needs to be translated to whatever is used on Brazilian server.
 

Johnny Tapia

Active Member
Reaction score
5
Hi @misteralb and @iDisbelieve, thanks for the help.

On the "Commands" page, these are the options:

Screenshot at Mar 14 20-35-41.png

The "Support" page link is "/game.php?screen=overview_villages&mode=commands&type=support":

Screenshot at Mar 14 20-43-17.png

In the script, in the line "if ($(cells[0]).text().match(/Support/) == "Support")" I also tested with "if ($(cells[0]).text().match(/Suporte/) == "Suporte")":

Screenshot at Mar 14 20-41-30.png

It didn't work, I'm about to give up.
 

lllll llll

Well-Known Member
Reaction score
66
Johnny Tapia

This version should work on any server and for any kind of world archers, non-archers, paladin or not.

javascript:
var heavyPop=6;
$.getScript('https://dl.dropboxusercontent.com/s/xpye9n8eu29vn6l/supportCounteriDisbelieve.js?dl=0');void 0;


And if you want to show troops in spanish try this one, it is set for a world with archers and paladin.
javascript:
var heavyPop=6;
var units =['Lanceiro', 'Espadachim', 'Bárbaro', 'Arqueiro', 'Explorador', 'Cavalaria leve', 'Arqueiro a cavalo', 'Cavalaria pesada', 'Aríete', 'Catapulta', 'Paladino', 'Nobre'];
$.getScript('https://dl.dropboxusercontent.com/s/xpye9n8eu29vn6l/supportCounteriDisbelieve.js?dl=0');void 0;




Screenshot_5.png
 

The Quacks

Non-stop Poster
Reaction score
76
Johnny Tapia

This version should work on any server and for any kind of world archers, non-archers, paladin or not.

javascript:
var heavyPop=6;
$.getScript('https://dl.dropboxusercontent.com/s/xpye9n8eu29vn6l/supportCounteriDisbelieve.js?dl=0');void 0;


And if you want to show troops in spanish try this one, it is set for a world with archers and paladin.
javascript:
var heavyPop=6;
var units =['Lanceiro', 'Espadachim', 'Bárbaro', 'Arqueiro', 'Explorador', 'Cavalaria leve', 'Arqueiro a cavalo', 'Cavalaria pesada', 'Aríete', 'Catapulta', 'Paladino', 'Nobre'];
$.getScript('https://dl.dropboxusercontent.com/s/xpye9n8eu29vn6l/supportCounteriDisbelieve.js?dl=0');void 0;




Positively triggered, Spanish != Portuguese
 

Johnny Tapia

Active Member
Reaction score
5
Johnny Tapia

This version should work on any server and for any kind of world archers, non-archers, paladin or not.

javascript:
var heavyPop=6;
$.getScript('https://dl.dropboxusercontent.com/s/xpye9n8eu29vn6l/supportCounteriDisbelieve.js?dl=0');void 0;


And if you want to show troops in spanish try this one, it is set for a world with archers and paladin.
javascript:
var heavyPop=6;
var units =['Lanceiro', 'Espadachim', 'Bárbaro', 'Arqueiro', 'Explorador', 'Cavalaria leve', 'Arqueiro a cavalo', 'Cavalaria pesada', 'Aríete', 'Catapulta', 'Paladino', 'Nobre'];
$.getScript('https://dl.dropboxusercontent.com/s/xpye9n8eu29vn6l/supportCounteriDisbelieve.js?dl=0');void 0;





Now it worked, thank you!
 

Say Bye

Non-stop Poster
Reaction score
300
JavaScript:
javascript: if (document.URL.match(/mode=commands/)) {
    //You can switch to English version if you write EN value in this variable (for .net servers), ang Hungarian with the HU value (for .hu servers). Set archers to true if the server has archers, and false, if not
    //Itt tudsz magyarra váltani, ha a változóba a HU értéket írod (.hu szerverekre), és angolra, ha az EN értéket (.net szerverekre). Az archers változót állítsd true-ra, ha van íjász a szerveren, és false-ra, ha nincs
    var localization = 'EN';
    var archers = true;
    console.log('Localization: ' + localization);
    console.log('Archers: ' + archers);
    var troopsArray = new Array();
    var numvil = 0;
    var main = $("#commands_table")[0];
    var names = new Array();
    var vilCoords = new Array();
    var village = new Array();
    var CurVill;
    var unitsHu = ['Lándzsa', 'Kard', 'Bárd', 'Íj', 'Kém', 'KL', 'LÍJ', 'NL', 'Kos', 'Kata', 'Lovag', 'Nemes'];
    var unitsEn = ['Spear', 'Sword', 'Axe', 'Archer', 'Scout', 'LCav', 'MArch', 'HCav', 'Ram', 'Cats', 'Paladin', 'Noble'];
    var unitTypes = ['[unit]spear[/unit]', '[unit]sword[/unit]', '[unit]axe[/unit]', '[unit]archer[/unit]', '[unit]spy[/unit]', '[unit]light[/unit]', '[unit]marcher[/unit]', '[unit]heavy[/unit]', '[unit]ram[/unit]', '[unit]catapult[/unit]', '[unit]knight[/unit]', '[unit]snob[/unit]'];
    var farmused = ['1', '1', '1', '1', '2', '4', '5', '4', '5', '8', '10', '100'];
    var hungarianText = ['Küldött erősítés','Támogatott falu','küldött védők tanyahelye','Sikeres összeítés'];
    var englishText = ['Sent support','Supported village','farm space used','Successful count'];
    var usedText = [];
    var usedUnits = [];
    if(localization == 'HU'){
        usedText = hungarianText;
        usedUnits = unitsHu;
    }
    else if(localization == 'EN'){
        usedText = englishText;
        usedUnits = unitsEn;
    }
    else console.log('Unrecognised localization');
    if (!archers){
        usedUnits.splice(6, 1);
        console.log(usedUnits)
        usedUnits.splice(3, 1);
        farmused.splice(6, 1);
        console.log(usedUnits)
        farmused.splice(3, 1);
        unitTypes.splice(6, 1);
        unitTypes.splice(3, 1);
    }
    var rows = main.getElementsByTagName('tr');
    for (var j = 1; j < rows.length; j++) {
        var cells = rows[j].getElementsByTagName('td');
        if (($(cells[0]).text().match(/Erősítés/) == "Erősítés") || ($(cells[0]).text().match(/Support/) == "Support" )) {
            CurVill = $(cells[0]).text().split(/\(/);
            CurVill = CurVill[CurVill.length - 1];
            CurVill = CurVill.match(/\d+\|\d+/);
            var val = 0;
            if (vilCoords[CurVill] == null) {
                village.push(CurVill);
                vilCoords[CurVill] = new Array();
                var p = 0;
                for (var k = 3; k <= (cells.length - 1); k++) {
                    val = cells[k].firstChild.nodeValue;
                    if (!val) {
                        val = cells[k].firstChild.innerHTML.replace(/<[^>]*>/g, '').replace(/\s+/, '').match(/\d+/)[0];
                    }
                    vilCoords[CurVill][p] = parseInt(val);
                    p = p + 1;
                }
            } else {
                var p = 0;
                for (var k = 3; k <= (cells.length - 1); k++) {
                    val = cells[k].firstChild.nodeValue;
                    if (!val) {
                        val = cells[k].firstChild.innerHTML.replace(/<[^>]*>/g, '').replace(/\s+/, '').match(/\d+/)[0];
                    }
                    vilCoords[CurVill][p] += parseInt(val);
                    p = p + 1;
                }
            }
        }
    }
        var msg = '<h1>[b][size=12]' + usedText[0] + '[/size][/b]</h1><br>';
        for (var g = 0; g < village.length; g++) {
            msg += "";
            var villageCoords = village[g];
            var troops = vilCoords[villageCoords];
            var farmspace = 0;
            for (var h = 0; h < 9; h++) {
                if (troops[h] == 0) {
                } else {
                    msg += "<b>[b]" + usedUnits[h] + "[/b] " + unitTypes[h] +": " + troops[h] + "</b><br>";
                    farmspace += parseInt(troops[h] * farmused[h]);
                }
            }
            msg += "<b>[b]" + usedText[1] + "[/b]</b>: [village]" + village[g] + "[/village] (" + usedText[2] + ": <b>[b]" + farmspace + "[/b]</b> [building]farm[/building])<br><br>";
        }
        console.log(usedText[3]);
    
    function openPopup() {
        var TheNewWin = window.open('', 'name', 'height=800,width=800, toolbar=no,directories=no,status=no,menubar=no');
        TheNewWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd"><html xmlns="http:\/\/www.w3.org\/1999\/xhtml">');
        TheNewWin.document.write('<head><title>Support<\/title><\/head><body style="overflow:auto" bgcolor="#EFD9B0"> <p>' + msg + '<\/p>');
    }

    openPopup();
} else {
    self.location = "http://" + window.location.hostname + "/game.php?screen=overview_villages&mode=commands";
}
void (0);

JmN6XZ0.png


tJPFfRt.png


JavaScript:
var localization = 'EN';
var archers = false;

These two variables decide if I use it on HU servers or EN servers, and has archers on the server, or not. I hope it's not a problem for you guys, if yes, please delete this comment :D

If you want to add other location, just need to make a new variable like these:

JavaScript:
var unitsEn = ['Spear', 'Sword', 'Axe', 'Archer', 'Scout', 'LCav', 'MArch', 'HCav', 'Ram', 'Cats', 'Paladin', 'Noble'];
var englishText = ['Sent support','Supported village','farm space used','Successful count'];

and translate this English text, for example (all the troops between the ' marks) and we have 4 text opinion always:

JavaScript:
var unitsPortugese = ['Spear in portugese', 'Sword in portugese', 'Axe in portugese', 'Archer in portugese', 'Scout in portugese', 'LCav in portugese', 'MArch in portugese', 'HCav in portugese', 'Ram in portugese', 'Cats in portugese', 'Paladin in portugese', 'Noble in portugese'];
var portugeseText = ['Sent support in portugese','Supported village in portugese','farm space used in portugese','Successful count in portugese']];

So we have two variables. We should navigate to that area in the code (the first if):

JavaScript:
if(localization == 'HU'){
        usedText = hungarianText;
        usedUnits = unitsHu;
    }
    else if(localization == 'EN'){
        usedText = englishText;
        usedUnits = unitsEn;
    }
    else if(localization == 'PT'){
        usedText = portugeseText;
        usedUnits = unitsPortugese;
    }
    else console.log('Unrecognised localization');

and choose that line

JavaScript:
if (($(cells[0]).text().match(/Erősítés/) == "Erősítés") || ($(cells[0]).text().match(/Support/) == "Support" ))

and add portugese variant of the support page here like this:

JavaScript:
if (($(cells[0]).text().match(/Erősítés/) == "Erősítés") || ($(cells[0]).text().match(/Support/) == "Support" || ($(cells[0]).text().match(/portugeseSupportTab/) == "portugeseSupportTab"))

and add Portugese in an else if like this. After all if you write PT in the localization variable (which is EN now), the script will run in Portugese language.
 
Last edited:
Top