ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Bug with EVENT_UNIT_CREATED and GetUnit* (https://www.esoui.com/forums/showthread.php?t=5553)

sirinsidiator 12/23/15 08:17 AM

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.

circonian 12/26/15 10:48 PM

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)


All times are GMT -6. The time now is 03:07 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI