Jump to content

Interact with all items in the inventory given a name


Recommended Posts

Posted (edited)

I'm making a combat script right now which kill mobs, and if the user requests it will pick up bones and bury them. I wait for the inventory to fill up and then do a check for all of the drop / banking needs of the script.

 

I want to make a method which will work for future uses as well and you can just give it a specific item and interact option and it will iterate over each item in the inventory and execute the interact command.

 

Currently the script has a problem where it will detect all of the bones, it will do the interact command but it gets way ahead of its self. Say if the inventory has 6 bones, it will spam click really bad on the first bone, and sometimes click the second bone and just stop.

 

I didn't want to use a while loop checking to make sure the inventory doesn't have anymore of that item in it since I wanted to make this method as I said more robust and not just for burying bones. So I can use it for multiple commands whenever they come up besides just burying.

 

I was wondering if there's a more elegant way of making sure the command has executed through the client vs just doing random sleeping amounts and hoping the script doesn't miss an item.

Edited by Nebulae
Posted (edited)

Use conditional sleeps when u bury each bone, eg store the valur of bones in inventory then click and wait until the amount of bones in invent is less than the stored value :)

Edit; eg:

if inventory contains bones

oldBones = inventory.getitem("bones").getAmount();

8nventory,".getitem("bones").interact("bury");

new ConditionalSleep(2000) {

@ Override

public boolean condition() throws InterruptedException {

return oldBones > inventory.getitem("bones").getamount;

}

}.sleep();

Sry for text wrote on phone

Edited by IHB
  • Like 1
Posted

Use conditional sleeps when u bury each bone, eg store the valur of bones in inventory then click and wait until the amount of bones in invent is less than the stored value smile.png

Edit; eg:

if inventory contains bones

oldBones = inventory.getitem("bones").getAmount();

8nventory,".getitem("bones").interact("bury");

new ConditionalSleep(2000) {

@ Override

public boolean condition() throws InterruptedException {

return oldBones > inventory.getitem("bones").getamount;

}

}.sleep();

Sry for text wrote on phone

nailed it

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...