Originally Posted by Kanegasi
The LootLog table initialization was fine where it was.
|
Yes, I read that it is done like that to save data between sessions. Though, I am just a newbie to LUA, so, just trying to stitch together bits of info here or there.
Originally Posted by Kanegasi
The problem is that you're looking through your entire inventory every bag update, adding an item 183 times because you have 183 total slots.
|
How do you calculate 183? I have backpack (16), 4 x 30 slot bags, shouldn't it be 136 in total?
Originally Posted by Kanegasi
What I find weird is that it's adding the same item, but your code should add every item the way it's written.
|
I also found that weird
Originally Posted by Kakjens
I don't see how moving LootLog = {} to just above table.insert(LootLog, itemName) would save anything but the last entry.
Also, I don't see how you are loading items from previous session.
Instead of table.insert(LootLog, itemName) I would suggest using LootLog[itemName] = {}, assuming you don't want to track how many items you obtained.
Edit. Also, there might be better events to watch, for example, "BAG_UPDATE_DELAYED" or events dealing with loot. Additionally, I think long time ago there was an addon that tracked what previously dropped from a mob. Due to AoE looting, it might be abandoned.
|
I started with LOOT_OPENED event which worked just fine for item acquisition from mobs, gathering, containers etc. (things that open a loot window) but I want to log
every item I acquire in every possible way as mentioned in my first post (loot, quest reward, trade, vendor, crafting etc.). Anything that enters into my inventory from an external source. I was recommended to use BAG_UPDATE as it seemed the best candidate.
With your tips and comments, I was finally able to do it, using the code below:
Lua Code:
LootLog = {}
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("BAG_UPDATE")
local function Log_Loot()
for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do
local item = GetContainerItemLink(bag, slot)
local itemName = select(1, GetItemInfo(item))
LootLog[itemName] = {}
end
end
end
f:SetScript("OnEvent", Log_Loot)
My last questions: Is my use of PLAYER_ENTERING_WORLD correct (I used it for efficiency, not sure). Is the code I have efficient?
Thanks.