BobSmokey Posted March 10, 2018 Posted March 10, 2018 (edited) Hey guys. I would like to make a script that kills a monster and then picks up valuable drops. The problem, however is that I am ironman. I need a way to idenify whether a drop is owned by my account. How would I do that? [Edit] Osbuddy pro is able to identify personal drops. Edited March 10, 2018 by BobSmokey
Juggles Posted March 10, 2018 Posted March 10, 2018 find monster you are interacting with, get position of monster, store position, then loot items only on that position 1
BobSmokey Posted March 10, 2018 Author Posted March 10, 2018 3 minutes ago, Juggles said: find monster you are interacting with, get position of monster, store position, then loot items only on that position ts not fail proof but I could flag items that are 100% surely not dropped by my monsters. thanks!
Charlotte Posted March 10, 2018 Posted March 10, 2018 You can try something along the lines of canLoot. If upon a message that you can't loot, move on to attack next monster.
Hannes7337 Posted March 11, 2018 Posted March 11, 2018 I'd say check for grounditems at the monster's position during the fight and store it in, for example, a list. Update the list only when the grounditems change during the fight. When your monster is dead the newly dropped items should be yours. For a failsafe I'd check for a message that' you can't loot this item" and skip the looting. This method shouldn't cost to much performance I think. Hope this helps.
liverare Posted March 11, 2018 Posted March 11, 2018 I don't think there exists a way to differentiate ground items like this. A possible workaround is to cache the ground items and flag the ground items you can't pickup. I wrote untested ad-hoc example you can try: Example code public class Test extends Script { IronManLootingAPI ironManLootingAPI; @Override public void onStart() throws InterruptedException { ironManLootingAPI = new IronManLootingAPI(); ironManLootingAPI.exchangeContext(bot); ironManLootingAPI.initializeModule(); } @Override public int onLoop() throws InterruptedException { // 1. find all existing ground items by calling "refresh" if (ironManLootingAPI.refresh()) { // 2. find a specific item if (ironManLootingAPI.find("Abyssal whip", "Abyssal dagger", "Gilded platelegs")) { // 3. Do your looting here if (ironManLootingAPI.getFound().interact("Take")) { /* * The IronManLootingAPI has a message listener * if it detects "You're an Iron Man, so you can't take that." */ if (ironManLootingAPI.isNotYours()) { logger.debug("Aww shucks..."); } } } } return 250; } } Iron Man Looting API (IronManLootingAPI.java) import java.util.Iterator; import java.util.Map; import java.util.WeakHashMap; import java.util.Map.Entry; import java.util.function.Predicate; import java.util.stream.Collectors; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.api.ui.Message.MessageType; import org.osbot.rs07.listener.MessageListener; import org.osbot.rs07.script.API; public class IronManLootingAPI extends API implements MessageListener { Map<GroundItem, Boolean> groundItems; Entry<GroundItem, Boolean> groundItemEntry; @Override public void initializeModule() { groundItems = new WeakHashMap<>(); bot.addMessageListener(this); } @Override public void onMessage(Message messageObj) throws InterruptedException { if (messageObj.getType() == MessageType.GAME) { if (messageObj.getMessage().equals("You're an Iron Man, so you can't take that.")) { if (groundItemEntry != null) { groundItemEntry.setValue(Boolean.FALSE); } } } } /** * To clear all entries */ public void reset() { groundItems.clear(); } /** * Reload all ground items * * @return Ground items found */ public boolean refresh() { // turn List<GroundItem> to Map<GroundItem, Boolean.TRUE> Map<GroundItem, Boolean> newGroundItems = super.groundItems.getAll().stream() .collect(Collectors.toMap(item -> item, item -> Boolean.TRUE)); removeInvalidGroundItems(); newGroundItems.forEach(groundItems::putIfAbsent); return !groundItems.isEmpty(); } /** * Find item by predicate * * @param predicate * @return */ public boolean find(Predicate<GroundItem> predicate) { removeInvalidGroundItems(); groundItemEntry = groundItems .entrySet() .stream() .filter(entry -> entry.getValue().equals(Boolean.TRUE)) .filter(entry -> predicate.test(entry.getKey())) .findFirst() .orElse(null); return (groundItemEntry != null); } /** * Find item by name * * @param itemNameArray * @return */ public boolean find(String... itemNameArray) { return find(item -> { boolean result = false; String itemName = item.getName(); for (String itemNameElement : itemNameArray) { if (itemName.equalsIgnoreCase(itemNameElement)) { result = true; break; } } return result; }); } /** * Remove items that have despawned/been taken */ private void removeInvalidGroundItems() { Iterator<Entry<GroundItem, Boolean>> iterator = groundItems.entrySet().iterator(); Entry<GroundItem, Boolean> entry; GroundItem groundItem; while (iterator.hasNext()) { entry = iterator.next(); groundItem = entry.getKey(); if (groundItem == null || !groundItem.exists()) { iterator.remove(); } } } /** * * @return Cached ground item */ public GroundItem getFound() { return groundItemEntry != null ? groundItemEntry.getKey() : null; } public boolean isNotYours() { return groundItemEntry != null && !groundItemEntry.getValue(); } } 2