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 ?


    vhh

    Recommended Posts

    Posted

    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);
    }

     

    Posted

    Respawned NPC's don't show up as null, could you take a short video of this script running to show it choosing a further away NPC?

    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.