bap 18 Share Posted September 30, 2020 Hi, I would like some help on how I would be able to get a list of NPCs closest to my player, and see if it has the option to attack them, and if it does, to attack them. This is the code I have so far. @Override public boolean accept() { return !Players.localPlayer().isHealthBarVisible() && !Players.localPlayer().isAnimating(); } @Override public int execute() { List<NPC> npcs = NPCs.all(); if (npcs.isEmpty()) { return Calculations.random(600,1000); //wait for an npc to be in our range } if (npcs.interact("Attack")) { sleepUntil(this::isAttacking, 5000); } return Calculations.random(600,1250); } private boolean isAttacking() { //returns if we are in an attacking animation return getLocalPlayer().isAnimating(); } } Are there any things that I could add? npcs.interact("Attack") is giving me an error, saying that you can't use it on a list, which is the main problem I'm having right now. Link to comment Share on other sites More sharing options...
yeeter 528 Share Posted September 30, 2020 NPCs is a LIST of NPC's and not an npc object. When you call .interact() on the list it has no clue what you are doing. You need to get an NPC out of the list then call .interact() on the npc not the NPCs list Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted October 1, 2020 NPC attackable = NPCs.closest(n -> n.distance(Players.localPlayer() < maxDistanceHere) && n.hasAction("Attack"); Something like this ought to suffice for what you said. Change the 'maxDistanceHere' to the maximum distance you'd like it to register npcs at. Additionally you may need to add a query checking if the npc(s) are reachable depending on your use case. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.