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
  • Calculating distance from closest NPC of a specific type?


    Azure117

    Recommended Posts

    Hi, how can I calculate how far I am from a given NPC? I just want to basically check if I should try walking somewhere or not based on how far I am from an NPC. Having a bit of trouble with syntax.

     

    NPC spot = NPCs.closest(new String[]{"NPC NAME"});

    is how I get the NPC I want.

    Thanks,
    Azure

    Link to comment
    Share on other sites

    Hey @Azure117, you can use the "Entity.distance()" method. By default it'll compare the entity's distance to your local player. An example can be found below:

    NPC nearbyNPC = NPCs.closest("NPC Name Here");
    
    if (nearbyNPC != null) {
    	int npcDistance = nearbyNPC.distance();
    }

    For NPCs specifically, you can see the JavaDocs here: https://dreambot.org/javadocs/org/dreambot/api/methods/interactive/NPCs.html

    With the general Entity methods being found here: https://dreambot.org/javadocs/org/dreambot/api/wrappers/interactive/Entity.html

    Link to comment
    Share on other sites

    Archived

    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.