Little update, because I still see some code with function linked to event and which execute code without doing any checks, so a little collection :
Lua Code:
if bagId ~= BAG_BACKPACK then return end --handle just backpack updates
Here, add the desired bags. Don't forget that moving an item to another bag fires twice the event.
Lua Code:
if updateReason ~= INVENTORY_UPDATE_REASON_DEFAULT then return end --ignore durability/dye update
At EACH damage or xp gained, the event can fire.
Lua Code:
if IsUnderArrest() then return end -- Avoid check when a guard destroy stolen items
Game will check all your backpack.
Lua Code:
if Roomba and Roomba.WorkInProgress and Roomba.WorkInProgress() then return end --support for Roomba
Some addons may working, please consider them and disable your code while they are doing their stuff.
Lua Code:
if IsItemJunk(bagId, slotId) then return end --we do not need to check junk again
Especially for item junkers. Do not do many checks, if it's pointless
If you need this event to get the slotId for your loot, just try to do a single thing in the function :
EVENT_SINGLE_SLOT_UPDATE always fires before EVENT_LOOT_RECEIVED, so this code will always be valid.
Lua Code:
function LootDrop:OnSingleSlotUpdate(_, bagId, slotId, _, _, updateReason)
if bagId == BAG_BACKPACK and updateReason == INVENTORY_UPDATE_REASON_DEFAULT and IsUnderArrest() == false then
self.lastSingleSlotUpdateSlotId = slotId
end
end
You can also Unregister the event listener while .... interacting with npc, opening bank, guild bank, be in combat, open mailbox, it depends of your needs!