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.

Using an item on an other item

Featured Replies

Probably a very simple solution but I can't seem to find it while searching through osbot API. I simply want to use an item on another (for example using a needle on leather or knife on logs).

I found the following method but how do I make it click on a certain item after?

getInventory().getItem("Needle").interact("Use")

Thankful for answers.

  • Author
4 minutes ago, Token said:

Interact with the second item after interacting with the first one

Would this work?

getInventory().getItem("Knife").interact("Use");
getInventory().getItem("Log").interact();
2 hours ago, barackogama said:

Probably a very simple solution but I can't seem to find it while searching through osbot API. I simply want to use an item on another (for example using a needle on leather or knife on logs).

I found the following method but how do I make it click on a certain item after?


getInventory().getItem("Needle").interact("Use")

Thankful for answers.

 

if (!"Needle".equals(getInventory().getSelectedItemName())) {
    if (getInventory().isItemSelected()) {
        getInventory().deselectItem();
    } else {
        getInventory().interact("Use", "Needle");
    }
} else if (getInventory().getItem("Leather").interact()) {
    new ConditionalSleep(2000) {
        @Override
        public boolean condition() throws InterruptedException {
            return getWidgets().getWidgetContainingText("Choose a quantity, then click an item to begin") != null;
        }
    }.sleep();
}


 

I wrote this ad-hoc and untested function:

public boolean useItemOnItem(String itemA, String itemB)
	throws IllegalArgumentException, RuntimeException {
	
	/* Variables */
	boolean successful = false;
	String selectedItemName;
	
	/* Validation */
	if (itemA == null || itemA.isEmpty()) {
		throw new IllegalArgumentException("Parameter \"itemA\" is invalid!");
	} else if (itemB == null || itemB.isEmpty()) {
		throw new IllegalArgumentException("Parameter \"itemB\" is invalid!");
	} else if (itemA == itemB) {
		throw new IllegalArgumentException("Parameter \"itemA\" and \"itemB\" must be different!");
	} else if (!inventory.contains(itemA)) {
		throw new RuntimeException("Inventory doesn't contain: " + itemA);
	} else if (!inventory.contains(itemb)) {
		throw new RuntimeException("Inventory doesn't contain: " + itemB);
	}
	
	/* Process */
	selectedItemName = inventory.getSelectedItemName();
	if (selectedItemName != null) {
		if (selectedItemName == itemA) {
			/* Now click on item B */
			successful = inventory.getItem(itemB).interact();
		} else if (selectedItemName == itemB) {
			/* Now click on item A */
			successful = inventory.getItem(itemA).interact();
		} else {
			/* Deselect and then re-try (safe recursion) */
			if (inventory.deselectItem()) {
				useItemOnItem(itemA, itemB);
			} else {
				throw new RuntimeException("Failed to deselect: " + selectedItemName);
			}
		}
	} else {
		/* Select item and re-try (safe recursion) */
		if (inventory.interact("Use", itemA)) {
			successful = useItemOnItem(itemA, itemB);
		} else {
			throw new RuntimeException("Failed to select: " + itemA);
		}
	}
	
	return successful;
}

Then you could do:

try {
    if (useItemOnItem("Needle", "Thread")) {
        /* Conditional sleep */
    }
} catch (IllegalArgumentException e) {
    /* I should have checked we have items before executing the function */
} catch (RuntimeException e) {
    /* Something bad happened... */
}

 

  • Author

Is there a simple way to not always interact with the first item found with the Interact-methods?

Ty for the help btw, I applied your solutions to my code and it's working well,

Edited by barackogama

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.