Thread: Junk events
View Single Post
05/17/14, 09:01 AM   #7
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
In my add-on, here is how I handle junk (don't mind the if checks in front of the event registers):

Registering event & marking junk:
Code:
if QB_vars.trashTreatmentSelection >= 2 then EVENT_MANAGER:RegisterForEvent( "QB", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, QB_HandlerSingleSlotUpdate ) end
...
local function QB_HandlerSingleSlotUpdate( _, bagId, slotIndex, isNewItem )
	if not isNewItem then return end
	if GetItemType( bagId, slotIndex ) == 48 then SetItemIsJunk( bagId, slotIndex, true ) end
end
Auto-sell:
Code:
if QB_vars.trashTreatmentSelection == 3 then EVENT_MANAGER:RegisterForEvent( "QB", EVENT_OPEN_STORE, QB_HandlerStoreOpened ) end
...
local function QB_HandlerStoreOpened()
	SellAllJunk()
end
In short, when we get an item, the event will fire, and we check if it is a new item, then if it is a trash item by using the passed badID and slotIndex. The API function, GetItemType() will return 48 if it is a trash quality item. If it is so, we mark it as junk.

Last edited by lyravega : 05/17/14 at 09:06 AM.
  Reply With Quote