Jump to content

How to track how much i picked up of one specific item?


Recommended Posts

Posted (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 by Explv
  • Like 1
Posted
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?
Posted (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 by FrostBug
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...