Thread Tools Display Modes
08/05/16, 02:21 PM   #1
Justinon
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
COMBAT_EVENT kill detection for mobs

Hey everyone, I'm currently trying to work out how to detect if the player has killed a mob, and I believe this is done using EVENT_COMBAT_EVENT. I'm trying to use the 'result' parameter, pairing it with ACTION_RESULT_DIED, ACTION_RESULT_KILLING_BLOW, and ACTION_RESULT_TARGET_DEAD, like so:
Lua Code:
  1. local function OnCombatEvent(eventCode, result, isError, abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, log, sourceUnitId, targetUnitId, abilityId)
  2.     d("event fired!")
  3.     if result == ACTION_RESULT_DIED or result == ACTION_RESULT_KILLING_BLOW or result == ACTION_RESULT_TARGET_DEAD then
  4.         d("Killed!")
  5.         --Do some stuff
  6.     end
  7. end
  8.  
  9. EVENT_MANAGER:RegisterForEvent(myNameSpace, EVENT_COMBAT_EVENT, OnCombatEvent)
  10. EVENT_MANAGER:AddFilterForEvent(myNameSpace, EVENT_COMBAT_EVENT, REGISTER_FILTER_COMBAT_RESULT, ACTION_RESULT_TARGET_DEAD)
  11. EVENT_MANAGER:AddFilterForEvent(myNameSpace, EVENT_COMBAT_EVENT, REGISTER_FILTER_COMBAT_RESULT, ACTION_RESULT_DIED)
  12. EVENT_MANAGER:AddFilterForEvent(myNameSpace, EVENT_COMBAT_EVENT, REGISTER_FILTER_COMBAT_RESULT, ACTION_RESULT_KILLING_BLOW)

But for some reason, I cannot get "killed" to be printed. I understand that the event only fires on player or pet actions, but I believed at least Killing Blow should be detected from the player's final, killing attack. Any suggestions for what I'm doing wrong?

Also, I tried commenting out the filters, but to no avail. Thank you!

EDIT 1: Okay so I realized that something is indeed wrong with the filters, because after reloadui it actually worked when commenting them out. However, I'm now still trying to figure out what to do with the filters

EDIT 2: After commenting out two of the three events, the "killed" is finally fired. So to me it's appearing like adding the filters together won't allow it to fire for these events. I thought that the filter would make it so that only those results would trigger the event, but now I'm not so sure how it works.

EDIT 3: Okay so I found out that, contrary to the ESOUI page, you do NOT need to pass the namespace in.

Last edited by Justinon : 08/05/16 at 02:56 PM. Reason: Realized something
  Reply With Quote
08/05/16, 03:04 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
You cannot use the same filter type more than once for an event handler. In order to get it to work properly, you will need to register 3 separate handlers (different namespace) for EVENT_COMBAT_EVENT.
  Reply With Quote
08/05/16, 03:14 PM   #3
Justinon
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
Originally Posted by sirinsidiator View Post
You cannot use the same filter type more than once for an event handler. In order to get it to work properly, you will need to register 3 separate handlers (different namespace) for EVENT_COMBAT_EVENT.
Interesting, when I simply didn't pass the namespace in for the (same) filter three times, it ended up finally working. I think you're right, perhaps because I used the same filter within the same namespace it didn't work, but it doesn't totally explain why it worked after not passing the namespace.

Any ideas?
  Reply With Quote
08/05/16, 03:27 PM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
My guess is that it didn't filter anything and you just received all events unfiltered.
  Reply With Quote
08/05/16, 04:10 PM   #5
Justinon
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
Okay thanks a bunch, I'll go ahead and do some more testing and see if a d() call before the result check prints anything.
  Reply With Quote
08/05/16, 04:30 PM   #6
Justinon
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
So you were totally correct, the event was just firing for everything! Nice intuition.

Last edited by Justinon : 08/05/16 at 05:35 PM.
  Reply With Quote
08/06/16, 12:45 AM   #7
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Glad to hear it worked!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » COMBAT_EVENT kill detection for mobs

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