Syndo Posted January 31, 2021 Share Posted January 31, 2021 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. Quote Link to comment Share on other sites More sharing options...
skillerkidos1 Posted January 31, 2021 Share Posted January 31, 2021 if(inventory.contains("Feather pack")){ inventory.getItem("Feather pack").interact("Open"); //add conditional sleep } Quote Link to comment Share on other sites More sharing options...
Syndo Posted January 31, 2021 Author Share Posted January 31, 2021 3 minutes ago, skillerkidos1 said: if(inventory.contains("Feather pack")){ inventory.getItem("Feather pack").interact("Open"); //add conditional sleep } Thanks! 1 Quote Link to comment Share on other sites More sharing options...
Tom Posted February 1, 2021 Share Posted February 1, 2021 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 } 3 Quote Link to comment Share on other sites More sharing options...
Canidae Posted February 1, 2021 Share Posted February 1, 2021 (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 February 1, 2021 by Canidae 3 Quote Link to comment Share on other sites More sharing options...
Nbacon Posted February 1, 2021 Share Posted February 1, 2021 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.... } } 1 Quote Link to comment Share on other sites More sharing options...
Canidae Posted February 3, 2021 Share Posted February 3, 2021 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 } } Quote Link to comment Share on other sites More sharing options...
Nbacon Posted February 4, 2021 Share Posted February 4, 2021 17 hours ago, Canidae said: This might mess up when trying to pause the script. I would also write it like this: Our loops do the same exact thing and will fuck up in the same way..... but mine can do diffent chaining types... Quote Link to comment Share on other sites More sharing options...
Canidae Posted February 7, 2021 Share Posted February 7, 2021 (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 February 7, 2021 by Canidae Quote Link to comment Share on other sites More sharing options...
Nbacon Posted February 7, 2021 Share Posted February 7, 2021 26 minutes ago, Canidae said: You forgot to check if the interaction actually was succesful, this way you can trigger the sleep without actually having opened the pack. 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 Quote Link to comment Share on other sites More sharing options...
Jarl Posted February 7, 2021 Share Posted February 7, 2021 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. 1 Quote Link to comment Share on other sites More sharing options...