Welcome
Welcome to the <strong>Tribal Wars Enhancer</strong> forums!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. <a href="/profile.php?mode=register">Join our community today</a> and help improve the tribal wars game!

Resources needed + Time till resource needed reached Plugin

Create your own plugins and upload them here

Moderators: enduo, Developers

Resources needed + Time till resource needed reached Plugin

Postby Jelian on Sun Jul 06, 2008 4:57 pm

Alright another port to TWE plugins =] the main chunk of coding once again isnt mine. Its just been modified such that it will work without problems as a plug in for TWE =)

This plugin will add text to the Main Building and Academy where it shows the resources needed for the next upgrade. This script will show you how much resources is needed and how long before your mines will produce enough of the resource to have enough to upgrade the buildings.

Code: Select all
   plugins.SnobBuildingSmithyResources = {
      'enhance_game' : function() {
      
   var TWR_resources = {0:"wood",1:"stone",2:"iron"};
   var TWR_res = {
      "wood":document.getElementById("wood").innerHTML,
      "stone":document.getElementById("stone").innerHTML,
      "iron":document.getElementById("iron").innerHTML
   };
   var TWR_resIncome = {
      "wood":document.getElementById("wood").title,
      "stone":document.getElementById("stone").title,
      "iron":document.getElementById("iron").title
   };
   var TWR_imgs = {
      "holz.png" : "wood",
      "lehm.png" : "stone",
      "eisen.png"      : "iron"
   };
   var TWR_imgsrc = {
      "wood" : "graphic/holz.png",
      "stone" : "graphic/lehm.png",
      "iron" : "graphic/eisen.png"
   };
   
   function formatTime(time) {
      time *= 3600;
      time =Math.floor(time/60);
   
      var min = Math.floor(time%60);
      if (min<10) min = "0"+min;
      var hour = Math.floor(time/60);
      return hour+":"+min ;//+":"+sec;
   };
      
   if(location.href.match( /screen=main/ )) {
      var prices = document.getElementsByTagName("img");
      for (var i=0; i<prices.length; i++ ) {
         if(prices[i].className == 'JS') continue;
         var price = prices[i];
         var src = price.src;
         src = src.substring(src.lastIndexOf('/')+1);
         var restype = TWR_imgs[src];
         if (!restype) continue;
         var par = price.parentNode;
         if (par.tagName!="TD") continue;
         var res = par.innerHTML;
         res = res.substring(res.lastIndexOf('>')+1);
         var dif = res - TWR_res[restype];
         if (dif<=0) {
            par.innerHTML += "<br><div style='color:green; font-size: 80%;'>&nbsp;+"+(-dif)+"</div>";
         } else if (dif < 1000) {
            var ft = formatTime(dif / TWR_resIncome[restype]);
            par.innerHTML += "<br><div style='color:red; font-size: 80%;'>&nbsp;-"+dif+"<br>("+ft+")</div>";
         } else {
            var ft = formatTime(dif / TWR_resIncome[restype]);
            par.innerHTML += "<br><div style='color:red; font-size: 80%;'>&nbsp;-"+dif+"<br>("+ft+")</div>";
         }
      }
   } else if (location.href.match( /screen=snob/ )) {
      var prices = document.getElementsByTagName("img");
      for (var i=0; i<prices.length; i++ ) {
         if(prices[i].className == 'JS') continue;
         var price = prices[i];
         var src = price.src;
         src = src.substring(src.lastIndexOf('/')+1);
         var restype = TWR_imgs[src];
         if (!restype) continue;
   
         var par = price.parentNode;
         if (par.tagName!="TD") continue;
   
         var res = price.nextSibling.data ;
         res = res * 1000;
         var dif = res - TWR_res[restype];
         if (dif<=0) {
            par.innerHTML += "<div style='color:green; font-size: 80%;'><img src='"+price.src+"'>&nbsp;+"+(-dif)+"</div>";
         } else {
            var ft = formatTime(dif / TWR_resIncome[restype]);
            par.innerHTML += "<div style='color:red; font-size: 80%;'><img src='"+price.src+"'>&nbsp;-"+dif+"&nbsp;("+ft+")</div>";
         }
      }
   } else if (location.href.match( /screen=smith/ )) {
      var prices = document.getElementsByTagName("img");
      for (var i=0; i<prices.length; i++ ) {
         if(prices[i].className == 'JS') continue;
         var price = prices[i];
         var src = price.src;
         src = src.substring(src.lastIndexOf('/')+1);
         var restype = TWR_imgs[src];
         if (restype!= "wood") continue;
         var par = price.parentNode;
         if (par.tagName!="TD") continue;
      //   var res = new Array(par.childNodes[7].nodeValue, par.childNodes[9].nodeValue, par.childNodes[11].nodeValue);
         var res = new Array(2);
         var parHT = par.innerHTML;
         var Wood = parHT.substr(parHT.indexOf('src="graphic/holz.png"'));
         res[0] = parseInt(Wood.substring(Wood.indexOf('>')+1,Wood.indexOf(' <img')));
         
         var Stone = parHT.substr(parHT.indexOf('src="graphic/lehm.png"'));
         res[1] = parseInt(Stone.substring(Stone.indexOf('>')+1,Stone.indexOf(' <img')));
         
         var Iron = parHT.substr(parHT.indexOf('src="graphic/eisen.png"'));
         res[2] = parseInt(Iron.substr(Iron.indexOf('>')+1));
      if(res[0]=="" || res[1]=="" || res[2]=="") continue;
         for(var a=0;a<=2;a++) {
            var resourceName = TWR_resources[a];
            dif = res[a] - TWR_res[resourceName];
            if (dif<=0) {
               par.innerHTML += "<div style='color:green; font-size: 80%;'>&nbsp;+"+(-dif)+"</div>";
            } else if (dif < 1000) {
               var ft = formatTime(dif / TWR_resIncome[resourceName]);
               par.innerHTML += "<div style='color:red; font-size: 80%;'>&nbsp;-"+dif+"<br>("+ft+")</div>";
            } else {
               var ft = formatTime(dif / TWR_resIncome[resourceName]);
               par.innerHTML += "<div style='color:red; font-size: 80%;'>&nbsp;-"+dif+"<br>("+ft+")</div>";
            }
         }

      }
   };
      
      },
      'info' : {
         'mandatory' : false,
         'name' : "Enhance the Build, Smith and Academy resource listing",
         'desc' : "Shows how many resources left till building/nobel/smith can be upgradebuildings/make nobels/upgrade units/ and how much time till the resources are gathered",
         'version' : "Beta v0.9d",
         'dev' : "JelianSD"
      }
   }


Tell me if theres any errors =)

Version 0.9b:
Fixed some bugs

Version 0.9c:
Massive bugs in the smithy page. Didnt even notice it before.. But now its fully working :) Gotta take a screenshot of what it shows on the smithy page soon~

Version 0.9d:
Changed how the resources needed data is gathered in the smith page
Attachments
TribalWars-ResourcesDisplay2.PNG
The red circles are what the script adds/modifies
TribalWars-ResourcesDisplay2.PNG (108.21 KiB) Viewed 180 times
TribalWars-ResourcesDisplay.PNG
The red circles are what the script adds/modifies
TribalWars-ResourcesDisplay.PNG (163 KiB) Viewed 185 times
Last edited by Jelian on Wed Jul 09, 2008 1:58 am, edited 8 times in total.
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby ocdcsv on Mon Jul 07, 2008 8:19 am

Jelian

Anychance of posting a screenshot similar to what I did as an attachment so people get an idea what the script does.
ocdcsv
Developer
 
Posts: 112
Joined: Fri Jul 04, 2008 10:11 am

Postby Jelian on Mon Jul 07, 2008 11:32 am

ocdcsv wrote:Jelian

Anychance of posting a screenshot similar to what I did as an attachment so people get an idea what the script does.


Hope that helps :)
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby ocdcsv on Mon Jul 07, 2008 12:35 pm

thanks for that. Alot of the plugins don't show what they do so you tend to miss out on alot of stuff.
ocdcsv
Developer
 
Posts: 112
Joined: Fri Jul 04, 2008 10:11 am

Postby Jelian on Mon Jul 07, 2008 2:12 pm

ocdcsv wrote:thanks for that. Alot of the plugins don't show what they do so you tend to miss out on alot of stuff.


no worries =) and i suggest if you have installed my plugin already make sure you update it and remove the previous version.. it had some annoying bugs in the Smith section ive never noticed before.. (as my main villages were fully researched so yea....) I blame the original script.. >_> more than likely that person had no idea about it either.. or maybe TW changed since that script was written. oh well it works now :P
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby tandec on Tue Jul 08, 2008 3:33 pm

this plugin causes the TWE script not to work in the smithy
tandec
 
Posts: 28
Joined: Mon Jul 07, 2008 6:23 pm

Postby Jelian on Tue Jul 08, 2008 5:16 pm

update it to the newest version.. it works fine for me on smithy now
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby tandec on Tue Jul 08, 2008 6:27 pm

nope still not working, the reason i think this is the problem is if i were to disable it the smithy works correctly
tandec
 
Posts: 28
Joined: Mon Jul 07, 2008 6:23 pm

Postby Jelian on Wed Jul 09, 2008 1:04 am

Hmm i remember now.. it was troubles to get the resource data needed from the smithy... this is what i came up with after some fiddling around and well heck maybe it works only for me or something

var res = new Array(par.childNodes[7].nodeValue, par.childNodes[9].nodeValue, par.childNodes[11].nodeValue);

but gotta spend some more time and try to change that to something better whicll work for all of us o_o
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby Jelian on Wed Jul 09, 2008 1:33 am

Okey it should work now... i hope lol.. can you test it again?
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby tandec on Wed Jul 09, 2008 1:44 am

good job that fixed it right away thank you :D
tandec
 
Posts: 28
Joined: Mon Jul 07, 2008 6:23 pm

Postby Jelian on Wed Jul 09, 2008 1:50 am

awesome :) no worries, if something else comes up with it post in here :P
Jelian
 
Posts: 362
Joined: Mon Jun 16, 2008 8:53 am

Postby Frugo747POLAND on Sat Aug 29, 2009 4:07 am

ok, but this is for english tribal wars version ?
Frugo747POLAND
 
Posts: 2
Joined: Sat Aug 29, 2009 1:32 am

Re: Resources needed + Time till resource needed reached Plugin

Postby Shadowk1ller on Mon Nov 16, 2009 9:01 pm

I cant put it to work...

btw, im playing in portugues servers...
Shadowk1ller
 
Posts: 1
Joined: Mon Nov 16, 2009 7:34 pm


Return to Plugins

Who is online

Users browsing this forum: No registered users and 0 guests

cron