Interacting with Items and Inventory
In Old School RuneScape (OSRS), items and inventory management are essential for successful gameplay automation. This page explains how to query and interact with items and inventory using the SimpleBot API.
Table of Contents
Querying Items
To interact with items, you first need to find them within the game world. The SimpleBot API provides functions to search for items by various attributes such as name, ID, or actions they can perform. You can learn more about querying in the Querying guide.
Here's an example of how to populate the inventory:
ctx.inventory.populate(); // Populate the inventory
Finding an Item by Name
To find an item in your inventory by name, use the inventory.populate().filter()
method. This returns the first item in your inventory that matches the specified name. Here's an example:
final SimpleItem sword = ctx.inventory.populate().filter("Bronze sword").next();
if (sword != null) {
System.out.println("Found item: " + sword.getName());
} else {
System.out.println("Item Bronze sword not found in inventory.");
}
Finding an Item by ID
To find an item in your inventory by ID, use the inventory.populate().filter()
method with the item ID. This returns the first item in your inventory with the specified ID. Here's an example:
final SimpleItem fish = ctx.inventory.populate().filter(317).next();
if (fish != null) {
System.out.println("Found item: " + fish.getName());
} else {
System.out.println("Item ID 317 not found in inventory.");
}
Interacting with Items
Once you have found an item, you can interact with it in various ways. The SimpleBot API provides two methods to interact with items: click()
and menuAction()
.
The click()
method uses the built-in SimpleBot Mouse API to interact with items and has two overloads: one for clicking a specific action by action name and another for clicking the item by action index.
The menuAction()
method uses the built-in SimpleBot Menu Action API to interact with items and has two overloads: one for sending a specific action by action name and another for sending a specific action by menu action id.
Interacting with an item using click()
To interact with an item using the click()
method, you can specify the action name or action index.
Using the action name click("Eat")
will ALWAYS perform an action using a right-click, while using the action index click(0)
will ONLY perform a right-click if the index is greater than 0.
Here's an example of clicking an item using both:
final SimpleItem shark = ctx.inventory.populate().filter("Shark").next();
if (shark != null) {
// Click the "Eat" action on the item
shark.click("Eat");
// Click the item by action index (0 is the first action). This will perform a left-click if the index is 0.
shark.click(0);
} else {
System.out.println("Item Shark not found in inventory.");
}
Interacting with an item using menuAction()
To interact with an item using the menuAction()
method, you can specify the action name or menu action id.
Here's an example of sending a menu action to an item using both:
final SimpleItem shark = ctx.inventory.populate().filter("Shark").next();
if (shark != null) {
// Send the "Eat" action to the item
shark.menuAction("Eat");
// Send the menu action by menu action id (you can find the menu action id by using the SimpleBot Menu Action Debugger dev tool)
shark.menuAction(3);
} else {
System.out.println("Item Shark not found in inventory.");
}