DeletedUser

Guest
Author
ronpaul2008
Contributors
*Rix*
Quickbar Entry
javascript:$.getScript('https://dl.dropboxusercontent.com/s/easpu2c1j2r710f/extremetwbalancer.js');
Public?
Public
Edit by mod
I fixed the problems with the send button not being clicked (TW changed so it didn't find the correct button anymore) and the popup blocking issue with this.

Code:
javascript:$.getScript('https://dl.dropboxusercontent.com/s/easpu2c1j2r710f/extremetwbalancer.js');

I rehosted the script since one of the problems causing the popup block is this script being hosted on an unsecured connection. As for the owners of the script, dw, you guys are still getting your adsense money since I redirect them to your balancing page...

Original post:



Hello everyone,

*Rix* and I have made a resource balancing tool that will help you to quickly and effectively balance your resources either among group of villages, or among all of your villages.

It uses this script to gather data about your villages (i.e. resources and available merchants) then run the data through a python algorithm.

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()}

The algorithm figures out what villages need to send resources where, and spits out a page detailing this and links to help you get there.

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.

At this point I copied functionality from some existing market scripts.

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.

Enjoy!

Edit: I've set up a skype chat for people that need help.


Common Issues and Solutions:

1. You must allow popups from tribalwars. (Tribalwars doesn't use popups, so you shouldn't have to worry about getting any from tribalwars anyway.)
2. You must wait long enough for the production overview tabs to finish loading before pressing the script a second time. Fixed with v2
3. You must have your dynamic menu bar turned on. Fixed with v2


Version 2 Released! 10/28/09

*Rix* and I just released version two of the resource balancer. There is no need to update your script, but you might get access to the new one a day sooner if you clear your cache.

New Features:

1. The Resource Balancer will now work in a sat account.

2. Warehouse levels are now taken into account, to prevent a village from receiving more resources than it can hold.

3. Optional Advanced settings that enable you to only balance one resource, or choose to horde a certain amount of a resource in villages with a surplus of that resource.

4. Adding formatting to the village data submission page.

Bug Fixes

1. The script will now prevent you from clicking it again too soon before the village overview tabs finish loading.

2. The script should now always open the village overview pages that displays "ALL" villages in the selected group.

3. You no longer need to have your dynamic menu bar turned on to use the Resource Balancer.

Enjoy!

Edit Dec. 6th 2009

Version 3 Released!

*Rix* and I just released version three of the resource balancer. There is no need to update your script, but you might get access to the new one a day sooner if you clear your cache.

New Features:

1. You can now select an option that will send extra resources from your villages with more than 23,950 population, to villages with less than 22k population. Once a village has less than 22k population it receives more and more extra resources the lower its population actually is. This setting is ideal for players with many villages recruiting troops or under construction. **Please note that this setting currently negates the 'horde' settings.**

2. New stat totaling how many merchant transports listed on the output page.

3. New stat revealing how many fields your merchant transports will travel on average.

Upcoming Feature:

By popular request I am working on a feature to limit how far your merchants travel. Currently the resource balancer maximizes merchants per resource transport, in order to limit how many transports you have to send. The new feature will allow you to instead minimize merchant travel time, at the cost of more resource transports to send. (Hopefully there won't be too many extra.)

How will this feature work? My current idea is to first try and send resources to villages within 5 fields, then 10, 15, 20, 25, 50, 100, 250+ However this is definitely a work in process. Please post feedback and suggestions below.
 
Last edited by a moderator:
Upvote 1

DeletedUser

Guest
Seagryfn is absolutely correct. I just spoke with Toyaga on skype and this was his problem as well. In some browsers, you must go to the popup village overview tabs, and make sure that "ALL" is selected.

You know that you can modify the links so that they will always go to the all page...it's just another parameter.
 

DeletedUser

Guest
Great script! Thanks.

However, it often sends resources to somewhere for example 100,000 clay to a village that only has a warehouse capacity of 50,000. I am unsure of how you could incorperate a script into this one which determines the warehouse capacity as well.

Apart from this, very helpful indeed. Thankyou!
 

DeletedUser

Guest
Great script! Thanks.

However, it often sends resources to somewhere for example 100,000 clay to a village that only has a warehouse capacity of 50,000. I am unsure of how you could incorperate a script into this one which determines the warehouse capacity as well.

Apart from this, very helpful indeed. Thankyou!

A temporary solution would be to group only villages that can support the full amount of resources that can be shipped in the markets of the villages in the group.
 

2004 Artemis

Guest
On the webpage you click the links on, it shows you the resource average of your villages, so you can look at that and compare it to your village list on the production overview after running a sort script on it. Makes it easy to tell if you have any villages with warehouses that don't fit.
 

DeletedUser

Guest
So then have the script check for some item on those pages that are near the end of the page (or at least load after everything that you need) and wait if that information isn't available.

Alternatively utilize the onload event for the page so that you don't start using it until everything is done loading. I didn't say this first simply because I've had trouble with it in the past. It can be done, but (especially if you haven't worked with javascript events a lot) can be harder to manage.

I will test it both ways and see which way is a better fix, thanks for the suggestions :).


You know that you can modify the links so that they will always go to the all page...it's just another parameter.

I know, I really didn't realize it was an issue until now though. I will probably make them static links so we don't have to require the dynamic menu bar when I am doing that. The problem is when I update the script, if your browser has it cached, your script may not update for a while. (I think its because my timezone is 1 hr before the server timezone that I am uploading to, I will change my time tonight and see if its an instant update).

Sorry for the problems with this.



Great script! Thanks.

However, it often sends resources to somewhere for example 100,000 clay to a village that only has a warehouse capacity of 50,000. I am unsure of how you could incorperate a script into this one which determines the warehouse capacity as well.

Apart from this, very helpful indeed. Thankyou!



This is already fixed, but we are bug testing it right now. So far I haven't seen any problems with it though. As soon as I figure out how to update the javascript without forcing everyone to clear their browser cache, we will make the code live (as long as RonPaul2008 is ready).
 
Last edited by a moderator:

DeletedUser

Guest
this is an amazing script, im truly greatful you guys made it:)

i broke my record on Merchants in transit with 1349:icon_eek:, and i only have 41 villages, and most aren't fully build yet:lol:

im defenetly moving resources far more than i ever had.
 

DeletedUser

Guest
I want to say thank you I hate moving resources around but I just tried this and it is fantastic :)
 

DeletedUser77177

Guest
am getting Error 404 Not found..:p ..

How do i solve it??
 

DeletedUser

Guest
am getting Error 404 Not found..:p ..

How do i solve it??

In the past this has been because your dynamic menu bar is not turned on. We are still working on a script update to avoid this bug. But for now, go to Settings --> Settings and check the "dynamic menu" box.
 

DeletedUser77177

Guest
In the past this has been because your dynamic menu bar is not turned on. We are still working on a script update to avoid this bug. But for now, go to Settings --> Settings and check the "dynamic menu" box.

still not working.. gives a blank screen, when i allow pop ups gives 2 blank screens..:(..

I was really looking for such script and when we have it cant use it.grrrr..:(
 

DeletedUser77177

Guest
hey got it sorted .. thnx ron working now..


Merchants in transit: 4129 :p:p
 

DeletedUser

Guest
I know, I really didn't realize it was an issue until now though. I will probably make them static links so we don't have to require the dynamic menu bar when I am doing that. The problem is when I update the script, if your browser has it cached, your script may not update for a while. (I think its because my timezone is 1 hr before the server timezone that I am uploading to, I will change my time tonight and see if its an instant update).

Sorry for the problems with this.

Yeah, it's way too much work to actually find the link in the menu bar to click it. Just find it yourself once, copy the address, and put that right in the code. Makes things way easier.

Great script! Thanks.

However, it often sends resources to somewhere for example 100,000 clay to a village that only has a warehouse capacity of 50,000. I am unsure of how you could incorperate a script into this one which determines the warehouse capacity as well.

Apart from this, very helpful indeed. Thankyou!

I'm assuming that your program calculates the average amount of a given resource per village and then sends transports from the villages over the average to villages under the average. In order to handle warehouses what you'd need to do is determine the average resources per village per warehouse size. In other words the average warehouse utilization. (Getting there isn't that hard.) The part that makes this process harder is that you then need to determine the amount of the resource that the village would need to send/receive in order to be at the average utilization. It wouldn't be that hard to do, but it would involve converting values each village several more times.
 

DeletedUser

Guest
I'm assuming that your program calculates the average amount of a given resource per village and then sends transports from the villages over the average to villages under the average. In order to handle warehouses what you'd need to do is determine the average resources per village per warehouse size. In other words the average warehouse utilization. (Getting there isn't that hard.) The part that makes this process harder is that you then need to determine the amount of the resource that the village would need to send/receive in order to be at the average utilization. It wouldn't be that hard to do, but it would involve converting values each village several more times.

That's sort of how my algorithm works, but not completely. :D

I have coded a change and tested it and it appears to work like a charm. The change basically looks at a village's warehouse level, and if the level is lower than current resources + desired resources, it lowers the amount of desired resources, and leaves a small resource cushion. Required another 8 lines of code. It wasn't that big of a deal.

The problem is that we have to change the script to send warehouse level data to the algorithm. And the last time we changed part of the script on our servers, it didn't work for people, until they cleared their cache. Rix and I would like to do some investigation to see if there is a way around that. If there's not, we are going to wait a little longer so that we can incorporate several changes at once, before forcing everyone to clear their cache.
 

DeletedUser

Guest
That's sort of how my algorithm works, but not completely. :D

I have coded a change and tested it and it appears to work like a charm. The change basically looks at a village's warehouse level, and if the level is lower than current resources + desired resources, it lowers the amount of desired resources, and leaves a small resource cushion. Required another 8 lines of code. It wasn't that big of a deal.

The problem is that we have to change the script to send warehouse level data to the algorithm. And the last time we changed part of the script on our servers, it didn't work for people, until they cleared their cache. Rix and I would like to do some investigation to see if there is a way around that. If there's not, we are going to wait a little longer so that we can incorporate several changes at once, before forcing everyone to clear their cache.

The issue there is that if you just max out resources sent based on warehouse level you also end up sending resources to all of your small villages. You may not be overflowing their warehouses (or at least not by much) but it still a side effect as you're now moving resources, not balancing them.
 

DeletedUser62440

Guest
^ Agreed lol. Alsothe cache issue, is it the cache or cookies? Because cache doesn't make much sense lol
 

DeletedUser

Guest
^ Agreed lol. Alsothe cache issue, is it the cache or cookies? Because cache doesn't make much sense lol

There is nothing in the JS for cookies. The cache I am talking about is when your browser takes the file (in this case the JS file) and stores it locally then reads it off your drive if there is not a newer updated file on the server.
 
Top