August 18, 20178 yr 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, 20178 yr by OllieW
August 18, 20178 yr Author 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
August 18, 20178 yr 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
August 18, 20178 yr 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
August 18, 20178 yr Author 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.
August 18, 20178 yr 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
August 18, 20178 yr 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 } }
August 18, 20178 yr // 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)
August 18, 20178 yr 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("); }
August 18, 20178 yr 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)
August 18, 20178 yr 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, 20178 yr by liverare
August 18, 20178 yr Author Thanks for the replies all, I managed to get it working using @dreameo snippit
Create an account or sign in to comment