View Single Post
03/19/23, 01:09 PM   #11
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
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.
I understand, thanks

This is not working for me tho
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 .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     EM:AddFilterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  9.  
  10.     EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT,
  11. function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  12.    if not isLocalPlayer then return end
  13.    LGRI.UpdateMyRole()
  14. end)
  15. end
But this is working the difference is in the AddFilterForEvent line
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 .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     EM:AddFilterForEvent(EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  9.  
  10.     EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT,
  11. function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  12.    if not isLocalPlayer then return end
  13.    LGRI.UpdateMyRole()
  14. end)
  15. end


And also one extra question, I want to register another event(EVENT_GROUP_MEMBER_JOINED) to trigger my UpdateMyRole() function, what's the correct way?
Lua Code:
  1. EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, EVENT_GROUP_MEMBER_JOINED, LGRI.UpdateMyRole)
  2.  
  3. or separately?
  4.  
  5. EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  6. EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_JOINED, LGRI.UpdateMyRole)

Last edited by nilo : 03/19/23 at 01:11 PM.
  Reply With Quote