Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Identify personal loot from monster drops

Featured Replies

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 by BobSmokey

  • Author
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!

You can try something along the lines of canLoot. If upon a message that you can't loot, move on to attack next monster.

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.

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();
	}
}

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.