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
  • Try asking for help in the chatbox
  • NPC Storage (Distance)


    Booshotti
     Share

    Recommended Posts

    Hello,

     

    I am curious what is the best way to store NPC's, Currently I am getNpcs().closest and I wanted to know if it's better to use a for loop to add NPC's to a list and then compare distance? I have noticed that my script sometimes doesn't go to the closest as at the time of the execution of the attack part of the script.

     

    Say I have an if statement that checks the closest and then within the if statement the closest has changed to another one because the NPCs are moving it will go a little crazy sometimes, I was thinking of doing getNpcs.all() and then sorting them within a List based on the distance so we can always go to the second closest NPC if the first closest has changed if that makes sense?

     

    I am at Rock Crabs so whilst attacking new idle rocks will spawn and it will choose the idle rock that is further away from the actual closest.

    Link to comment
    Share on other sites

    well something you can do is

    for (NPC i : getNpcs().all()) {

     

    }

    and in that just compare distance

    That was what I was thinking, Would you consider that to be more efficient than npc.closest()?

    Link to comment
    Share on other sites

    That was what I was thinking, Would you consider that to be more efficient than npc.closest()?

    well you can check each npc this way for the things you wanna check rather then only the closest one  for example if the closest ons doesn't have the attack option but the 2nd closest does then its gonna be hard to get that info using .closest

    Link to comment
    Share on other sites

    I'm pretty sure closest filters them on distance and you seem like the only one who has the problem where its not getting the closest entity. So are you sure its not other parts of your code?

    Link to comment
    Share on other sites

    	public T getBest(Evaluator<T> evaluator, List<T> objects){
    T out = null;
    double best = Double.MAX_VALUE;
    if(objects.size() == 0){
    System.out.println("No objects to evaluate");
    return null;
    }
    for(T i:objects){
    double tmp;
    if((tmp = evaluator.evaluate(i)) < best){
    best = tmp;
    out = i;
    }
    }
    return out;
    }
    public abstract class Evaluator <C> {
    public abstract double evaluate(C i);
    }
    Edited by Dorkinator
    Link to comment
    Share on other sites

    I'm pretty sure closest filters them on distance and you seem like the only one who has the problem where its not getting the closest entity. So are you sure its not other parts of your code?

     

    It's really hard to explain what is going on, I will try the loop method anyway because right now I am limited on what I can check with the NPC's because it's only doing closest.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • 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.