View Single Post
02/12/17, 08:15 AM   #4
ArtOfShred
 
ArtOfShred's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 103
Originally Posted by Klingo View Post
snip
Hey thanks for all the suggestions!

I was actually looking into indexing the inventory earlier today to do something like this, and I got it figured out. And it works for crafting/laundering too.

Basically have a function for open/closing of Bank/Guild Bank/Fence/Crafting Station and it registers a different event for EVENT_INVENTORY_SINGLE_SLOT_UPDATE and uses a function to index the contents of my bag and bank where relevant. Then any changes to those slots has context sensitive messages sent to a print function that gathers further info on the item based off the itemlink.

I haven't finalized the implementation yet, but now that I have this enabled, I'm pretty sure I have 100% coverage for inventory change events with LUI now (Except transfer from craft bag to normal bag, but there's no loss present there so not necessary).

I even went as far as adding a function for EVENT_INVENTORY_ITEM_DESTROYED that sets a variable to true, and if the next EVENT_INVENTORY_SINGLE_SLOT_UPDATE reads that variable, it will print the item destroyed.

BTW, this is the function for indexing the inventory, can just run this on initialization and also call it before opening a bank, etc:

The 3 forms of information extracted here are all we need, any other information can be pulled from the itemlink if sent to another function.

Code:
function CA.IndexInventory()

-- Bag 1 = player bag, bag 2 = bank, bag 3 = guild bank, bag 5 = crafting bag (too big to index)

local bagsize = GetBagSize(1)

    for i = 1,bagsize do
        local icon, stack = GetItemInfo(1, i)
        local bagitemlink = GetItemLink(1, i, LINK_STYLE_DEFAULT)
        if bagitemlink ~= "" then
            g_InventoryStacks[i] = { icon=icon, stack=stack, itemlink=bagitemlink}
        end
    end
    
end

Last edited by ArtOfShred : 02/12/17 at 08:20 AM.