From 07fc67545a696850dfb34f6eb54ade7e95f20c13 Mon Sep 17 00:00:00 2001 From: Cuchi Date: Sat, 23 Apr 2022 15:16:28 +0200 Subject: [PATCH] Update AddItem --- .../Functions/Server/Inventory/AddItem.md | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/docs/ox_inventory/Functions/Server/Inventory/AddItem.md b/docs/ox_inventory/Functions/Server/Inventory/AddItem.md index 618b31da..cf2db810 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/AddItem.md +++ b/docs/ox_inventory/Functions/Server/Inventory/AddItem.md @@ -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) -``` \ No newline at end of file +``` + +**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