ospaul Posted November 24, 2020 Share Posted November 24, 2020 (edited) Hi there, currently wrapping up a script, in which my player is in ranged combat with an NPC from a distance, so I cant store which exact NPC is closest, as normally this npc is medium-long range. As of now my code looks something along the lines of private list<npc> npcName; npcName = script.getNpcs().filter(isNPCDangerous()); private static boolean isNPCDangerous(NPC npc) { if( script.myPlayer().isInteracting(npc) && npc.getName().equals("NPC name") && !npc.isUnderAttack()) return false; if (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack()) return true; else return false; } Currently NPCs that are not under attack are included as dangerous when I am in combat with a different NPC, as well as NPCs that are under attack by another player but are in a long animation, or are not being attacked back Edited November 24, 2020 by ospaul Quote Link to comment Share on other sites More sharing options...
Heist Posted November 24, 2020 Share Posted November 24, 2020 (edited) I believe the problem is your second if statement. The mix of && and || is confusing and I don't think it works the way you are thinking it does. Try looking into ways to change that. For example, maybe something like this where it groups the statements: if ((npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc)) || (npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack())) EDIT: Your second if statement is actually really confusing. I just realized it contradicts itself so it'll always return true. Edited November 25, 2020 by Heist Quote Link to comment Share on other sites More sharing options...
ospaul Posted November 25, 2020 Author Share Posted November 25, 2020 Code got a bit mixed up while transposing from memory, I reduced it to a single if statement and it works now. Brand new to OSBot api so I over complicated Quote Link to comment Share on other sites More sharing options...
Mom Posted December 1, 2020 Share Posted December 1, 2020 Just an fyi (not sure if this is what you're referring to in previous comment) but your if conditions are redundant. This: private static boolean isNPCDangerous(NPC npc) { if( script.myPlayer().isInteracting(npc) && npc.getName().equals("NPC name") && !npc.isUnderAttack()) return false; if (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack()) return true; else return false; } should just be -> private static boolean isNPCDangerous(NPC npc) { return (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack()) } Quote Link to comment Share on other sites More sharing options...
ospaul Posted December 1, 2020 Author Share Posted December 1, 2020 28 minutes ago, Mom said: Just an fyi (not sure if this is what you're referring to in previous comment) but your if conditions are redundant. This: private static boolean isNPCDangerous(NPC npc) { if( script.myPlayer().isInteracting(npc) && npc.getName().equals("NPC name") && !npc.isUnderAttack()) return false; if (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack()) return true; else return false; } should just be -> private static boolean isNPCDangerous(NPC npc) { return (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack()) } Yeah that’s close to what I came up with, it was a long day haha Quote Link to comment Share on other sites More sharing options...