Thread Tools Display Modes
12/23/15, 08:17 AM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Bug with EVENT_UNIT_CREATED and GetUnit*

I tried to get the unit name of newly joined group members and found that it does not work as expected.
Here is the code I tested it with:
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("nametest", EVENT_UNIT_CREATED, function(_, unitTag)
  2. df("unit created: %s %s (%s)", tostring(unitTag), GetUnitDisplayName(unitTag), tostring(DoesUnitExist(unitTag)))
  3. end)

When I make a new group, I get one EVENT_UNIT_CREATED for myself which is fine, but for some reason I get two events for whoever I invited. Besides that everything works fine in all three events.
Code:
unit created: group1 @sirinsidiator (true)
unit created: group2 @groupie1 (true)
unit created: group2 @groupie1 (true)
But when I invite another player, the first occurrence returns an empty name and only the second one works as expected.
Code:
unit created: group3  (true)
unit created: group3 @groupie2 (true)
DoesUnitExist does not help as it always returns true, so the only thing I can do is check for an empty string and ignore those events.
  Reply With Quote
12/26/15, 10:48 PM   #2
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
This probably isn't very helpful, but here is a snippet I found in the lua files. It looks like they call a delay when a unit is created (or destroyed) and then call self:BuildMasterList() to rebuild all of the group data from scratch. So whatever is causing it, this is probably a known issue. They do the same when a unit is destroyed.

ZO_GroupList_Manager.lua

Lua Code:
  1. function ZO_GroupList_Manager:RegisterForEvents()
  2.     --  During group invitation, we can receive a lot of event spam at once on a single invite when the
  3.      -- involved players are at the same location. Add a delay so we only refresh once in cases like this.
  4.     local function DelayedRefreshData()
  5.         self.delayedRebuildCounter = self.delayedRebuildCounter - 1
  6.         if self.delayedRebuildCounter == 0 then
  7.             self:RefreshData()
  8.         end
  9.     end
  10.  
  11.     local function RegisterDelayedRefresh()
  12.         self.delayedRebuildCounter = self.delayedRebuildCounter + 1
  13.         zo_callLater(DelayedRefreshData, 50)
  14.     end
  15.  
  16.   ...
  17. end
  18.  
  19. EVENT_MANAGER:RegisterForEvent("ZO_GroupList_OnUnitCreated", EVENT_UNIT_CREATED, RegisterDelayedRefreshOnUnitEvent)
  20. EVENT_MANAGER:RegisterForEvent("ZO_GroupList_OnUnitDestroyed", EVENT_UNIT_DESTROYED, RegisterDelayedRefreshOnUnitEvent)
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Bug with EVENT_UNIT_CREATED and GetUnit*


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