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


    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.

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


    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.