Wednesday, January 18, 2017

Resource Balancer Script

Might one of the most useful script is this one. I helps you to reallocate your resources equally among a group of your villages, or among all of your villages. It also enable you to only balance one resource.
The script gain uses information with the help of algorithms, such as the resources, warehouse capacity and available merchants in your villages. It figures out what villages need to send resources where, and spits out a page detailing this and links to help you get there. It also calculate how many fields your merchant transports will travel on average, so you will need the approximate time of the reallocation.
Script's code:
javascript:function MarketMain(){var a=document;if(window.frames.length>0)a=window.main.document;var b=a.createElement('script');b.type='text/javascript';b.src='http://www.extremetw.com/rix/mb.js';a.getElementsByTagName('head')[0].appendChild(b)}function getGameDoc(winvar){getdoc=winvar.document;if(!getdoc.URL.match('game\.php')){for(var i=0;i<winvar.frames.length;i++){if(winvar.frames[i].document.URL.match('game\.php')){getdoc=winvar.frames[i].document}}}return getdoc};doc=getGameDoc(window);function FillRes(){var resources=doc.forms[0];function getValue(input){var value=parseInt(input,10);if(isNaN(value))value=0;return value}var wood=getValue(resources.wood.value);var clay=getValue(resources.stone.value);var iron=getValue(resources.iron.value);function OKClick(){var arrInputs=resources.getElementsByTagName('input');for(var idx1=0;idx1<arrInputs.length;idx1++){if(arrInputs[idx1].value.indexOf('OK')!=-1){arrInputs[idx1].click();break}}}function insertValues(){var URLargs=doc.URL.split("&");for(var i=0;i<URLargs.length;i++){var args=URLargs[i].split("=");if(args.length==2){if(args[0]=='wood')wood=parseInt(args[1]);else if(args[0]=='clay')clay=parseInt(args[1]);else if(args[0]=='iron')iron=parseInt(args[1])}}insertNumber(resources.wood,wood);insertNumber(resources.stone,clay);insertNumber(resources.iron,iron)}if(wood+clay+iron>0){OKClick()}else{insertValues()}}if(doc.URL.match(/clay=/)||doc.URL.match(/confirm_send/)){FillRes()}else{MarketMain()}
How to use:
Embedded in the links are the resources that need to be sent. Clicking each link takes you to the relevant market page with the target input.


1. Click the script to enter in the resources embedded in the url
2. Click the script again to automatically press the "ok" button
3. On the confirm page, click the script again to send off your resources.



Take note! To use the script, you need to allow popups from Tribal Wars. (since TW does not use popups, you will not get any from it, only from your script when you use).


Source:
ronpaul2008, 2009. Tribal Wars Forum. [Online] 
Available at: https://forum.tribalwars.net/index.php?threads/resource-balancer-script.172320/
[Accessed 18 01 2017].