View Single Post
05/06/15, 11:14 AM   #4
Minceraft
 
Minceraft's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 51
Take a look at this...



Lua Code:
  1. function ZO_SharedInventoryManager:Initialize()
  2.     local function OnInventoryItemDestroyed(eventCode, itemSoundCategory)
  3.         PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_DESTROY)
  4.     end
  5.     EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_ITEM_DESTROYED, OnInventoryItemDestroyed)
  6.  
  7.     local function OnInventoryItemUsed(eventCode, itemSoundCategory)
  8.         PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_USE)
  9.     end
  10.     EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_ITEM_USED, OnInventoryItemUsed)
  11.  
  12.     EVENT_MANAGER:RegisterForEvent(namespace, EVENT_OPEN_FENCE, function() self:RefreshInventory(BAG_BACKPACK) end)
  13.  
  14.     self.bagCache = {}
  15.     self.questCache = {}
  16.  
  17.     self.refresh = ZO_Refresh:New()
  18.  
  19.     self.refresh:AddRefreshGroup("inventory",
  20.     {
  21.         RefreshAll = function()
  22.             self:RefreshInventory(BAG_BACKPACK)
  23.             self:RefreshInventory(BAG_WORN)
  24.         end,
  25.         RefreshSingle = function(...)
  26.             self:RefreshSingleSlot(...)
  27.         end,
  28.     })
  29.  
  30.     self.refresh:AddRefreshGroup("guild_bank",
  31.     {
  32.         RefreshAll = function()
  33.             self:RefreshInventory(BAG_GUILDBANK)
  34.         end,
  35.     })
  36.  
  37.     self.refresh:AddRefreshGroup("quest_inventory",
  38.     {
  39.         RefreshAll = function()
  40.             self:RefreshAllQuests()
  41.         end,
  42.         RefreshSingle = function(questIndex)
  43.             self:RefreshSingleQuest(questIndex)
  44.         end,
  45.     })
  46.  
  47.     local function OnFullInventoryUpdated()
  48.         self.refresh:RefreshAll("inventory")
  49.     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:
  1. local function OnInventorySlotUpdated(eventCode, bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
  2.         if updateReason == INVENTORY_UPDATE_REASON_DURABILITY_CHANGE then
  3.             local newCondition = GetItemCondition(bagId, slotIndex)
  4.             if newCondition == 100 then
  5.                 self:FireCallbacks("ItemRepaired", bagId, slotIndex)
  6.             end
  7.         end
  8.  
  9.         self.refresh:UpdateRefreshGroups()
  10.  
  11.         self.refresh:RefreshSingle("inventory", bagId, slotIndex, isNewItem, itemSoundCategory, updateReason)
  12.  
  13.         if bagId == BAG_BACKPACK then
  14.             if isNewItem and GetCraftingInteractionType() == CRAFTING_TYPE_INVALID then
  15.                 PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_ACQUIRE)
  16.             end
  17.         elseif GetInteractionType() == INTERACTION_BANK and bagId == BAG_BANK then
  18.             PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_SLOT)
  19.         end
  20.  
  21.         self:FireCallbacks("SingleSlotInventoryUpdate", bagId, slotIndex)
  22.     end
  23.  
  24.     local function OnGuldBankUpdated()
  25.         self.refresh:RefreshAll("guild_bank")
  26.         self:FireCallbacks("FullInventoryUpdate", BAG_GUILDBANK)
  27.     end
  28.  
  29.     local namespace = tostring(self)
  30.     EVENT_MANAGER:RegisterForEvent(namespace, EVENT_INVENTORY_FULL_UPDATE, OnFullInventoryUpdated)
  31.     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...

Last edited by Minceraft : 05/06/15 at 11:17 AM.
  Reply With Quote