Mushphang Posted December 13, 2016 Share Posted December 13, 2016 (edited) Hey all For the last couple of days I've been experimenting and trying to find out how to properly identify who's attacking me. My script is struggling differentiating between Mobs attacking me and Players. Here's my code: //Monster Attacking: NPC monster = getNpcs().closest(npc -> npc.getName().equals("Skeleton") || npc.getName().equals("Scorpion")); if (myPlayer().isUnderAttack() && (monster != null) && monster.isInteracting(myPlayer())) { //stuff } //Player Attacking: //Use to be more complex but after taking out the conditions I had for players //attacking it seamed to work better. So its literally just: }else { //stuff } Edited December 13, 2016 by Mushphang Quote Link to comment Share on other sites More sharing options...
House Posted December 13, 2016 Share Posted December 13, 2016 I'm not sure this will work i have not tested it but maybe: myPlayer().getInteracting() instanceof Player you could determine if its a player or an NPC this way Quote Link to comment Share on other sites More sharing options...
liverare Posted December 13, 2016 Share Posted December 13, 2016 (edited) Give this a whirl: public final List<NPC> whoIsPossiblyAttackingMe() { return npcs.getAll().stream() .filter((npc) -> npc.isInteracting(myPlayer())) .collect(java.util.stream.Collectors.toList()); } This gets a list of all NPCs interacting with you (e.g., a goblin attacking you, a shop keeper responding to you, a pet following you, etc.) You can then loop through and check each of those npcs for a specific name. For instance, you know that a goblin would only be interacting with you because it's attacking you. However, a guard may have knocked you for failing to pickpocket him. So bare that in mind. Edited December 13, 2016 by liverare Quote Link to comment Share on other sites More sharing options...
Mushphang Posted December 15, 2016 Author Share Posted December 15, 2016 Give this a whirl: public final List<NPC> whoIsPossiblyAttackingMe() { return npcs.getAll().stream() .filter((npc) -> npc.isInteracting(myPlayer())) .collect(java.util.stream.Collectors.toList()); } This gets a list of all NPCs interacting with you (e.g., a goblin attacking you, a shop keeper responding to you, a pet following you, etc.) You can then loop through and check each of those npcs for a specific name. For instance, you know that a goblin would only be interacting with you because it's attacking you. However, a guard may have knocked you for failing to pickpocket him. So bare that in mind. Sorry for the late response! Thank you very much for both of your replies. So far after implementing this all is working well so far! Thank you much. Quote Link to comment Share on other sites More sharing options...