Thread Tools Display Modes
11/25/15, 09:34 PM   #1
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Event for entering a group (and have unit frames ready)

I'm having the hardest time figuring out how to properly detect when I get in a group. Whatever event I use it seems there's always some missing information at that point.

I need an event that tells me:

- I'm in a group
- The unit frames for group mates are created

And from any state

- I got invited
- I invited someone
- I was offline and logged in already in a group
- I am in a group and reloaded the UI
- Any other possible state

I was using the official source for unit frames as a guide - http://esodata.uesp.net/current/src/....lua.html#2024

On EVENT_PLAYER_ACTIVATED it seems I can't iterate over UNIT_FRAMES.groupFrames, they're not always initialized at this point.

EVENT_GROUP_UPDATE, EVENT_UNIT_CREATED, EVENT_UNIT_FRAME_UPDATE and EVENT_GROUP_MEMBER_JOINED does not happen every time, or not with everyone, or some other shortcoming.

Any ideas?
  Reply With Quote
11/26/15, 03:01 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
I had the same problem which couldn't be solved in the past.
So I wrote a workaround at player activated event callback function, which get's the actual group size and checks if I'm in the group member table:


Lua Code:
  1. -- Get group Size
  2.     local groupSize = GetGroupSize()
  3.     if groupSize <= 1 then
  4.         d(">> You are not in a group")
  5.         return
  6.     end
  7.  
  8.     local charName
  9.     local playerName = GetUnitName("player")
  10.     -- Cycle through group and check their "unitTags"
  11.     for i=1, groupSize, 1 do
  12.         charName = GetUnitName(GetGroupUnitTagByIndex(i))
  13.         if charName == playerName then
  14.             d("You are in a group!")
  15.                 return -- break here
  16.         end
  17.     end

Edit:
Oh and for all other situations the callback function for event EVENT_GROUP_MEMBER_JOINED used the same check, and it fired correctly for me (couldn't test it in the past days though!)

Last edited by Baertram : 11/26/15 at 03:04 AM.
  Reply With Quote
11/26/15, 04:50 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
@Baertram: There are easier ways to check if someone is in a group:
Lua Code:
  1. IsPlayerInGroup(characterName)
  2. IsUnitGrouped("player")

@haggen: In my SocialIndicators addon I do not directly operate on every group member event as there are a lot of things going on when a member joins that caused micro freezes in the past (and still do sometimes) without addons adding more work.
So in regard to accessing the unit frames this is what I do in my upcoming update for SocialIndicators:

Lua Code:
  1. local function ClearCallLater(id)
  2.     EVENT_MANAGER:UnregisterForUpdate("CallLaterFunction"..id)
  3. end
  4.  
  5. local function RequestUpdateGroupSocialIndicators()
  6.     if(refreshGroupIconsPending) then
  7.         ClearCallLater(refreshGroupIconsPending)
  8.         refreshGroupIconsPending = false
  9.     end
  10.     if(IsUnitGrouped("player")) then
  11.         refreshGroupIconsPending = zo_callLater(UpdateGroupSocialIndicators, 200)
  12.     end
  13. end
  14. ...
  15. -- in OnAddonLoaded:
  16.     UpdateGroupSocialIndicators()
  17.  
  18.     RegisterForEvent(EVENT_GROUP_MEMBER_JOINED, RequestUpdateGroupSocialIndicators)
  19.     RegisterForEvent(EVENT_GROUP_MEMBER_LEFT, RequestUpdateGroupSocialIndicators)
  20.     RegisterForEvent(EVENT_GROUP_TYPE_CHANGED, RequestUpdateGroupSocialIndicators)
  21.     RegisterForEvent(EVENT_GROUP_UPDATE, RequestUpdateGroupSocialIndicators)

As for the other things you need:
- I got invited
GetGroupInviteInfo()
EVENT_GROUP_INVITE_RECEIVED
EVENT_GROUP_INVITE_REMOVED

- I invited someone
Does not seem to be possible to completely track it via the api.
You will need to hook into all the methods that allow you to invite someone and remember who was invited.
GroupInvite(*string* _unitTag_)
GroupInviteByName(*string* _name_)

At least you should get an event when that invite changes: EVENT_GROUP_INVITE_RESPONSE

- I was offline and logged in already in a group
- I am in a group and reloaded the UI
- Any other possible state
See above.
  Reply With Quote
11/26/15, 09:34 PM   #4
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
So, I registered a bunch of events with a debug function and then invited some random fella from my guild to group, note that he/she was in a different region.

Here's the events that were triggered, with some additional information:

- Value of UNIT_FRAMES.groupSize
- If a unitTag was provided in the arguments


Code:
1. EVENT_GROUP_MEMBER_ROLES_CHANGED,    groupSize = 0, unitTag = group2
2. EVENT_GROUP_MEMBER_IN_REMOTE_REGION, groupSize = 0, unitTag = group2
3. EVENT_GROUP_MEMBER_JOINED,           groupSize = 0, no unitTag, but my name character's was available
4. EVENT_LEADER_UPDATE,                 groupSize = 0, unitTag = group1
5. EVENT_GROUP_SUPPORT_RANGE_UPDATE,    groupSize = 0, unitTag = group2
In this test I was assigned as "group1".

The events I was listening to were:

- EVENT_GROUP_MEMBER_CONNECTED_STATUS
- EVENT_GROUP_MEMBER_IN_REMOTE_REGION
- EVENT_GROUP_MEMBER_JOINED
- EVENT_GROUP_MEMBER_LEFT
- EVENT_GROUP_MEMBER_ROLES_CHANGED
- EVENT_GROUP_NOTIFICATION_MESSAGE
- EVENT_GROUP_SUPPORT_RANGE_UPDATE
- EVENT_GROUP_TYPE_CHANGED
- EVENT_GROUP_UPDATE
- EVENT_LEADER_UPDATE
- EVENT_UNIT_FRAME_UPDATE

The important lesson here is: during these events the unit frames were NOT ready, and NONE of them provided me with full information of my party, nor one same event was fired for each member of my group.

Really, WHAT THE ****?
  Reply With Quote
11/26/15, 09:42 PM   #5
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Now, I reloaded the UI, left the group and asked the guy to invite me back again.

Here's what happened:

Code:
EVENT_GROUP_MEMBER_ROLES_CHANGED,    0, group1
EVENT_GROUP_MEMBER_IN_REMOTE_REGION, 0, group1
EVENT_GROUP_MEMBER_ROLES_CHANGED,    0, group2
EVENT_GROUP_MEMBER_IN_REMOTE_REGION, 0, group2
EVENT_GROUP_MEMBER_JOINED,           0, only my name
EVENT_GROUP_SUPPORT_RANGE_UPDATE,    0, group1
EVENT_GROUP_SUPPORT_RANGE_UPDATE,    0, group2

Last edited by haggen : 11/26/15 at 09:46 PM.
  Reply With Quote
11/26/15, 10:43 PM   #6
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
One last trivia, I formed a grouped, logged out and then in, here's what happened.


Code:
GameTimeMilliseconds | Event                               | unitTag
---------------------+-------------------------------------+---------
            10421439 | EVENT_LEADER_UPDATE                 | [Empty String]
            10421439 | UNIT_CREATED                        | group1
            10421439 | EVENT_GROUP_MEMBER_ROLES_CHANGED    | group1
            10421439 | EVENT_GROUP_MEMBER_IN_REMOTE_REGION | group1
            10421439 | UNIT_CREATED                        | group2
            10421439 | EVENT_GROUP_MEMBER_ROLES_CHANGED    | group2
            10421439 | EVENT_GROUP_MEMBER_IN_REMOTE_REGION | group2
            10421445 | EVENT_GROUP_UPDATE                  | -
            10421445 | EVENT_GROUP_SUPPORT_RANGE_UPDATE    | group1
            10421445 | EVENT_GROUP_SUPPORT_RANGE_UPDATE    | group2
            10421892 | UNIT_CREATED                        | group1
            10421892 | UNIT_CREATED                        | group2
            10421894 | EVENT_GROUP_UPDATE                  | -
Anyway, I'm gonna standardize the tests and run them all again tomorrow or this weekend.
  Reply With Quote
11/27/15, 05:48 AM   #7
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
UNIT_FRAMES.groupSize is only updated in specific cases.
  • EVENT_PLAYER_ACTIVATED fires
  • EVENT_GROUP_UPDATE fires and EVENT_UNIT_CREATED or EVENT_UNIT_DESTROYED has fired before
  • every second in the OnUpdate handler of ZO_UnitFrames if EVENT_UNIT_CREATED or EVENT_UNIT_DESTROYED has fired before
If you want to know the group size before that happens, use GetGroupSize() instead.
  Reply With Quote
11/27/15, 06:26 AM   #8
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Originally Posted by sirinsidiator View Post
UNIT_FRAMES.groupSize is only updated in specific cases.
  • EVENT_PLAYER_ACTIVATED fires
  • EVENT_GROUP_UPDATE fires and EVENT_UNIT_CREATED or EVENT_UNIT_DESTROYED has fired before
  • every second in the OnUpdate handler of ZO_UnitFrames if EVENT_UNIT_CREATED or EVENT_UNIT_DESTROYED has fired before
If you want to know the group size before that happens, use GetGroupSize() instead.
Thank you. I actually was just trying to check if the unit frames for group were ready. I guess this wasn't the best way to do this. Anyway, as I said, I'm gonna improve the tests and run some full scenarios so I can better evaluated what happens when and in what order.
  Reply With Quote
11/28/15, 07:42 PM   #9
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
I did not test any of this, but maybe it will help.

As for your problem with unit frames not being initialized yet. The zos code registers for this event to create/initialize UNIT_FRAMES:
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("UnitFrames_OnAddOnLoaded", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

and when its done it fires this callback & unregisters the event:
Lua Code:
  1. CALLBACK_MANAGER:FireCallbacks("UnitFramesCreated")
  2. EVENT_MANAGER:UnregisterForEvent("UnitFrames_OnAddOnLoaded", EVENT_ADD_ON_LOADED)

So it doesn't look like you need PLAYER_ACTIVATION, you could just register for that callback to know when it is done initializing UNIT_FRAMES and then UNIT_FRAMES.groupFrames should be available:
Warning: Spoiler


As for knowing when a unit in the unit frames change: it looks like when the units change a dirty flag is set and after it updates everything the flag is cleared. I would think you could just use that function so you know when it is done updating all of the unit frames.
Warning: Spoiler


I think sirinsidiator answered the other questions.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Event for entering a group (and have unit frames ready)


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