View Single Post
10/30/15, 05:59 PM   #23
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
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:
  1. 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:
  1. 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:
  1. if IsUnderArrest() then return end -- Avoid check when a guard destroy stolen items
Game will check all your backpack.



Lua Code:
  1. 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:
  1. 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:
  1. function LootDrop:OnSingleSlotUpdate(_, bagId, slotId, _, _, updateReason)
  2.    
  3.     if bagId == BAG_BACKPACK and updateReason == INVENTORY_UPDATE_REASON_DEFAULT and IsUnderArrest() == false then
  4.        
  5.         self.lastSingleSlotUpdateSlotId = slotId
  6.  
  7.     end
  8. 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!
  Reply With Quote