Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Tutorial An API overview & basic concepts - Tutorial 2

The only thing Alpha about me is my bots
Joined
Sep 22, 2014
Messages
618
Tutorial 2: An API overview & basic concepts

This is the second tutorial in a series, if you'd like to see more, take a look at this thread:
https://www.runemate.com/community/...bots-for-runemate-from-novice-to-expert.2322/

This tutorial takes you through some of the most important features of the RuneMate API, including navigation, the newQuery API, areas & coordinates, etc. It also introduces the concept of one action per loop.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.


For the presentation used in the tutorial, see here:
https://dl.dropboxusercontent.com/u/7543521/Images/RuneMate/Tutorials/RuneMate Tutorial 2.pptx
If you want to further familiarise yourself with the API, take a look at the jdocs here:
https://www.runemate.com/developer/jdocs/




RuneMate Tutorial 2 Manuscript
Note: Skip this if you intend to watch the video and/or download the PowerPoint presentation.
In this video:

  • A broad overview of some essential API features
  • The newQuery API
  • Navigation methods
  • Different types of paths & basic navigation
  • The onLoop() event & safe bot logic
  • An introduction to the other events in a LoopingScript.

Essential API Features (1):

com.runemate.game.api.hybrid.local.hud.interfaces.Bank - used toaccess the bank:
Code:
Bank.open();
Bank.close();
Bank.isOpen();
Bank.deposit("Ironore", 0);
Bank.withdraw("Ironore", 0);
Bank.depositInventory();
Bank.depositEquipment();

if (Bank.getItems("Ironore").size() != 0) {
    System.out.println("We haveiron ore in the bank");
} else {
    System.out.println("We'reout of iron ore in the bank");
}

if (Bank.newQuery().actions("Eat").results().isEmpty()) {
    System.out.println("There'sno more food in the bank!");
}

com.runemate.game.api.hybrid.local.hud.interfaces.Inventory - much thesame as the bank, but for the inventory.
com.runemate.game.api.hybrid.local.hud.interfaces.Equipment - much thesame as the inventory, but for the worn equipment.



Essential API Features (2):
com.runemate.game.api.hybrid.entities.Players - Used toaccess players.


Code:
Players.getLocal();
Players.newQuery();

com.runemate.game.api.hybrid.entities.Player - Representsa single player, and provides useful functionality to access information abouthim/her.
Code:
Player.getAnimationId();
Player.getName();
Player.getCombatLevel();
Player.getPosition();
Player.getTarget();
Player.distanceTo(entity);

com.runemate.game.api.hybrid.entities.Npcs - Used toaccess NPCs, in much the same way as Players.
com.runemate.game.api.hybrid.entities.Npc - Representsa single player, in much the same way as Player.


Essential API Features (3):

com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces – used forinterface handling – for example the make-x interface, the GE, or otherinterfaces which are not wrapped in the API.

Code:
Interfaces.getAt(0, 0);
Interfaces.newQuery();

com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent- Allows for the manipulation of a single interface.

Code:
InterfaceComponent.click();
InterfaceComponent.isVisible();
InterfaceComponent.getText();


com.runemate.game.api.hybrid.location.Coordinate - Used torepresent a single "square" on the RuneScapesurface.

com.runemate.game.api.hybrid.location.Area - Used torepresent an area made up of one or more coordinates on the RuneScapesurface. Areas can be rectangular, circular, polygonal or absolute.



Essential API features: newQueryAPI

The newQuery API is amethod of locating very particular objects & entities within the game thatyou may want to use. It allows you to locate extremely specific entities,normally using a single line of code, where traditionally it might take severallines of code, and even complex iteration in order to achieve the sameresults.



Bank.newQuery().actions("Eat").results().first();


Npcs.newQuery().names("Man").within(new Area.Circular(player.getPosition(), 5)).actions("Attack").reachable().results().random();



Interfaces.newQuery().containers(1244).filter(e -> e.getContainedItem().getName().equals("Iron Longsword")).results().first();





Navigation:

The API provides several different methods ofgetting around RuneScape, by way of using paths. Pathtypes are as follows:

· Region paths
· The good: region paths take obstacles intoaccount, so they won’t lead to the player getting stuck anywhere. They alsohave significant entropy, meaning that they are likely the least detectable ofall walking methods.
· The bad: Region paths only work in a 102x102grid, with the player being at the center of thatgrid. If you try to generate a Region path any further away than that, it willreturn null.
· Web paths
· The good: web paths are similar to RegionPaths, but they work all over RuneScape,and are extremely useful. Dfsdfasd
· The bad: web paths are the most resourceintensive to generate, and have slightly less entropy than region paths.
· The ugly: the web is often difficult andcounter-intuitive to extend.
· Bresenham paths
· The good: useful as an option to fall back on if other methods fail.
· The bad: Bresenhampaths are straight paths, and are not aware of any obstacles – meaning thatusing Bresenham paths to travel large distances canlead to the player getting stuck.
· The ugly: Bresenhampaths have little entropy.
· ViewPort paths
· Viewport paths are unlike any type of otherpath, in that they don’t actually generate a path to a particular place, insteadthey transform any of the other three types of path into a type of path whichcan be traversed without using the minimap – the pathwill be traversed by clicking on objects to go to in the main game viewport.



Navigation: A graphical example





The onLoop() event

The onLoop() event is an event which must be overridden in any LoopingScript which contains the main logic for the bot.For example, if we wanted to write a bot which opens the bank, withdraws ironore, and then closes the bank, we would have to tell the LoopingScriptto do this (programmatically) in the onLoop() event.



The onLoop event

This will not work well:
Code:
public class testbot extends LoopingScript{
    @Override
    public void onLoop() {
        Bank.open();
        Bank.withdraw("Ironore", 28);
        Bank.close();
        /Perform our actions with the iron ore
    }
}
However, this will work much better:
Code:
@Override
public void onLoop() {
    if (!Inventory.contains("Ironore")) {
        if (Bank.isOpen()){
            Bank.withdraw("Ironore", 28);
        } else {
            Bank.open();
        }
    } else {
        if (Bank.isOpen()){
            Bank.close();
        } else {
            /Perform ouractions with the iron ore
        }
    }
}

  • The onStart event:
    • The onStart event fires as soon as your bot is started (duh!). In this event, it’s often useful to be able to ask the and user what they want the bot to do (using a GUI and controls – tutorial on this coming soon).
    • It’s highly recommended that you use the setLoopDelay(int, int) in this event to specify how often your LoopingScript should loop, as the default value (25, 50) may cause performance problems.
    • You may want to start a timer/stopwatch in this event in order to track XP over time, kills over time, or any other time-dependent statistics.
  • The onPause event:
    • Fires when the bot is paused. You may want to pause any running timers in this event.
  • The onResume event:
    • I’m sure you can work this one out.
  • The onStop event:
    • Fires when the bot is stopped.You will certainly want to dispose of any resources in this event, stop any running timers, or recurring events, and if you have any form of stat-tracking implemented, make sure that the data from the current session is submitted.
 
Last edited:
The only thing Alpha about me is my bots
Joined
Sep 22, 2014
Messages
618
Should be working fine now. Patience is a virtue.
 
Joined
Oct 13, 2015
Messages
10
What about DarkScape in the part where I need to input my forum credentials and the game type? DS? or what?

edit: sorry wrong part of tutorial :s
 
Joined
May 6, 2017
Messages
6
This tutorial is definitely front page worthy. Maybe even pin worthy.

Good job giving a good overview of the API for new bot developers.
 
Joined
Sep 21, 2018
Messages
20
is there an updated guide, i get null ref pointers trying to run any of the commands above in onloop, furthermore extending from loopingscript is deprecated and is now loopingbot.
 
Top