Update AddItem

This commit is contained in:
Cuchi committed 2022-04-23 15:16:28 +02:00
1 parent 43f8625fa5
commit 07fc67545a
1 file changed
+26 -5
@@ -1,6 +1,6 @@
Adds an item into the specified inventory. Adds an item into the specified inventory.
Should be used alongside [CanCarryItem](./CanCarryItem.md). Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximum weight may be exceeded.
```lua ```lua
-- inv: string or number -- inv: string or number
@@ -15,10 +15,31 @@ exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb)
**Example:** **Example:**
```lua ```lua
exports.ox_inventory:AddItem(1, 'bread', 4, nil, nil, function(success, reason) exports.ox_inventory:AddItem(1, 'bread', 4, nil, nil, function(success, reason)
if not success then if success then
if reason == 'overburdened' then print(json.encode(reason, {indent=true}))
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = shared.locale('cannot_carry', count, data.label), duration = 2500}) --[[
end {
"metadata": [],
"label": "Bread",
"slot": 1,
"stack": true,
"close": true,
"name": "bread",
"count": 1,
"weight": 150
}
]]
else
print(success)
-- nil
print(reason)
-- for example if all slots are taken it will give us "inventory_full"
end end
end) end)
``` ```
**Possible value of the "reason" argument for the callback function:**
+ "invalid_item": the item doesn't exist
+ "invalid_inventory": the inventory doesn't exist
+ "inventory_full": no free slots