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.

Custom inventory interact method

Featured Replies

	/*
	 * public boolean interactInv will return true/false whether it was capable of interacting with an inventory item given the specified interaction.
	 */
	public boolean interactInv(String itemName, String interact) throws InterruptedException{
                //create an inventory variable for less typing.
                Inventory in = client.getInventory();
		//check if inventory contains item
		if(in.contains(itemName)){
			//create a mouse destination based off of a rectangle created around the slot of the item
			MouseDestination md = new RectangleDestination(in.getDestinationForSlot(in.getSlotForName(itemName)));
			//move the mouse over the slot
			if(!client.moveMouseTo(md, false, false, false))
                                return false;
			//create a list of the options available in the menu, cycle through them to find specified interaction
			List<Option> menu_option = client.getMenu();
			int use = 999;
			for(Option opt : menu_option){
				if(opt != null){
					if(opt.action.compareToIgnoreCase(interact) == 0){
						use = menu_option.indexOf(opt);
						break;
					}
				}
			}
			//if the option was the first in the list, left click it and return true.
			if(use == 0){
				return client.moveMouseTo(md, false, true, false);
			}
			//if use != 999, it was found in the options list.
			if(use != 999){
				//move mouse over the slot, right click it. (could be replaced with client.moveMouse(md,true))
				if(!client.moveMouseTo(md, false, true, true))
                                        return false;
				//create a new mouse destination based a new rectangle created over interact option of the menu
				md = new RectangleDestination(new Rectangle(client.getMenuX(), client.getMenuY() + 19 + use * 15, client.getMenuWidth(), 14));
				//click the mouse
				return client.moveMouseTo(md, false, true, false);
			}
			else{
				//the interact option wasn't found in the list, return false
				sleep(25);
				return false;
			}
		}
		else
                        return false;
	}

This can be adapted for NPC's, RS2Object's, items in a bank, etc.

Any improvements/suggestions are appreciated. biggrin.png

Edited by Nezz

A couple things:

  1. Remove the random "sleep(50)" you have when right clicking an item as the menu opens on mouse press and not release.
  2. You can create a RectangleDestination to move your mouse to in one line instead of creating two different variables like you're doing, just pass a RectangleDestination the bounds of the slot you need (aka a Rectangle).
  3. moveMouse returns a boolean for a reason. Return the value returned by the method to see if it really did complete successfully.
  4. Arrays.asList is a great method to use for things like this. Just use the get(0) method to see if the action you want is the first one instead of iterating through them.
  5. Instead of an enhanced for loop just increment until your value is equal to the array size, then break because the action would not have been found.

I wrote this a few days ago for a friend. Haven't tested it out but it should be beneficial if you don't understand my points :)

public boolean interactInventoryItem(String itemName, String interaction) throws InterruptedException {
        Item[] items = client.getInventory().getItems();
        if (items == null)
                return false;
        RectangleDestination itemDestination = new RectangleDestination(new Rectangle(client.getInventory().getDestinationForSlot(client.getInventory().getSlotForName(itemName)).getBounds()));
        for (Item currentItem : items) {
                if (currentItem.getName().equalsIgnoreCase(itemName)) {
                        String[] itemActions = currentItem.getDefinition().getActions();
                        if (itemActions[0].equalsIgnoreCase(interaction))
                                return client.moveMouseTo(itemDestination, false, true, false);
                        else {
                                for (int i = 1; i < itemActions.length; i++) {
                                        if (itemActions[i].equalsIgnoreCase(interaction)) {
                                                client.moveMouseTo(itemDestination, false, true, true);
                                                if (client.isMenuOpen()) {
                                                        List<Option> options = client.getMenu();
                                                        for (int j = 0; j < options.size(); j++) {
                                                                if (options.get(i).action.equalsIgnoreCase(interaction)) {
                                                                        return client.moveMouseTo(new RectangleDestination(client.getMenuX(), client.getMenuY()+21+i*14, client.getMenuWidth(), 10), false, true, false);
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
        return false;
}
  • Author

you use too much of the osbot api make your own inventory class!

My goal isn't to make my own inventory class.

It's just a custom method to interacting with an item in your inventory.

It uses osbot api, but it uses osbot api that works consistently. I don't see an issue with that.

Guest
This topic is now closed to further replies.

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.