AddFilterForEvent
From ESOUI Wiki
Line 7: | Line 7: | ||
local wasFilterAppliedBool = EVENT_MANAGER:AddFilterForEvent(string eventNamespace, number eventId, RegisterForEventFilterType filterType, varying filterParameter) | local wasFilterAppliedBool = EVENT_MANAGER:AddFilterForEvent(string eventNamespace, number eventId, RegisterForEventFilterType filterType, varying filterParameter) | ||
</source><br> | </source><br> | ||
- | Multiple filters can be added for the same event in one call by repeatedly supplying a filter type | + | Multiple filters can be added for the same event in one call by repeatedly supplying a filter type , filterParameter pair:<br> |
<source lang="lua"> | <source lang="lua"> | ||
local wasFilterAppliedBool = EVENT_MANAGER:AddFilterForEvent(string eventNamespace, number eventId, RegisterForEventFilterType filterType, varying filterParameter, RegisterForEventFilterType filterType2, varying filterParameter2, RegisterForEventFilterType filterType3, varying filterParameter3) | local wasFilterAppliedBool = EVENT_MANAGER:AddFilterForEvent(string eventNamespace, number eventId, RegisterForEventFilterType filterType, varying filterParameter, RegisterForEventFilterType filterType2, varying filterParameter2, RegisterForEventFilterType filterType3, varying filterParameter3) |
Revision as of 17:03, 26 June 2022
In Update 7 (Imperial City) combat related events were changed in order to give addons more information about what is going on in the world.
This would result in a flood of information that would degrade the performance of many addons by sending events for things they are not even interested in.
In order to prevent this, a new method AddFilterForEvent was added to the EVENT_MANAGER, which allows authors to reduce the amount of received data via predefined filters
that run in the c-code part of the client.
For the announcement of those changes see this thread.
local wasFilterAppliedBool = EVENT_MANAGER:AddFilterForEvent(string eventNamespace, number eventId, RegisterForEventFilterType filterType, varying filterParameter)
Multiple filters can be added for the same event in one call by repeatedly supplying a filter type , filterParameter pair:
local wasFilterAppliedBool = EVENT_MANAGER:AddFilterForEvent(string eventNamespace, number eventId, RegisterForEventFilterType filterType, varying filterParameter, RegisterForEventFilterType filterType2, varying filterParameter2, RegisterForEventFilterType filterType3, varying filterParameter3)
The return boolean of the function tells you if the filter was applied properly, or not.
Attention: Applied filters cannot be removed without unregistering the event!
Applying different filterTypes with multiple calls to EVENT_MANAGER:AddFilterForEvent(string eventNamespace, ... will deactivate the brefore registered filterTypes at the same event! If you want to register mutiple filterTypes and parameters you need to define this within 1 function call to EVENT_MANAGER:AddFilterForEvent(string eventNamespace, ... using multiple filterType & filterParameter pairs after another.
Take note that you cannot use the same filterType more than once for the same eventNamespace - eventId pair (this means you need to specify the same eventNameSpace for the registering of the event and the filter, in order to make the filter work for this event. And you need to change the eventNameSpace and re-register the same event if you want to register another filter with the same filterType).
Filter Types
There are currently 15 filter types which all receive different arguments and can be used for different event types.
filterType | eventNames (examples) | filterParameter | description |
---|---|---|---|
REGISTER_FILTER_ABILITY_ID | EVENT_ABILITY_COOLDOWN_UPDATED, EVENT_COMBAT_EVENT, EVENT_EFFECT_CHANGED | number abilityId | Filters for specific abilities |
REGISTER_FILTER_BAG_ID | EVENT_INVENTORY_SINGLE_SLOT_UPDATE | Bag bagId | Filters for specific inventory bag |
REGISTER_FILTER_COMBAT_RESULT | EVENT_COMBAT_EVENT | ActionResult actionResult | Filters for combat action results |
REGISTER_FILTER_INVALID | Not used in the ui code. Seems to be a placeholder | ||
REGISTER_FILTER_INVENTORY_UPDATE_REASON | EVENT_INVENTORY_SINGLE_SLOT_UPDATE | InventoryUpdateReason inventoryUpdateReason | Filters for specific inventory update reason |
REGISTER_FILTER_IS_ERROR | EVENT_COMBAT_EVENT | boolean isError | Filters combat events for errors |
REGISTER_FILTER_IS_IN_GAMEPAD_PREFERRED_MODE | Any | boolean showInGamepadPreferredMode | Only handle event while gamepad mode is active |
REGISTER_FILTER_IS_NEW_ITEM | EVENT_INVENTORY_SINGLE_SLOT_UPDATE | boolean isNewItem | Filters for new items |
REGISTER_FILTER_POWER_TYPE | EVENT_COMBAT_EVENT, EVENT_POWER_UPDATE | CombatMechanicType powerType | Filter for a specific power type |
REGISTER_FILTER_SETTING_SYSTEM_TYPE | EVENT_INTERFACE_SETTING_CHANGED | SettingSystemType settingType | Filter for a specific power type |
REGISTER_FILTER_SOURCE_COMBAT_UNIT_TYPE | EVENT_COMBAT_EVENT, EVENT_EFFECT_CHANGED | CombatUnitType unitType | Filter for the source unit type |
REGISTER_FILTER_TARGET_COMBAT_UNIT_TYPE | EVENT_COMBAT_EVENT | CombatUnitType unitType | Filter for the target unit type |
REGISTER_FILTER_UNIT_TAG | Any event with a unitTag argument | string unitTag | Filter for the exact unitTag |
REGISTER_FILTER_UNIT_TAG_PREFIX | Any event with a unitTag argument | string unitTagPrefix | Filter for a unitTag that has multiple instances (e.g. group, boss) |
REGISTER_FILTER_VIBRATION_FILTER | EVENT_COMBAT_EVENT | number vibrationStrength | Filter for combat events that would cause a vibration on a gamepad |
Example
Filtering for combat events that are not errors:
local namespace = "MyAddonEventNamespace" EVENT_MANAGER:RegisterForEvent(namespace, EVENT_COMBAT_EVENT, function(eventCode, result, isError, abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, log, sourceUnitId, targetUnitId, abilityId, overflow) -- do something here end) EVENT_MANAGER:AddFilterForEvent(namespace, EVENT_COMBAT_EVENT, REGISTER_FILTER_IS_ERROR, false)
A function available to register multiple filter functions for the same event and filterType combatResult (ActionResult):
local nextEventHandleNr = 0 local function RegisterCombatResultEvent(result, callback) local eventHandleName = "MyAddonEventNameSpace" .. tostring(nextEventHandleNr) -- This is needed in order to generate a new unique eventNameSpace for each filterType added! nextEventHandleNr = nextEventHandleNr + 1 EVENT_MANAGER:RegisterForEvent(eventHandleName, EVENT_COMBAT_EVENT, callback) EVENT_MANAGER:AddFilterForEvent(eventHandleName, EVENT_COMBAT_EVENT, REGISTER_FILTER_COMBAT_RESULT, result) return eventHandleName end