Take a look at this...
Lua Code:
function ZO_SharedInventoryManager:Initialize()
local function OnInventoryItemDestroyed(eventCode, itemSoundCategory)
PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_DESTROY)
end
EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_ITEM_DESTROYED, OnInventoryItemDestroyed)
local function OnInventoryItemUsed(eventCode, itemSoundCategory)
PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_USE)
end
EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_ITEM_USED, OnInventoryItemUsed)
EVENT_MANAGER:RegisterForEvent(namespace, EVENT_OPEN_FENCE, function() self:RefreshInventory(BAG_BACKPACK) end)
self.bagCache = {}
self.questCache = {}
self.refresh = ZO_Refresh:New()
self.refresh:AddRefreshGroup("inventory",
{
RefreshAll = function()
self:RefreshInventory(BAG_BACKPACK)
self:RefreshInventory(BAG_WORN)
end,
RefreshSingle = function(...)
self:RefreshSingleSlot(...)
end,
})
self.refresh:AddRefreshGroup("guild_bank",
{
RefreshAll = function()
self:RefreshInventory(BAG_GUILDBANK)
end,
})
self.refresh:AddRefreshGroup("quest_inventory",
{
RefreshAll = function()
self:RefreshAllQuests()
end,
RefreshSingle = function(questIndex)
self:RefreshSingleQuest(questIndex)
end,
})
local function OnFullInventoryUpdated()
self.refresh:RefreshAll("inventory")
end
This is ZOs own code for the inventory refreshing functions for the destroy function and the like...
And maybe this for a few more ideas??
I find other peoples coding neat...
Lua Code:
local function OnInventorySlotUpdated(eventCode, bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
if updateReason == INVENTORY_UPDATE_REASON_DURABILITY_CHANGE then
local newCondition = GetItemCondition(bagId, slotIndex)
if newCondition == 100 then
self:FireCallbacks("ItemRepaired", bagId, slotIndex)
end
end
self.refresh:UpdateRefreshGroups()
self.refresh:RefreshSingle("inventory", bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
if bagId == BAG_BACKPACK then
if isNewItem and GetCraftingInteractionType() == CRAFTING_TYPE_INVALID then
PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_ACQUIRE)
end
elseif GetInteractionType() == INTERACTION_BANK and bagId == BAG_BANK then
PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_SLOT)
end
self:FireCallbacks("SingleSlotInventoryUpdate", bagId, slotIndex)
end
local function OnGuldBankUpdated()
self.refresh:RefreshAll("guild_bank")
self:FireCallbacks("FullInventoryUpdate", BAG_GUILDBANK)
end
local namespace = tostring(self)
EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_FULL_UPDATE, OnFullInventoryUpdated)
EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnInventorySlotUpdated)
EDIT: You could maybe make your own refresh functions in the same manner?? Or just hook theirs...