Jump to content

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


DebilasTuNX
 Share

Recommended Posts

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
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

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