The Undefeated Posted December 11, 2017 Share Posted December 11, 2017 (edited) Small but very useful snippet. This will prioritize items with the lowest dose. It returns null if not enough doses are in the bank. Code: Spoiler private HashMap<String,Integer> withdrawDoses(String item, int doses) { int i = 1; HashMap<String,Integer> map = new HashMap<>(); while (doses > 0 && i <= 8) { String itemName = item + "(" + i + ")"; int j = 1; while (doses > 0 && j <= getBank().getAmount(itemName)) { doses = doses - i; if (map.containsKey(itemName)) { map.put(itemName,map.get(itemName) + 1); } else { map.put(itemName,1); } j++; } i++; } if (doses <= 0) { return map; } return null; } private int getCurrentDoses(String item) { int i = 1; int doses = 0; while (i <= 8) { String itemName = item + "(" + i + ")"; int curAmount = (int) (i * getInventory().getAmount(itemName)); doses = doses + curAmount; i++; } return doses; } Usage: Spoiler getBank().withdraw(withdrawDoses("Stamina potion",10)); Edited December 11, 2017 by The Undefeated 6 Quote Link to comment Share on other sites More sharing options...
Deceiver Posted December 11, 2017 Share Posted December 11, 2017 thx Quote Link to comment Share on other sites More sharing options...
Chikan Posted December 11, 2017 Share Posted December 11, 2017 Ty fren 19 minutes ago, Deceiver said: thx I feel like you asked him for this and he posted public Quote Link to comment Share on other sites More sharing options...
Deceiver Posted December 11, 2017 Share Posted December 11, 2017 3 minutes ago, Chikan said: Ty fren I feel like you asked him for this and he posted public i already have a method >:( Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted December 14, 2017 Author Share Posted December 14, 2017 On 12/11/2017 at 9:09 PM, Chikan said: Ty fren I feel like you asked him for this and he posted public He didn't. 1 Quote Link to comment Share on other sites More sharing options...