Troop Counter/Vault Villages Troops Counter

NunoF-

Active Member
Reaction score
9
Author
NunoF-
Contributors
N/A
Quickbar Entry
javascript:$.getScript('https://nunoferr.github.io/TribalWars/Scripts/VillagesTroopsCounter/villagesTroopsCounter.js');
Public?
Public
1723857205438.png


What does the script do?
The script generates a popup with a table where you can see how many troops you have idle in your villages, on scavenging hunts, and the total of both. You can also filter by group.


When is this useful?
I am unsure how it works on other servers, but at least on the .com.pt, whenever we are part of a big and active tribe, the tribe leadership always asks players to put a screenshot of their available troops to send as a support to other players weekly or bi-weekly, as a way to have some sort of realistic notion of what they can work with. For this, people usually use other unrelated scripts such as Support Sender, which displays the current troops that the user has available on the mass support page.

However, that script was not done for this. Firstly, a player always needs to change the default target village. Secondly, that kind of script never takes into consideration the troops that players have in scavenging hunts. This is a pain for many players who do scavenging hunts quite often, since they usually either forget it's the day of the week that they need to screenshot their troops (and it's too late since the troops are already on a scavenging hunt), or they simply do not have time in their schedules to wait for the scavenging hunts to finish, due to either work, sleep, or life commitments.

This script solves all the above-mentioned issues, and it is a literal 'one-click' solution. Even a new player can do it without any issues. This will likely facilitate the work of leaderships for years to come.


Where can this script be run?
Everywhere you want.


Does this work when you are on someone's account as a sitter?
Yes.


Does this require a premium account?
Yes.


How does the script interact with TW?
The script fetches code that is written inside a script tag inside the Mass Scavenging page. This code seems to be used to generate the content for that page, and it does not seem to be accessible anywhere outside the script tag. Without a better option, we make a request to that page, fetch the data using regex, and parse the JSON string containing the data with the units that are currently on a scavenging hunt and idle in the village.

The script also allows users to run it by group. To achieve this, the easier way I found was to make a request to TW requesting the group to be changed, as it seems to usually be the case, mimicking the behavior of clicking on a link to change groups on the villages overview screen. To fetch the groups, a simple request is done on the background to the villages overview pages, with the mode being groups, and we just fetch it from the HTML directly using JQuery.


Script
JavaScript:
$.getScript('https://nunoferr.github.io/TribalWars/Scripts/VillagesTroopsCounter/villagesTroopsCounter.js');
 
Changelog
22/08/2024 14:12 - fix: Regex Json selection no longer preventing parsing if the village name contains the character ]
12/09/2024 19:20 - fix: Script now taking into consideration all the troops from groups with more than 50 villages (instead of only considering the first 50)
26/09/2024 20:03 - fix: Script now properly parsing group names/ids on mobile devices on player accounts that have more than 5 groups.
26/09/2024 20:05 - comments: Changed 'Last Updated' field.
26/09/2024 20:06 - fix: Version number changed.
16/10/2024 18:16 - assets: Assets for upcoming Breast Cancer Awareness Month layout changes
16/10/2024 18:19 - assets: fixed assets location
16/10/2024 18:24 - refactor: Layout now being representative of the Breast Cancer Awareness Month
16/10/2024 18:26 - comments: Last changed date, and version date, fixed.
01/11/2024 11:15 - assets: Movember assets added
01/11/2024 11:15 - refactor: Layout now being representative of Movember
12/12/2024 03:40 - new: Script now supporting worlds without scavenging
12/12/2024 03:50 - refactoring: Disabled awareness section.
10/05/2025 19:19 - fix: Script now fetching the correct troops line data for non-scavenging worlds
Last edited:
Upvote 0

NunoF-

Active Member
Reaction score
9
There was a bug with this script where, for groups with more than 50 villages, it was not taking into consideration any village after the 50th. This has now been fixed.
 

NunoF-

Active Member
Reaction score
9
Apparently, the game displays the groups in a different way when (on mobile only) when a player has more than 5 groups. This was causing the group selection to not load properly and only display as "1". This has now been fixed, it was a simple data parsing issue.
 

NunoF-

Active Member
Reaction score
9

Version 1.2.0​


Change Log*​

  1. After several people asked - Script now running on worlds without scavenging. Keep in mind that the scavenging section won't show for obvious reasons.


* Relevant commits summary only. The full change log can be found in my original post.
 

NunoF-

Active Member
Reaction score
9

Version 1.3.0​


Change Log*​

  1. Script now fetching the correct troops line data for non-scavenging worlds.


* Relevant commits summary only. The full change log can be found in my original post.
 
Top