Interfaces
Interfaces and components refer to elements of the game's user interface (UI). These are essential parts of interacting with the game’s menus, dialogs, trading windows, inventories, and other on-screen elements. Understanding how interfaces and components work is crucial for writing scripts that interact with the game’s UI.
A component is a smaller element inside an interface. Each interface is made up of multiple components, and these components are the individual buttons, text labels, item slots, or other interactive elements within that interface. Components can also go multiple levels deep, meaning that a component can have children components too!
For example, in the banking interface, the game would have components for:
- The withdraw buttons
- Each of the item slots
- Each of the bank tabs
Each interface has an index, and each of these components has a component index within its interface.
Interface: A whole UI section of the game (e.g., Inventory, Bank)
Component: A part of an interface or component (e.g., individual item slots, buttons)
Scripts interact with these interfaces and components to perform actions like withdrawing items from the bank, selecting options in dialogues, or interacting with inventory items.
For most common interfaces we already provide high level APIs such as Bank, Trade, Shop, Inventory, Magic and so on. However, in some cases you will still need to interact with components yourself.
Using Interfaces and Components in Scripts
Accessing an Interface
You might want to check if an interface is open an visible before performing an action. This can be done by querying for the component.
The in-client Interface Explorer tool allows you to view all sorts of data for components. This includes their indexes as explained above, as well as attributes such as material IDs (textures), model IDs, names and any text they display.
The easy way
InterfaceComponent component = Interfaces.getDirect(interfaceIndex, componentIndex);
If the component is at a deeper level, then you can keep passing more indexes as such:
InterfaceComponent component = Interfaces.getDirect(interfaceIndex, componentIndex, subComponentIndex);
Note: As always, don't forget to null check the component before using it!
Queries
Moving on, component indexes do change every now and then while interface indexes generally remain intact. The best way to deal with these changes is to avoid using component indexes and query for the components attributes instead. Based on what the interface explorer displays, it's up to you to decide which attributes are best to query for. Some may be as simple as searching for text.
Here is an example that queries for a component with the action "Enter Wilderness" under interface 475:
InterfaceComponent component=
Interfaces.query(475)
.actions("Enter Wilderness")
.results()
.first();
This is less prone to breaking and makes it easier to maintain your code in the long run.
Since there can be a lot of components, by default the queries exclude subcomponents to maintain
efficiency. If it's a subcomponent, then you should specify includeSubComponents()
in the query
InterfaceComponent component=
Interfaces.query(475)
.includeSubComponents()
.actions("Enter Wilderness")
.results()
.first();