PapaH 1 Posted December 19, 2021 Hey guys! I'm trying to write a script that attacks NPCs in a specific area that are not in combat. My script already checks whether there are enemies in the specific area to attack and wait until out of combat to attack another. How would you go about writing the ! .isInCombat check? This is what I was thinking, but it doesn't seem to be working: if (attackSpot.contains(NPCs.closest("Sand Crab")) && !NPCs.closest("Sand Crab").isInCombat()){ //if (NPCs.closest(crab -> crab != null && crab.getName() == "Sand crab" && attackSpot.contains(crab)).exists()){ log("Attack Sand Crab"); NPCs.closest("Sand Crab").interact("Attack"); I thought maybe this would work, but it doesn't attack anything. NPC SandCrab = NPCs.closest(crab -> crab != null && crab.getName() == "Sand Crab" && !crab.isHealthBarVisible() && attackSpot.contains(crab)); //if (attackSpot.contains(NPCs.closest("Sand Crab")) && !NPCs.closest("Sand Crab").isInCombat()){ if(SandCrab != null && !getLocalPlayer().isInCombat()){ log("Attack Sand Crab"); SandCrab.interact("Attack");
PapaH 1 Author Posted December 19, 2021 Thought I had it with the last edit, but It wouldn't actually attack anything. Still trying to figure out the best .isincombat check while alscho checking if area.contains
FriedNuts 2 Posted December 19, 2021 NPC monster = NPCs.closest(crab -> crab != null && (!crab.isInCombat() || crab.isInteracting(getLocalPlayer())) && crab.getName() == "Sand Crab"); if(!getLocalPlayer().isInCombat()) if(monster != null) monster.interact("Attack"); Would something like this work?
Hosfad 155 Posted December 20, 2021 Hello there @PapaH You would want to check if the crab is not in combat in the npc predicate , i also noticed that you are using == for a String , That doesnt work in java , you need to use .equals for Strings in java . Your predicate should look something like NPC SandCrab = NPCs.closest(crab -> crab != null && crab.getName().equals("Sand Crab") && !crab.isInCombat() && attackSpot.contains(crab));
PapaH 1 Author Posted December 20, 2021 3 hours ago, Hosfad said: Hello there @PapaH You would want to check if the crab is not in combat in the npc predicate , i also noticed that you are using == for a String , That doesnt work in java , you need to use .equals for Strings in java . Your predicate should look something like NPC SandCrab = NPCs.closest(crab -> crab != null && crab.getName().equals("Sand Crab") && !crab.isInCombat() && attackSpot.contains(crab)); That's pretty much exactly what I was looking for, thank you.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.