View Single Post
03/19/23, 07:01 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,016
You do not always need to filter events, and beside that you cannot even filter each event! The filters are helpers to prevent event callbacks firing each time for unneccessary circumstances, like if you only want to check yourself but the event fires for all units around you.

Some events do not even support filters as the Wiki describes, e.g. if there is no unitTag in the event's callback function parameters you cannot use any unitTag related event filters for it.
Same counts for displayname and I think there does not even exist and event filter stuff for displaynames -> check the event filter site at the wiki.

If the callback function of the event already provides a parameter like isLocalPlayer and it's true if YOU left the group, then just add the EVENT_MANAGER:RegisterForEvent... of the group_left and check in your callback function at the start if it's you who left, or others.
e.g. if only you are the relevant unit to check things with you can skip all others simply by:

Lua Code:
  1. if not isLocalPlayer then return end


Lua Code:
  1. function LGRI.OnAddOnLoaded(event, addonName)
  2.     if addonName ~= LGRI.name then return end
  3.     EM:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  4.  
  5.     LargeGroupRoleIcons.Initialize()
  6.  
  7.     EM:RegisterForEvent(LGRI.name .. "_EVENT_GROUP_MEMBER_ROLE_CHANGED", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     EM:AddFilterForEvent(LGRI.name .. "_EVENT_GROUP_MEMBER_ROLE_CHANGED", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player") --carefull! You are missing the first parameter, the unique event name of your addon! That way the filters won't be applied! Event filters always need to use the unique SAME name as your RegsiterForEvent used where you want to apply the filter!!!
  9.  
  10.          --number eventCode, string memberCharacterName, GroupLeaveReason reason, boolean isLocalPlayer, boolean isLeader, string memberDisplayName, boolean actionRequiredVote
  11.     EM:RegisterForEvent(LGRI.name .. "_EVENT_GROUP_MEMBER_LEFT", EVENT_GROUP_MEMBER_LEFT,
  12. function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  13.    if not isLocalPlayer then return end[
  14.    LGRI.UpdateMyRole()
  15. end)
  16. end

Last edited by Baertram : 03/19/23 at 07:06 AM.
  Reply With Quote