ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   COMBAT_EVENT kill detection for mobs (https://www.esoui.com/forums/showthread.php?t=6451)

Justinon 08/05/16 02:21 PM

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.

sirinsidiator 08/05/16 03:04 PM

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.

Justinon 08/05/16 03:14 PM

Quote:

Originally Posted by sirinsidiator (Post 27991)
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?

sirinsidiator 08/05/16 03:27 PM

My guess is that it didn't filter anything and you just received all events unfiltered.

Justinon 08/05/16 04:10 PM

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.

Justinon 08/05/16 04:30 PM

So you were totally correct, the event was just firing for everything! Nice intuition.

sirinsidiator 08/06/16 12:45 AM

Glad to hear it worked! :)


All times are GMT -6. The time now is 11:41 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI