Now that getFacing returns null if an NPC is attacking client.getMyPlayer(), you have to use this fact in conjunction with the fact that getFacingId = -1 if the NPC is not attacking any player to find a monster that is attacking you. Here's my version:
NPC getAttackingNPC() {
List<NPC> npcs = client.getLocalNPCs();
int n = 0;
for (n = 0; n < npcs.size(); n++) {
if (npcs.get(n).getFacing() == null
&& npcs.get(n).getFacingId() != -1) {
return npcs.get(n);
}
}
return null;
}
Any script using NPC.getFacing() or Character.getFacing() to function will be broken, as any npc that is facing the player will not return so. When I am under attack from for example an Iron dragon, that Iron dragon's getFacing() returns null even though the getFacing() for another dragon attacking another player will return that player. This distinction can probably be used to find the NPC interacting with the player but might need some API updates.
Are there any inbuilt methods for handling auto-retliate? I want to toggle it on and off at certain times but can't for the life of me find anything in the API.