CharlesWoodchuck Posted February 14, 2020 Posted February 14, 2020 Writing a combat fighter/loot/banking script. loot = GroundItem lootList = String[] {"Stuff", "To", "Loot"} Anyone have recommendations for how to improve this? or other ways that you loot that could be better? current onLoop() order if(lootExists()){ loot(); } methods private boolean lootExists() { for (int i = 0; i < lootList.length; i++) { loot = groundItems.closest(lootList[i]); if (loot != null && loot.exists()) { log("Loot exists!"); return true; } } return false; } private void loot() { for (int i = 0; i < lootList.length; i++) { loot = groundItems.closest(lootList[i]); if (loot != null && loot.exists() && getMap().canReach(loot) && loot.isVisible()) { log("loot: " + loot); loot.interact("Take"); log("Taking loot"); } } }
Gunman Posted February 14, 2020 Posted February 14, 2020 @CharlesWoodchuck You could make it grab the items on the tile at which the npc died and grab all the items. Could also add something that would grab the price of the items and loot the most expensive item first. 1
BrainDeadGenius Posted February 14, 2020 Posted February 14, 2020 You're also looping your loot list twice. Inefficient, so I recommend not.
Camaro Posted February 14, 2020 Posted February 14, 2020 Using my Simple Continuous Loop Class, Spoiler private void pickUpItems(List<GroundItem> items) { Loop.until(getBot(), () -> { GroundItem item = items.get(0); log("Attempting to pick up " + item.getName()); if (generalTasks.interact(item, "Take") && Timing.waitCondition(() -> !item.exists(), 3000)) { log("Successfully picked up item"); items.remove(item); } else if (!item.exists()) { items.remove(item); } }, items::isEmpty); }