Tutorial An API overview & basic concepts - Tutorial 2

Discussion in 'Tutorials & Resources' started by Eagles13, Jul 25, 2015.

  1. 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:

    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.

    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:

    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 (Text):
    2. Bank.open();
    3. Bank.close();
    4. Bank.isOpen();
    5. Bank.deposit("Ironore", 0);
    6. Bank.withdraw("Ironore", 0);
    7. Bank.depositInventory();
    8. Bank.depositEquipment();
    10. if (Bank.getItems("Ironore").size() != 0) {
    11.     System.out.println("We haveiron ore in the bank");
    12. } else {
    13.     System.out.println("We'reout of iron ore in the bank");
    14. }
    16. if (Bank.newQuery().actions("Eat").results().isEmpty()) {
    17.     System.out.println("There'sno more food in the bank!");
    18. }
    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 (Text):
    2. Players.getLocal();
    3. Players.newQuery();
    com.runemate.game.api.hybrid.entities.Player - Representsa single player, and provides useful functionality to access information abouthim/her.
    Code (Text):
    2. Player.getAnimationId();
    3. Player.getName();
    4. Player.getCombatLevel();
    5. Player.getPosition();
    6. Player.getTarget();
    7. 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 (Text):
    2. Interfaces.getAt(0, 0);
    3. Interfaces.newQuery();
    com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent- Allows for the manipulation of a single interface.

    Code (Text):
    2. InterfaceComponent.click();
    3. InterfaceComponent.isVisible();
    4. 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.


    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();


    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 (Text):
    2. public class testbot extends LoopingScript{
    3.     @Override
    4.     public void onLoop() {
    5.         Bank.open();
    6.         Bank.withdraw("Ironore", 28);
    7.         Bank.close();
    8.         /Perform our actions with the iron ore
    9.     }
    10. }
    However, this will work much better:
    Code (Text):
    2. @Override
    3. public void onLoop() {
    4.     if (!Inventory.contains("Ironore")) {
    5.         if (Bank.isOpen()){
    6.             Bank.withdraw("Ironore", 28);
    7.         } else {
    8.             Bank.open();
    9.         }
    10.     } else {
    11.         if (Bank.isOpen()){
    12.             Bank.close();
    13.         } else {
    14.             /Perform ouractions with the iron ore
    15.         }
    16.     }
    17. }
    • 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.
    #1 Eagles13, Jul 25, 2015
    Last edited: Jul 25, 2015
  2. The video is too long? :)
  3. Should be working fine now. Patience is a virtue.
  4. Working fine now, thank you very much :)
  5. #5 Eagles13, Jul 25, 2015
    Last edited: Jul 25, 2015
  6. 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
  7. put "DARK"

Share This Page