1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tutorial An API overview & basic concepts - Tutorial 2

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

  1. Eagles13

    Eagles13 The only thing Alpha about me is my bots

    Joined:
    Sep 22, 2014
    Messages:
    618
    Likes Received:
    186
    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.




    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 (Text):
    1.  
    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();
    9.  
    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. }
    15.  
    16. if (Bank.newQuery().actions("Eat").results().isEmpty()) {
    17.     System.out.println("There'sno more food in the bank!");
    18. }
    19.  
    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):
    1.  
    2. Players.getLocal();
    3. Players.newQuery();
    4.  
    com.runemate.game.api.hybrid.entities.Player - Representsa single player, and provides useful functionality to access information abouthim/her.
    Code (Text):
    1.  
    2. Player.getAnimationId();
    3. Player.getName();
    4. Player.getCombatLevel();
    5. Player.getPosition();
    6. Player.getTarget();
    7. Player.distanceTo(entity);
    8.  
    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):
    1.  
    2. Interfaces.getAt(0, 0);
    3. Interfaces.newQuery();
    4.  
    com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent- Allows for the manipulation of a single interface.

    Code (Text):
    1.  
    2. InterfaceComponent.click();
    3. InterfaceComponent.isVisible();
    4. InterfaceComponent.getText();
    5.  

    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 (Text):
    1.  
    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. }
    11.  
    However, this will work much better:
    Code (Text):
    1.  
    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. }
    18.  
    • 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. Sweden

    Joined:
    Jul 20, 2015
    Messages:
    27
    Likes Received:
    4
    The video is too long? :)
     
  3. Eagles13

    Eagles13 The only thing Alpha about me is my bots

    Joined:
    Sep 22, 2014
    Messages:
    618
    Likes Received:
    186
    Should be working fine now. Patience is a virtue.
     
  4. Sweden

    Joined:
    Jul 20, 2015
    Messages:
    27
    Likes Received:
    4
    Working fine now, thank you very much :)
     
  5. Eagles13

    Eagles13 The only thing Alpha about me is my bots

    Joined:
    Sep 22, 2014
    Messages:
    618
    Likes Received:
    186
    #5 Eagles13, Jul 25, 2015
    Last edited: Jul 25, 2015
  6. creativeself

    Joined:
    Jul 16, 2015
    Messages:
    212
    Likes Received:
    42
  7. nrkoo

    Joined:
    Oct 13, 2015
    Messages:
    10
    Likes Received:
    1
    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
     
  8. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    put "DARK"
     
  9. mpcomplete

    Joined:
    May 6, 2017
    Messages:
    6
    Likes Received:
    2
    This tutorial is definitely front page worthy. Maybe even pin worthy.

    Good job giving a good overview of the API for new bot developers.
     
    mzez1994 likes this.
  10. mzez1994

    Joined:
    Dec 11, 2017
    Messages:
    4
    Likes Received:
    0
    i have found this very useful too. great explanation of what can be done and how
     
  11. Emrys

    Joined:
    Sep 21, 2018
    Messages:
    21
    Likes Received:
    2
    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.
     

Share This Page

Loading...