--- Add card with metadata to player Inventory
--- @param source integer # Player source
--- @param metadata table # Contains metadata of the card (cardId, accountIdentifier)
--- @return boolean # Success
function addCardToInventory(source, metadata)
assert(math.type(source) == "integer", "Source needs to be an integer")
assert(type(metadata) == "table", "Metadata needs to be a table!")
local isSuccess = false
local canCarryItem = exports.ox_inventory:CanCarryItem(source, Config.item, 1, metadata)
if canCarryItem then
local availableSlot = exports.ox_inventory:GetEmptySlot(source)
exports.ox_inventory:AddItem(source, Config.item, 1, metadata, availableSlot, function(success)
if success then
sendDebugMessage("debug", "Item correctly added to inventory")
isSuccess = true
else
sendDebugMessage("error", "Failed to add item to inventory")
isSuccess = false
end
end)
else
sendDebugMessage("debug", "Inventory Full")
isSuccess = false
end
return isSuccess
end