DebilasTuNX Posted December 14, 2015 Posted December 14, 2015 How to track how much i picked up of one specific item? I want to kill chickens and track how many feathers i gain
Explv Posted December 14, 2015 Posted December 14, 2015 (edited) How to track how much i picked up of one specific item? I want to kill chickens and track how many feathers i gain private long feathersCollected; private long prevInvCount; @Override public void onStart(){ // initialise previous inventory count to current inventory count prevInvCount = getInventory().getAmount("Feather"); } @Override public int onLoop(){ long invCount = getInventory().getAmount("Feather"); // get number of feathers in inventory // If the amount of feathers has increased, add the change to total feathers collected if(invCount > prevInvCount) feathersCollected += (invCount - prevInvCount); // Update previous inventory count to current count prevInvCount = invCount; ... } (This accounts for if you are banking, or if you are disposing of the items e.g. burying bones) If you aren't banking: private long startFeatherCount; @Override public void onStart(){ startFeatherCount = getInventory().getAmount("Feather"); } private long getFeathersCollected(){ return getInventory().getAmount("Feather") - startFeatherCount; } If you want to make it so that the updating of the count is not paused by the bot's actions, you can move the code in onLoop to the onPaint method. However you should ensure that you limit the amount of times it is called per second. Edited December 14, 2015 by Explv 1
FrostBug Posted December 14, 2015 Posted December 14, 2015 currentFeathers - startFeathers = gainedFeathers
DebilasTuNX Posted December 14, 2015 Author Posted December 14, 2015 private long feathersCollected;private long prevInvCount;@Overridepublic void onStart(){ prevInvCount = getInventory().getAmount("Feather");}@Overridepublic int onLoop(){ long invCount = getInventory().getAmount("Feather"); if(invCount > prevInvCount) featherCount += (invCount - prevInvCount); else prevInvCount = invCount; ...}But what about bones, if i pick them up and bury them, how would i do it then?
FrostBug Posted December 14, 2015 Posted December 14, 2015 (edited) But what about bones, if i pick them up and bury them, how would i do it then? bonesBuried = (currentXp - startXp) / boneXP or if(inventory.interact("Bury", "Bones")) bonesBuried++; or onMessage(Message m) { if(m.getMessage().contains("bury")) bonesBuried++; }} (find the correct message, and only check game messages) Edited December 14, 2015 by FrostBug 1
DebilasTuNX Posted December 14, 2015 Author Posted December 14, 2015 bonesBuried = (currentXp - startXp) / boneXPThats not what i meant, i know how to get how many i burried, but i want ton get how many i picked up too
FrostBug Posted December 14, 2015 Posted December 14, 2015 Thats not what i meant, i know how to get how many i burried, but i want ton get how many i picked up too Same way as the feather issue, then.
Explv Posted December 14, 2015 Posted December 14, 2015 Thats not what i meant, i know how to get how many i burried, but i want ton get how many i picked up too See the first part of the solution i posted, and substitute "Feather" for "Bones" .
herojord Posted December 14, 2015 Posted December 14, 2015 I would go for the solution frostbug gave you: onMessage(Message m) { if(m.getMessage().contains("bury")) bonesBuried++; }} (find the correct message, and only check game messages) Since you can use the same method to track other stuff. 1