Thread Tools Display Modes
07/08/19, 08:53 PM   #1
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
Collectible Unlocked Event?

I'm trying to get my addon to trigger when a collectible is unlocked, specifically when a house is purchased so that I can update my data. However I can't seem to find the event that I thought was there a while back. The event "EVENT_COLLECTIBLE_UPDATED" doesn't seem to fire when I think it should and the "EVENT_COLLECTION_UPDATED" doesn't have any other parameters that it passes to detect what was going on. Anyone have some insight here? Even just tell me where to look in the source code. I looked there but the event that is listed in the source code doesn't exist anymore.

Thanks in advance!
  Reply With Quote
07/08/19, 10:59 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I only did a quick search, and you might have found this already:

Code:
--[[
        EVENT_COLLECTIBLE_UPDATED fires when a nickname changes or a collectible is set as active/inactive. It does not encompass unlock state changes.
        EVENT_COLLECTION_UPDATED happens on init or when a command forces all collectibles to lock/unlock (re-init). Those cases don't use dirty unlock mappings from C, so we do that delta work here while we refresh everything.
        EVENT_ESO_PLUS_FREE_TRIAL_STATUS_CHANGED can happen at any time, and is an event that tells us to re-evaluate unlock status for everything because anything could be based on that. Like with EVENT_COLLECTION_UPDATED, we handle the delta here, not in C.
        EVENT_COLLECTIBLES_UNLOCK_STATE_CHANGED happens when the client maps out dirty unlock states (collectibles go on trial or ownership changes like crown store or rewards). We consume the dirty mapping from C and broadcast it out.
        The later 3 all fire the same callback ("OnCollectionUpdated") to all systems registering with the callback manager with info to help determine what happened: collectionUpdateType (ZO_COLLECTION_UPDATE_TYPE), collectiblesByNewUnlockState
    --]]
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTIBLE_UPDATED, function(_, ...) self:OnCollectibleUpdated(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTION_UPDATED, function(_, ...) self:OnCollectionUpdated(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_ESO_PLUS_FREE_TRIAL_STATUS_CHANGED, function(_, ...) self:OnESOPlusFreeTrialStatusChanged(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTIBLES_UNLOCK_STATE_CHANGED, function(_, ...) self:OnCollectiblesUnlockStateChanged(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTIBLE_NEW_STATUS_CLEARED, function(_, ...) self:OnCollectibleNewStatusCleared(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTIBLE_CATEGORY_NEW_STATUS_CLEARED, function(_, ...) self:OnCollectibleCategoryNewStatusCleared(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTIBLE_NOTIFICATION_NEW, function(_, ...) self:OnCollectibleNotificationNew(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_COLLECTIBLE_NOTIFICATION_REMOVED, function(_, ...) self:OnCollectibleNotificationRemoved(...) end)
EVENT_MANAGER:RegisterForEvent("ZO_CollectibleDataManager", EVENT_HOUSING_PRIMARY_RESIDENCE_SET, function(_, ...) self:OnPrimaryResidenceSet(...) end)

https://github.com/esoui/esoui/blob/...atamanager.lua

Maybe you can use EVENT_COLLECTIBLES_UNLOCK_STATE_CHANGED (if this is not the one which you meant was removed).
Or you use the callback function "function ZO_CollectibleDataManager:OnCollectiblesUnlockStateChanged()" with a ZO_PreHook.
As the are no parameter you might need to rebuild the code in there yourself to get the colelctibleIds unlocked:

Lua Code:
  1. ZO_PreHook(ZO_COLLECTIBLE_DATA_MANAGER, "OnCollectiblesUnlockStateChanged", function()
  2. d("A collectible was unlocked!")
  3.     --Copied from [url]https://github.com/esoui/esoui/blob/c47af79c7c51681ae315d4f9a6d70d9e965ad514/esoui/ingame/collections/collectibledatamanager.lua[/url]
  4.  
  5.     local function GetNextDirtyUnlockStateCollectibleIdIter(_, lastCollectibleId)
  6.         --Attention: PLease test here, if your PreHook to the event function, which callls GetNextDirtyUnlockStateCollectibleId before the non-prehooked original code will call GetNextDirtyUnlockStateCollectibleId again, does break the function GetNextDirtyUnlockStateCollectibleId somehow so that the original code won't find any new collectible afterwards! If this is the case you need to copy the whole function somehow and assure all original code is run beside yours. But please do not overwrite it as other addons might get destroyed this way.
  7.         return GetNextDirtyUnlockStateCollectibleId(lastCollectibleId)
  8.     end
  9.  
  10.     function ZO_CollectibleDataManager:OnCollectiblesUnlockStateChanged()
  11.         local collectiblesByNewUnlockState = {}
  12.         for collectibleId in GetNextDirtyUnlockStateCollectibleIdIter do
  13. d(">collectibleId: " .. tostring(collectibelId)
  14. --[[
  15.             --If needed use this code as well to check if the colelctibelId and data is valid
  16.             local collectibleData = ZO_COLLECTIBLE_DATA_MANAGER.collectibleIdToDataMap[collectibleId]
  17.             if collectibleData then
  18.                 --sanity checks finished, run code
  19.             end
  20. ]]
  21.       end
  22. return false -- to call original code afterwards
  23. end)

Edit:
Please check if the PreHook will break the function GetNextDirtyUnlockStateCollectibleId somehow so that the original code won't get any new collectibelids after your prehook anymore.

Last edited by Baertram : 07/08/19 at 11:55 PM.
  Reply With Quote
07/09/19, 07:57 PM   #3
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
I actually ended up using EVENT_COLLECTIBLE_NOTIFICATION_NEW because I realised that every time you unlock a collectible you get a notification and the collectible id is one of the parameters. Works perfectly. Thanks for looking into it though!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Collectible Unlocked Event?

Thread Tools
Display Modes

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