Jump to content

Determine who is attacking myself/NPC?


Recommended Posts

Posted (edited)

If the sole purpose is to check if YOU are the one attacking the man, then you could just do:

if (man.isUnderAttack() && !man.equals(myPlayer().getInteracting())) //I'm not attacking the man
if (man.isUnderAttack() && man.equals(myPlayer().getInteracting())) //I'm attacking the man

For the second case tho, you should probably add some more checks (We ARE in combat / the man is also interacting with us), in order to prevent any confusion that could occur if someone else is attacking the man, but we're still interacting with it for whatever reason.

Edited by FrostBug
  • Like 1
Posted
NPC monster = npcs.closest(monsterID);

if(monster != null) { 
   if(monster.isInteracting(myPlayer()) {
      //monster is interacting with my player
   }
}

OR

NPC monster = npcs.closest(monsterID);

if(monster != null) {
  if(myPlayer().isInteracting(monster)) {
     // my player is interacting with monster
  }
}
Posted

If the sole purpose is to check if YOU are the one attacking the man, then you could just do:

if (man.isUnderAttack() && !man.equals(myPlayer().getInteracting())) //I'm not attacking the man
if (man.isUnderAttack() && man.equals(myPlayer().getInteracting())) //I'm attacking the man

For the second case tho, you should probably add some more checks (We ARE in combat / the man is also interacting with us), in order to prevent any confusion that could occur if someone else is attacking the man, but we're still interacting with it for whatever reason.

 

The idea is that if someone tries to attack the man while I am pickpocketing it, it will stop and say "dude wtf" or something similar. Sometimes, the bot does misclick and attack the man too (which I want to detect)

 

So I would use the first example to check if someone is attacking him?

 

Posted

The idea is that if someone tries to attack the man while I am pickpocketing it, it will stop and say "dude wtf" or something similar. Sometimes, the bot does misclick and attack the man too (which I want to detect)

 

So I would use the first example to check if someone is attacking him?

 

 

That may work, but only while you're not focusing on the man as well (eg. will not work right before you pickpocket the man, while the player is focusing the man).

 

What you could do instead is simply check if your own player is under attack. If both you and the man are under attack, you'll be the one attacking him. If the man is under attack, but you are not, then it's probably someone else.

 

  • Like 1
Posted

That may work, but only while you're not focusing on the man as well (eg. will not work right before you pickpocket the man, while the player is focusing the man).

 

What you could do instead is simply check if your own player is under attack. If both you and the man are under attack, you'll be the one attacking him. If the man is under attack, but you are not, then it's probably someone else.

 

 

Thanks, I will try that :)

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...