IsEventRegistered() - ESOUI
Thread Tools Display Modes
07/10/19, 02:02 PM   #1
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238

Hey guys, is it possible to check wether an event is already registered? If I register the same event multiple times, it seems not to be overwritten but registering multiple times which is very odd behavior.

Lua Code:
  1. function AuraMastery:RegisterForEvent(eventId, abilityId)
  2.         local eventNamespace = "AM_"..eventId..abilityId
  3.     local eventHandler = MyHandler
  4.     EVENT_MANAGER:RegisterForEvent(eventNamespace, eventId, eventHandler)
  5.     EVENT_MANAGER:AddFilterForEvent(eventNamespace, eventId, REGISTER_FILTER_ABILITY_ID, abilityId)
  6. end

AuraMastery:RegisterForEvent(EVENT_COMBAT_EVENT, 30920)
AuraMastery:RegisterForEvent(EVENT_COMBAT_EVENT, 30920)

Any use of ability(30920) will trigger MyHandler TWO TIMES! instead of one time.

I need a function to determine if an event of specified Namespace and filter /w abilityId is already registered.

(I know I could handle it manually by saving it to a table onRegistering, but maybe there is a more elegant way
  Reply With Quote
07/10/19, 03:41 PM   #2
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,427
You are mistaken. Event handlers can only be registered once for the same eventNamespace/eventId pair. EVENT_MANAGER:RegisterForEvent returns true if it actually registered the function and false otherwise. In order to assign a different function you have to first call UnregisterForEvent for the same namespace and id, which will also return true in case it did unregister something.

The reason why you see your handler getting called more than once is that some abilities have more than one effect. I tried your code with Shadowy Disguise (id 62141) and it is called 2 times when it is cast and one more time when the invisibility runs out.
https://www.imperialtradingcompany.eu/ - My Addons - The Vault (Early updates and experimental projects) - My patreon - My blog
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
07/12/19, 09:19 AM   #3
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
Found the problem, thanks for the help!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » IsEventRegistered()

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