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
  • How to get NPC that is attacking me?


    mitch6024

    Recommended Posts

    Hello all!

     

     

    I've been trying to find the correct method to use to find the NPC that is attacking the getLocalPlayer(). The whole reason I'm trying to locate it is to get the NPC that is attacking me and get it's Center Tile. I'm ultimately trying to then get that distance away from my character's tile. I can figure out the rest, all I need is the correct method to find the NPC that is in combat with me.

     

     

    I'm still a nooby scripter and have been trying different things for about 3 hours. With no luck of course, I'm posting here for help. Thanks in advance for any help!

    Link to comment
    Share on other sites

    if you wanna make a list

    List<NPC> bastards = getNpcs().all(NPC->NPC!=null && NPC.isInteracting(getLocalPlayer()) && NPC.isInCombat())

     

    or if you want a single npc replace all with closest..etc

     

    i read the "NPC->" as "Such that" -> "get all NPCs such that" + your conditions

     

    but its called a lambda if you wanna google

    Link to comment
    Share on other sites

    That's what I thought originally but I wasn't sure because it was returning a Character instead of a NPC.  Thank you for the help!

     

    if you wanna make a list

    List<NPC> bastards = getNpcs().all(NPC->NPC!=null && NPC.isInteracting(getLocalPlayer()) && NPC.isInCombat())

     

    or if you want a single npc replace all with closest..etc

     

    i read the "NPC->" as "Such that" -> "get all NPCs such that" + your conditions

     

    but its called a lambda if you wanna google

     

    Yeah I just need a Single NPC. ill try both and see which one works best. Thank you!

    Link to comment
    Share on other sites

    • 2 weeks later...
    //npcToFight is any npc name

    NPC npcX;

    if(getLocalPlayer().getCharacterInteractingWithMe().getName().equals(npcToFight)){

     log("Attacking aggressive NPC");

     npcX = (NPC)getLocalPlayer().getCharacterInteractingWithMe();

     fight(npcX); //this is my custom method to fight npcs

    }

    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.