H0rn Posted August 18, 2017 Share Posted August 18, 2017 (edited) I've tried a couple of ways to do this, for example if the bank contains a charged glory or stamina potion, basically I am trying to use the lowest value of charge/stamina before going back to the (6) or (4) Could anyone post a snippet? I've tried searching about, but I am sort of new to lists What I have so far: String[] gloryNames = {"Amulet of glory(1)", "Amulet of glory(2)", "Amulet of glory(3)", "Amulet of glory(4)", "Amulet of glory(5)", "Amulet of glory(6)"}; if (needGlory == true && bank.contains(gloryNames)){ new ConditionalSleep(random(5000,7000)) { public boolean condition() { if (getBank().withdraw(bank.getSlot(gloryNames),1)) { getStatus = "Withdraw glory";} return inventory.contains(gloryNames.toString()); } }.sleep(); inventory.interact(inventory.getSlot(gloryNames.toString()), "Wear"); } Edited August 18, 2017 by OllieW Quote Link to comment Share on other sites More sharing options...
Abysm Posted August 18, 2017 Share Posted August 18, 2017 you could just use multiple else if? I dont know if thats really inefficient tho 1 Quote Link to comment Share on other sites More sharing options...
H0rn Posted August 18, 2017 Author Share Posted August 18, 2017 1 minute ago, Abysm said: you could just use multiple else if? I dont know if thats really inefficient tho Thats why I was avoiding that, I am certain there's a better way :\ will use that for now I guess Quote Link to comment Share on other sites More sharing options...
Rekt Posted August 18, 2017 Share Posted August 18, 2017 19 minutes ago, OllieW said: Thats why I was avoiding that, I am certain there's a better way :\ will use that for now I guess Optional<Item> gloryNames= Arrays.stream(getInventory().getItems()).filter(i -> i != null && (i.nameContains("Amulet of glory(1)") || i.nameContains("Amulet of glory(2)"))).findFirst(); Try This 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 18, 2017 Share Posted August 18, 2017 zz Just use a for loop, if need glory and bank open iterate through the glory strings (1,...6) if has glory, withdraw (cond sleep) if inv contains a glory, break the for loop need glory bool should be flase now Quote Link to comment Share on other sites More sharing options...
H0rn Posted August 18, 2017 Author Share Posted August 18, 2017 18 minutes ago, dreameo said: zz Just use a for loop, if need glory and bank open iterate through the glory strings (1,...6) if has glory, withdraw (cond sleep) if inv contains a glory, break the for loop need glory bool should be flase now Sorry4noob but can you give an example? I haven't used for loops very much, understand how they work but don't understand how they would work in this instance. Quote Link to comment Share on other sites More sharing options...
Explv Posted August 18, 2017 Share Posted August 18, 2017 You could try doing something like: Optional<Item> glory = Arrays.stream(getBank().getItems()).filter(item -> item.getName().startsWith("Amulet of glory(")).min((g1, g2) -> g1.getName().compareTo(g2.getName())) Sorry for any syntax errors, on phone 1 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted August 18, 2017 Share Posted August 18, 2017 12 minutes ago, OllieW said: Sorry4noob but can you give an example? I haven't used for loops very much, understand how they work but don't understand how they would work in this instance. Something like for (String : gloryString) { if bank contains glory string { withdraw glory } } 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 18, 2017 Share Posted August 18, 2017 // assuming bank is open because needGlory is true String[] glorys = [...] if(getBank().isOpen) { for(String glory : glorys) { if(getBank().contains(glory) { if(getBank().withdraw(glory, 1) { cond sleep // inv contains glory break; // exit loop since we have item // needGlory should be false now } { } // script should exit here since bank contains no glory stop(true); } Not tested, insert the condition sleep, (maybe few syntax errors idk, just wrote it here) 2 Quote Link to comment Share on other sites More sharing options...
liverare Posted August 18, 2017 Share Posted August 18, 2017 My favourite thing about programming is that there's literally a million different ways of doing things: public void withdrawGlory() { Item glory = Stream .of(bank.getItems()) // stream of all bank items .filter(ScriptName::isAmuletOfGlory) // filter for glories .findFirst() // get first glory .orElse(null); // null if (glory != null) { // do something } } public static boolean isAmuletOfGlory(Item item) { return item.getName().contains("glory("); } 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted August 18, 2017 Share Posted August 18, 2017 15 minutes ago, liverare said: My favourite thing about programming is that there's literally a million different ways of doing things: public void withdrawGlory() { Item glory = Stream .of(bank.getItems()) // stream of all bank items .filter(ScriptName::isAmuletOfGlory) // filter for glories .findFirst() // get first glory .orElse(null); // null if (glory != null) { // do something } } public static boolean isAmuletOfGlory(Item item) { return item.getName().contains("glory("); } This would just get any glory, he's looking to prioritize getting glories with the lowest charge (1),(2)...(n) 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted August 18, 2017 Share Posted August 18, 2017 (edited) 23 minutes ago, dreameo said: This would just get any glory, he's looking to prioritize getting glories with the lowest charge (1),(2)...(n) You can use Explv's "min" statement. It's easy to make the adaptation: private void withdrawGlory() { Item glory = Stream .of(bank.getItems()) // all bank items .filter(ScriptName::isAmuletOfGlory) // glories only (which includes eternal glory) .min(ScriptName::sortByItemName) // get first glory, but not before sorting them by item name .orElse(null); // return result glory, or else return null if (glory != null) { // do something } } public static int sortByItemName(Item a, Item b) { String aa = a.getName(); String bb = b.getName(); return aa.compareTo(bb); } public static boolean isAmuletOfGlory(Item item) { return item.getName().contains("glory"); } Edited August 18, 2017 by liverare 1 Quote Link to comment Share on other sites More sharing options...
H0rn Posted August 18, 2017 Author Share Posted August 18, 2017 Thanks for the replies all, I managed to get it working using @dreameo snippit Quote Link to comment Share on other sites More sharing options...