Originally Posted by Garkin
I think that the easiest solution is checking if arguments are valid before you use them.
Lua Code:
--for our purposes are valid bags: -- BAG_WORN (0) -- BAG_BACKPACK (1) -- BAG_BANK (2) -- BAG_GUILDBANK(3) --Other bags are invalid: -- BAG_BUYBACK (4), -- BAG_TRANSFER (5) -- BAG_DELETE(255) local function IsSlotOccupied(bagId, slotIndex) if (type(bagId) == "number" and bagId >= 0 and bagId <= 3) then if (type(slotIndex) == "number" and slotIndex >= 0 and slotIndex <= GetBagSize(bagId) - 1) then local _, stackCount = GetItemInfo(bagId, i) return stackCount > 0 end end end --function returns: --true: bag slot is occupied --false: bag slot is empty --nil: invalid bagId or slotIndex arguments
This is how it does inventory manager:
Lua Code:
function ZO_InventoryManager:IsSlotOccupied(bagId, slotIndex) local inventoryType = self.bagToInventoryType[bagId] local slot = self.inventories[inventoryType].slots[slotIndex] return ((slot ~= nil) and (slot.stackCount > 0)) end
Global reference to that function is PLAYER_INVENTORY:IsSlotOccupied(bagId, slotIndex)
|
Ok, I didn't know if there was some function built in to do it for me or not.
Thanks for the help Garkin.