View Single Post
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,327
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