Quantcast
WoWInterface - View Single Post - Logging the item my character acquired
View Single Post
05-19-17, 10:06 AM   #6
Eommus
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 28
Originally Posted by Kanegasi View Post
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 View Post
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 View Post
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 View Post
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:
  1. LootLog = {}
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  5. f:RegisterEvent("BAG_UPDATE")
  6.  
  7. local function Log_Loot()
  8.     for bag = 0, NUM_BAG_SLOTS do
  9.         for slot = 1, GetContainerNumSlots(bag) do
  10.             local item = GetContainerItemLink(bag, slot)
  11.             local itemName = select(1, GetItemInfo(item))
  12.            
  13.             LootLog[itemName] = {}
  14.         end
  15.     end
  16. end
  17.  
  18. 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.

Last edited by Eommus : 05-19-17 at 01:13 PM.
  Reply With Quote