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
  • GameObjects closest based on pathfinding?


    Nazeradom

    Recommended Posts

    Hi I am quite new to scripting for Dreambot but I have a strong professional programming background.

     

    Something I noticed while creating a Motherload script was using getGameObjects().closest() could sometimes give you a game object which is technically closest but behind a wall or inaccessible.

    I noticed the pathfinding classses and was wondering if anyone had used them in conjunction with game objects to find the closest game object as far as pathfinding is concerned.

    I tried using the getGameObjects.all() function and looping through, performing pathfinding, but I found it clunky and slow and also all(<ID>) returns way too many of the object to be useful.

     

    TL;DR
    I need to find the closest game object as far as pathfinding is concerned and not just simply radius to the player.

     

    Thanks in advance for any help.

    Link to comment
    Share on other sites

    Idk which method you used but you can use Map#canReach or you can wrote youre own method for that.

    I've heard other scripters talk about this but I've never found it. WHERE IS THIS METHOD HIDING!??

    Link to comment
    Share on other sites

    Idk which method you used but you can use Map#canReach or you can wrote youre own method for that.

    But if I can figure out which ones I can reach and which ones I can't, how do I then know which one is closest?

     

    Edit: I guess I could then loop through the reachable ones and find the closest one. But it could be reachable, have the shortest distance but still not be closest as far as time it takes the player to get to it.

    Link to comment
    Share on other sites

    You can check how many obstacles are on the path and choose the one with the lowest amount. Or you could calculate it. 1 obstacle = 4 tiles for example

    Link to comment
    Share on other sites

    closest just filters through a list of gameopbjects that are not null. So in your case as you describe it, i'd think it works like this:

     

    It gets all objects that are not null, then it filters the objects based on distance by using getLocalPlayer().distance(getGameObjects().closest()) something like that. It doesn't really take care of paths or if it is reachable.

     

    Correct me if i'm wrong, because i have no idea how the method was written.

    Link to comment
    Share on other sites

    I think I am going to get the closest 5 objects and run pathfinding on them to figure out which one is actually closest, this seems to be the best way based on the feedback.

    If I am unlucky enough that all 5 are behind a wall then tough luck I guess.

     

    Thanks everyone.

    Link to comment
    Share on other sites

    I think I am going to get the closest 5 objects and run pathfinding on them to figure out which one is actually closest, this seems to be the best way based on the feedback.

    If I am unlucky enough that all 5 are behind a wall then tough luck I guess.

     

    Thanks everyone.

    You can also write it so that it will filter through the objects and only return the ones that actually have a walkpath that isn't null. Use the Filter class for this (basically what you want)

     

    Would you mind telling us what objects are blocked by the wall(s)? maybe we've got some better ideas :)

    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.