k9thebeast Posted May 6, 2017 Share Posted May 6, 2017 if(script.myPlayer().isUnderAttack()){ for(Player p : script.getPlayers().getAll()){ if(p.isInteracting(script.myPlayer())){ //Playyer attacking me } } } This no work Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted May 6, 2017 Share Posted May 6, 2017 Try just filtering the currently loaded players. The code below was typed up in notepad and yes i know it doesn't compare properly. players.getAll().stream().filter(p->p!=null && p.getInteracting() != null && p.getInteracting() == myPlayer()).findFirst() Quote Link to comment Share on other sites More sharing options...
Token Posted May 7, 2017 Share Posted May 7, 2017 (edited) script.players.getAll().stream().filter(x -> script.myPlayer().equals(x.getInteracting())).findFirst().isPresent(); // there is a player ATTEMPTING to attack, not necessarily already attacked script.myPlayer().isHitBarVisible(); // only works if the attack triggered health bar display (not a splashed spell) script.projectiles.getAll().stream().filter(x -> script.myPlayer().equals(x.getTargetEntity())).findFirst().isPresent(); // a ranged/magic attack was launched against the bot Combining the 3 will give you a relatively good coverage on simple cases but unfortunately the topic of accurately determining combat is very complex. Imagine a player casts wind strike on you in the wilderness (he's interacting with you in this case) then quickly eats food (he's no longer interacting with you), the health bar is not visible but there is a projectile launched with your player as its target, if it hits then your health bar will be visible but if it splashes, your health bar will not be visible, the player is not interacting with you because the interaction was interrupted by eating and there is no projectile launched towards your player. But you are in combat with him for 8 seconds or whatever the timer is. The only way to determine if you really are under attack 100% is by caching this state once you detect an attacker and clearing the cache once the combat timer is up so if you want the maximum precision (eg pking scripts) you will have to multithread your script and dedicate a whole thread to managing the combat state and determining the opponent. Edited May 7, 2017 by Token 6 Quote Link to comment Share on other sites More sharing options...
k9thebeast Posted May 7, 2017 Author Share Posted May 7, 2017 6 minutes ago, Token said: script.players.getAll().stream().filter(x -> script.myPlayer().equals(x.getInteracting())).findFirst().isPresent(); // there is a player ATTEMPTING to attack, not necessarily already attacked script.myPlayer().isHitBarVisible(); // only works if the attack triggered health bar display (not a splashed spell) script.projectiles().getAll().stream().filter(x -> script.myPlayer().equals(x.getTargetEntity())).findFirst().isPresent(); // a ranged/magic attack was launched against the bot Combining the 3 will give you a relatively good coverage on simple cases but unfortunately the topic of accurately determining combat is very complex. Imagine a player casts wind strike on you in the wilderness (he's interacting with you in this case) then quickly eats food (he's no longer interacting with you), the health bar is not visible but there is a projectile launched with your player as its target, if it hits then your health bar will be visible but if it splashes, your health bar will not be visible, the player is not interacting with you because the interaction was interrupted by eating and there is no projectile launched towards your player. But you are in combat with him for 8 seconds or whatever the timer is. The only way to determine if you really are under attack 100% is by caching this state once you detect an attacker and clearing the cache once the combat timer is up so if you want the maximum precision (eg pking scripts) you will have to multithread your script and dedicate a whole thread to managing the combat state and determining the opponent. Thank you mr token Quote Link to comment Share on other sites More sharing options...
Guest Posted May 7, 2017 Share Posted May 7, 2017 57 minutes ago, Token said: script.players.getAll().stream().filter(x -> script.myPlayer().equals(x.getInteracting())).findFirst().isPresent(); // there is a player ATTEMPTING to attack, not necessarily already attacked script.myPlayer().isHitBarVisible(); // only works if the attack triggered health bar display (not a splashed spell) script.projectiles.getAll().stream().filter(x -> script.myPlayer().equals(x.getTargetEntity())).findFirst().isPresent(); // a ranged/magic attack was launched against the bot Combining the 3 will give you a relatively good coverage on simple cases but unfortunately the topic of accurately determining combat is very complex. Imagine a player casts wind strike on you in the wilderness (he's interacting with you in this case) then quickly eats food (he's no longer interacting with you), the health bar is not visible but there is a projectile launched with your player as its target, if it hits then your health bar will be visible but if it splashes, your health bar will not be visible, the player is not interacting with you because the interaction was interrupted by eating and there is no projectile launched towards your player. But you are in combat with him for 8 seconds or whatever the timer is. The only way to determine if you really are under attack 100% is by caching this state once you detect an attacker and clearing the cache once the combat timer is up so if you want the maximum precision (eg pking scripts) you will have to multithread your script and dedicate a whole thread to managing the combat state and determining the opponent. The master has answered Quote Link to comment Share on other sites More sharing options...