Thread Tools Display Modes
03-24-16, 08:52 PM   #1
tonyis3l33t
A Cyclonian
 
tonyis3l33t's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 47
best way to detect combat status as an event?

Hey guys. I'm trying to find the best way to determine if the player is in combat, and run a function based on that status.

Right now I'm using the event PLAYER_REGEN_ENABLED, but it only fires when the player has agro. This wouldn't work for, say, dps or a healer entering combat, but not being attacked themselves.

Elsewhere I'm using UnitAffectingCombat("player") as a condition for an if statement, but it's not a great solution either as it's buried in an OnEnter hook, so it only checks when the mouse hovers on that frame.

Thanks,
Tony
  Reply With Quote
03-24-16, 08:53 PM   #2
tonyis3l33t
A Cyclonian
 
tonyis3l33t's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 47
also looking for an event solution for when the user's health is under 100%. I have an IF version for that already, but again, it only fires on frame OnEnter. I need it to fire as soon as they're under 100%....
  Reply With Quote
03-24-16, 09:02 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
For combat, use the function InCombatLockdown().

For health, use the UNIT_HEALTH event.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-24-16, 11:21 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Or "UNIT_HEALTH_FREQUENT" to get a more immediate response.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
03-25-16, 12:25 AM   #5
TOM_RUS
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 95
Originally Posted by tonyis3l33t View Post
Right now I'm using the event PLAYER_REGEN_ENABLED, but it only fires when the player has agro. This wouldn't work for, say, dps or a healer entering combat, but not being attacked themselves.
Do you mean PLAYER_REGEN_DISABLED? PLAYER_REGEN_ENABLED in this case makes no sense (fires when you leave combat...). Also it should fire when you enter combat even if not attacked...
  Reply With Quote
03-25-16, 12:28 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by tonyis3l33t View Post
Hey guys. I'm trying to find the best way to determine if the player is in combat, and run a function based on that status.

Right now I'm using the event PLAYER_REGEN_ENABLED, but it only fires when the player has agro. This wouldn't work for, say, dps or a healer entering combat, but not being attacked themselves.

Elsewhere I'm using UnitAffectingCombat("player") as a condition for an if statement, but it's not a great solution either as it's buried in an OnEnter hook, so it only checks when the mouse hovers on that frame.

Thanks,
Tony
First of all, it's PLAYER_REGEN_DISABLED that fires when the player enters combat. PLAYER_REGEN_ENABLED fires when you exit combat. If this mistake is actually in your code, it might cause problems. As Seerah mentioned, if you're wanting to query if you're in combat arbitrarily, you could use InCombatLockdown(). This is tied in with the events mentioned before as it returns true after PLAYER_REGEN_DISABLED fires and false before PLAYER_REGEN_ENABLED fires. This means if you check InCombatLockdown() as a response to either event, it will return false.

If your problem is with the timing of when these events fire, it's just how the game considers when the player is in combat. There are only a handful of things that put you in combat when someone else engages a mob. The most common ways are either hitting the mob with an attack or ability; or healing/buffing someone already on their threat list.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-25-16, 05:43 AM   #7
tonyis3l33t
A Cyclonian
 
tonyis3l33t's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 47
Originally Posted by TOM_RUS View Post
Do you mean PLAYER_REGEN_DISABLED? PLAYER_REGEN_ENABLED in this case makes no sense (fires when you leave combat...). Also it should fire when you enter combat even if not attacked...
yea, sorry i use both in this addon, copy/pasta'd the wrong one

Thanks all for pointers, I will be trying them after work, which is where I must now go... UNIT_WORK.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » best way to detect combat status as an event?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off