Merge pull request #16 from Cu-chi/main

Update AddItem (inventory)
This commit is contained in:
Linden authored and GitHub committed 2022-04-25 00:09:36 +10:00
commit 18a2e906a2
1 file changed
+27 -6
@@ -1,6 +1,6 @@
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
-- inv: string or number
@@ -15,10 +15,31 @@ exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb)
**Example:**
```lua
exports.ox_inventory:AddItem(1, 'bread', 4, nil, nil, function(success, reason)
if not success then
if reason == 'overburdened' then
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = shared.locale('cannot_carry', count, data.label), duration = 2500})
end
if success then
print(json.encode(reason, {indent=true}))
--[[
{
"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)
```
```
**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