Jump to content

Help with looping inventory


Recommended Posts

Posted

Hey guys sorry im rushed n looking for a quick answer i have this loop

	while (this.inventory.contains(new String[] { "Ferret" })){
    		for (Item fr : inventory.getItems()) {   			
    			if (fr.getId() == 10092) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}
    	}

 and instead of going to the item it just sits there i tired debugging it but im strapped for time anyone run into this before?

Posted (edited)
if(inventory.contains(10092)//assuming ferret id is 10092
inventory.interact("Release",10092);


Not sure if that's what you wanted or not, but I feel ilke that's what I read. so long as you have 10092 in your inventory it will go through this until your dont.

Edited by twin 763
Posted
if(inventory.contains(10092)//assuming ferret id is 10092
inventory.interact("Release",10092);


Not sure if that's what you wanted or not, but I feel ilke that's what I read. so long as you have 10092 in your inventory it will go through this until your dont.

 

 

tired but it freaks out does one then just jumps along the others and is very slow. error is with the fr.getid equalling 10092 and yes using 10092 ids the ferrets inventory id

Posted (edited)

The script already runs on a loop, so my modified version of your code should work :)

 

Hey guys sorry im rushed n looking for a quick answer i have this loop

	while (this.inventory.contains(new String[] { "Ferret" })){
    		for (Item fr : inventory.getItems()) {   			
    			if (fr.getId() == 10092) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}
    	}

 and instead of going to the item it just sits there i tired debugging it but im strapped for time anyone run into this before?

                for (Item fr : inventory.getItems()) {   			
    			if (fr.getName().equals("Ferret")) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}
Edited by Valkyr
Posted

The script already runs on a loop, so my modified version of your code should work :)

for (Item fr : inventory.getItems()) {   			    			if (fr.getName().equals("Ferret")) {    				fr.interact("Release");    				sleep(random(500, 600));    			}    		}
shouldn't you include a null check on fr? Because he says it is throwing an error where is checks the id which would lead me to believe it is an NPE. I may be wrong :)

Precise

Posted

 

The script already runs on a loop, so my modified version of your code should work smile.png

                for (Item fr : inventory.getItems()) {   			
    			if (fr.getName().equals("Ferret")) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}

This worked out perfect I kinda had an idea to use the name but i went with id, I see this api is slightly different than i've scrip[ted before but thanks to the community I hope to get the hang of it fast! Thank you Valk

 

shouldn't you include a null check on fr? Because he says it is throwing an error where is checks the id which would lead me to believe it is an NPE. I may be wrong smile.png

Precise

IT wouldn't execute as the condition of state checks for  the item before executing

Posted (edited)
 
for(int i = 0; i < 28; i ++){
    item = instance.inventory.getItemInSlot(i);
    if(item == null) continue;

         instance.inventory.interact(i, "Drop");
         for(int temp = 0; temp < i; temp ++){ //This part of the method should counter
             Item tempItem = instance.inventory.getItemInSlot(temp); // items being skipped due to unknown causes, presumably lag.
             if(tempItem != null)){
                   MethodProvider.sleep(MethodProvider.random(200,400));
                   inventory.interact(temp, "Drop");
}
}
}
}

You can probably change this around a bit, but what it does is goes back when items are accidentally skipped due to lag, instead of looping through the entire inventory, then checking if there are items left over. Snippet I provided is not very bot like.

 

Just add the ferret check line, and you should be all G

Edited by Mykindos
Posted
 
for(int i = 0; i < 28; i ++){
    item = instance.inventory.getItemInSlot(i);
    if(item == null) continue;

         instance.inventory.interact(i, "Drop");
         for(int temp = 0; temp < i; temp ++){ //This part of the method should counter
             Item tempItem = instance.inventory.getItemInSlot(temp); // items being skipped due to unknown causes, presumably lag.
             if(tempItem != null)){
                   MethodProvider.sleep(MethodProvider.random(200,400));
                   inventory.interact(temp, "Drop");
}
}
}
}

You can probably change this around a bit, but what it does is goes back when items are accidentally skipped due to lag, instead of looping through the entire inventory, then checking if there are items left over. Snippet I provided is not very bot like.

 

Just add the ferret check line, and you should be all G

 

 

Thanks kindo may need this now because it will jsut randomly stop on items that arent the ferret n sit there haha!!!

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