1. #1

    Trigger when an item is placed in my inventory

    Hi,

    Is there an event that is triggered when an item is placed in my inventory? The source can be anything, e.g.:

    - looting a mob
    - opening a chest or box
    - opening mail
    - trading with another player
    - buying from a vendor
    - crafting
    - quest reward
    ...

    simply any action that may place an item in your inventory.

    If there isn't one single event to handle all these, which other events shall I need to register, in addition to LOOT_OPENED?

    Basically, I want my addon function to trigger when my character gets a new item from external sources (excluding moving an item from one bag to another, from my personal bank, reagent storage or guild bank).

    Thanks for any ideas.

  2. #2
    Deleted
    I think Xloot already does this, have notif window like in GW2

  3. #3
    You could check the chat-message-lock for loot-events and handle them in your weakaura

  4. #4
    There are different events that fire depending on the situation.

    There's one event that fires for looting a corpse. There might be 2-3 different events that fire if you craft something depending on what it is. A proc that generates an item on the side might be a different event. Completing a world quest kinda has its own ecosystem and might have its own event.

    you have to use /eventtrace to hunt them down.

    /eventtrace will pull up the event window in-game. shows you what events are firing.

    /eventtrace stop
    /eventtrace start

    those will let you cut out the noise because sometimes there are a lot of events firing.
    TO FIX WOW:1. smaller server sizes & server-only LFG awarding satchels, so elite players help others. 2. "helper builds" with loom powers - talent trees so elite players cast buffs on low level players XP gain, HP/mana, regen, damage, etc. 3. "helper ilvl" scoring how much you help others. 4. observer games like in SC to watch/chat (like twitch but with MORE DETAILS & inside the wow UI) 5. guild leagues to compete with rival guilds for progression (with observer mode).6. jackpot world mobs.

  5. #5
    The BAG_UPDATE Event that fire when you put anything or move anything in your bag

  6. #6
    Quote Originally Posted by Rehok View Post
    The BAG_UPDATE Event that fire when you put anything or move anything in your bag
    Thanks for the note, this might be what I can use. As usual, I seek the simplest method that would do the job. So, if there's one single event that will do the job, that will be enough.

    http://wowprogramming.com/docs/events/BAG_UPDATE page says BAG_UPDATE event needs to be registered after PLAYER_ENTERING_WORLD, to prevent excessive processing at each UI load/reload. Is this how it is done?

    Code:
    local f = CreateFrame("Frame")
    f:RegisterEvent("PLAYER_ENTERING_WORLD")
    f:RegisterEvent("BAG_UPDATE")
    
    local function My_Function()
    	...
    end
    
    f:SetScript("OnEvent", My_Function)

    Also, BAG_UPDATE requires a bag id, how do I find the bag ids for my inventory bags (5 of them) and how do I use that ids in my code? Unfortunately, I couldn't find any sample code explaining that.

    If it would help, here is my current code, which is supposed to log (in a savedvariable lua file) the id of every item I obtain in the game from any source I listed in the OP.

    Code:
    LootLog = {}
    
    local f = CreateFrame("Frame")
    f:RegisterEvent("LOOT_OPENED")
    
    local function Log_Loot()
    	local n = GetNumLootItems()
    	for i = 1, n do
    		local item = GetLootSlotLink(i)
    		local itemId = select(2, strsplit(":", itemLink, 3))
    		
    		table.insert(LootLog, itemId)
    	end
    end
    
    f:SetScript("OnEvent", Log_Loot)

    It works fine for "loot" type of item acquisition, I just want it to work for any type of item acquisition.
    Last edited by Eommus; 2017-05-18 at 07:26 AM.

  7. #7
    You would use

    Code:
    for bag = 0, NUM_BAG_SLOTS do                for slot = 1, GetContainerNumSlots(bag) do
              -- do stuff
    You can see how its used (sort of) in the APUse WA's (https://wago.io/UseArtifactPowerIcon or https://wago.io/UseArtifactPower)

  8. #8
    Quote Originally Posted by Rehok View Post
    You would use

    Code:
    for bag = 0, NUM_BAG_SLOTS do                for slot = 1, GetContainerNumSlots(bag) do
              -- do stuff
    You can see how its used (sort of) in the APUse WA's (https://wago.io/UseArtifactPowerIcon or https://wago.io/UseArtifactPower)
    Thank you, I modified my code as:

    Code:
    LootLog = {}
    
    local f = CreateFrame("Frame")
    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))
    			
    			table.insert(LootLog, itemName)
    		end
    	end
    end
    
    f:SetScript("OnEvent", Log_Loot)

    I don't know if I am doing the loop correctly but it creates the same entry 183 times. Say, I acquired 1 item, it logs that item for 183 times. Then if I acquire another item, it logs those two items 183 times. I have backpack (16) plus 4 x 30 bags, 136 slots in total.
    Last edited by Eommus; 2017-05-18 at 12:40 PM.

  9. #9
    I ended up with the following code, which is more efficient than BAG_UPDATE and works just as I wanted (also, it does not create duplicate entries):

    Code:
    LootLog = {}
     
    local f = CreateFrame("Frame")
    f:RegisterEvent("CHAT_MSG_LOOT")
     
    function Log_Loot(self, event, message, _, _, _, player, _, _, _, _, _, _, ...)
        if player == "Eommus" then
            local itemId = message:match("item:(%d+):")
            LootLog[itemId] = {}
        end
    end
     
    f:SetScript('OnEvent', Log_Loot)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •