Thread Tools Display Modes
06-13-13, 06:05 AM   #1
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Detecting end of combat

Is there a simple way in the game API to tell when combat ends? I don't mean just REGEN_ENABLED event, because then my entire raid can still keep fighting (and even resurrect me), but some way to know that that battle is definitely finished, one way or the other.
  Reply With Quote
06-13-13, 07:05 AM   #2
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
I suppose there are several possibilities:

1] Use the REGEN_ENABLED event in conjunction with UnitHealth("player"). If regen is enabled, and your health is greater than 0, you're alive and out of combat, therefore your raid likely is as well.

2] If the NPC in question has a death emote, you can use that to determine that the "battle is over".

3] I suppose if you need to know that an ENTIRE raid is out of combat (why would you?), you could run UnitAffectingCombat() across the entire raid roster.

You should probably explain what it is you are trying to accomplish.
  Reply With Quote
06-13-13, 08:12 AM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Calling UnitAffectingCombat on each member of the raid on update (maybe throttled a few frames) is probably the simplest way to do this. It would be somewhat costly though.
  Reply With Quote
06-13-13, 08:40 AM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Also, bosses with bonus loot has an event that fires when killed.
  Reply With Quote
06-13-13, 08:50 AM   #5
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Looks like UnitAffectingCombat is what I was looking for... now I just have to figure out indeed how not to call it too often. Thanks
  Reply With Quote
06-14-13, 07:39 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Since you are asking about raids (this will not work in some scenarios or in battlegrounds), what about checking if you can release your spirit? If the button is visible, but cannot be interacted with, it is because "a member of your raid is still in combat", right?

The button only lights up when the whole raid is either dead or out of combat. The downside is that you would have to be dead to use this as a check.
  Reply With Quote
06-14-13, 07:58 AM   #7
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
That's a pretty nice idea
But I ended up simply calling UnitAffectsCombat for everyone in the group (whichever type of group it is) every 5 seconds or so, on the assumption that this won't overload the system too much and is still more than accurate enough for my needs.
  Reply With Quote
06-14-13, 08:21 AM   #8
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Well if you're going to be calling something on a timer to check for group combat it's probably preferable to use IsEncounterInProgress() instead of calling UnitAffectingCombat() on all group members.

Edit:
In fact if it was me I'd use the traditional event-based way to check for combat end for the player and only if they are dead at the time of exiting combat start my throttled OnUpdate/Animation to check IsEncounterInProgress()

Last edited by Dridzt : 06-14-13 at 08:24 AM.
  Reply With Quote
06-14-13, 02:14 PM   #9
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
I didn't know IsEncounterInProgress() existed... should I assume by the name that it's limited to a boss encounter or something? Because if it is, I think I would rather not use it.
The event based method you suggest seems legit, although something in it is bothering me and I can't tell what...
  Reply With Quote
06-14-13, 07:28 PM   #10
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Keep in mind you only need to check until you encounter a unit that is still in combat before you break out of the loop, so worst case scenario is combat has ended and it has to check however many units are in the raid.

I would avoid using IsEncounterInProgress as relatively few fights will actually support the function, I think it may be exclusively for encounters during which you can't release, and I believe those fights can be tracked through events since boss frames have to be shown and hidden.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Detecting end of combat


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