Jump to content

Opening items in inventory


Recommended Posts

Posted

I was making a script that at some point needed to open feather packs, but i cant find a way to open them.

if(getInventory().contains(11881)) {

if inventory contains feather pack, open. but how?
}

I checked the api but couldnt find an answer.

Posted
On 2/1/2021 at 2:16 AM, skillerkidos1 said:

if(inventory.contains("Feather pack")){

 inventory.getItem("Feather pack").interact("Open");
  //add conditional sleep

}

To improve on this, Item#interact returns a boolean if it was successful or not, so you can do

if(inventory.getItemm("Feath pack").interact("Open")) {
 // Conditional sleep that checks if the number of feather packs in your inventory decreased by 1 
}

 

  • Like 3
Posted (edited)
54 minutes ago, Tom said:

To improve on this, Item#interact returns a boolean if it was successful or not, so you can do



if(inventory.getItemm("Feath pack").interact("Open")) {
 // Conditional sleep that checks if the number of feather packs in your inventory decreased by 1 
}

 

I would say it depends on the situation. In case of feather packs, I can imagine you don't want to wait a tick everytime you open one since opening them as quick as possible is what you essentially want. You would probably need different code to prevent trying to interact with a non-existent item.

Edited by Canidae
  • Like 3
Posted

I think this is would be better...

        int chain[] ={0,1,2,3,4,5,6,...,28};
        int chain[] ={0,4,8,12,16,20,24,1,5,9,13,17,...};
        for (int i = 0; i < 28; i++) {
            Item item =getInventory().getItemInSlot(chain[i]);
            if (item!=null &&(item.getName().contains("pack"))){
                getInventory().interact(chain[i],"Open");
              	sleep....
            }

        }

 

  • Like 1
Posted
On 2/1/2021 at 9:05 PM, Nbacon said:

I think this is would be better...


        int chain[] ={0,1,2,3,4,5,6,...,28};
        int chain[] ={0,4,8,12,16,20,24,1,5,9,13,17,...};
        for (int i = 0; i < 28; i++) {
            Item item =getInventory().getItemInSlot(chain[i]);
            if (item!=null &&(item.getName().contains("pack"))){
                getInventory().interact(chain[i],"Open");
              	sleep....
            }

        }

 

This might mess up when trying to pause the script. I would also write it like this:

for (Item item : getInventory().getItems()) {
            if (item != null && item.getName().equals("Feather pack") && item.interact("Open")) {
                //sleep
            }
        }

 

Posted (edited)
On 2/4/2021 at 2:57 AM, Nbacon said:

Our loops do the same exact thing and will fuck up in the same way..... but mine can do diffent chaining types...

You forgot to check if the interaction actually was succesful, this way you can trigger the sleep without actually having opened the pack. 

Edited by Canidae
Posted
48 minutes ago, Nbacon said:

Why would you care if the interaction is succesful? you just click and move on and if it fails come back with a second(slower) pass

I agree, I think it's better to not check if interaction is successful. This way, you won't always open items in the perfect order every time.

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