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
  • Player is attacking an NPC that is further away than the NPCs.Closest ?


    vhh
     Share

    Recommended Posts

    Hi, my script is almost complete. I just have this issue:

    After I have killed a monster, I want to attack the next closest one that is not already in combat with another player.

    My issue is that if a Monster respawns next to me as I finish my kill, it wont attack it. It ignores it and attacks one further away.
    If there are no other monsters, it throws a NullPointerException. 

    This suggests that whenever a monster respawns, it is Null. However, I have declared the NPC within the method so I thought it would be checking every return what the nearest NPC is. 

    Can someone help me figure out why any respawned NPC's are showing as null and aren't getting attacked? Thank you.

    @Override
    public int onLoop() {
    
        if (KillArea.contains(getLocalPlayer()) && !getLocalPlayer().isInCombat() && !getLocalPlayer().isAnimating()){
    
            log("Attacking NPC");
            sleep(500,1100);
            NPC Monster = NPCs.closest(NPC->NPC!=null && !NPC.isInCombat());
            Monster.interact("Attack");
            sleepUntil(() -> getLocalPlayer().isAnimating(), Calculations.random( 5000,8000));
    
        }
    
        return Calculations.random(850,1150);
    }

     

    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.