Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • How to restrict interaction distance when interacting with a game object?


    Recommended Posts

    I want to make a power miner but the bot keeps running off because it finish's mining the iron too quickly.

    I want something like below so that it only mines objects within 1 tile I have no idea how to do it can anyone give some insight

    GameObject rock = GameObjects.closest(Rock,Rock2 .distance(Players.localPlayer() < 1);
    Link to comment
    Share on other sites

    Very close buddy 🙂 There is a filtering function that the API supports for getting most things like this (includings NPCs, GameObjects, and others). Try this code:

    GameObject rock = GameObjects.closest(p -> p.getName().equals("Rock") && p.distance() <= 1);

    Some relevant info about this code line:

    -p is a name, and doesn't matter what its called, could've been named "literallyUselessVariableName" or "Rock"

    -everything after the -> has to return true in order for the GameObject to be considered valid and returned, otherwise will skip those GameObjects for which these conditions are false

    -When this line runs it finds all rendered GameObjects and filters these to match both the name and the distance. Each GameObject takes a turn at being "p" and gets evaluated, then the closest is determined and that one GameObject is returned

    -the method .distance() will automatically assume distance is being calculated from the local player's tile

    -distance is calculated via pythagorian theorem to get real circle radius distances, rather than "square" distances. For example: something 15 tiles east and 15 tiles north will result in 21.2132 as distance, whereas "square" distance would simply be 15. So therefore any rocks that are adjacent to your player will be 1.0 distance away, and if you only say "distance < 1" then it wouldn't ever pick up any rocks because you can never stand on any rocks, so it must be "distance <= 1" or "distance  < 2"



    Link to comment
    Share on other sites


    This topic is now archived and is closed to further replies.

    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.