mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 22:22:46 +00:00
new docs
This commit is contained in:
1 parent
3cebaf7fa5
commit
b5eba8423f
229 files changed
+6238
-10690
No files matched your search
@@ -0,0 +1,57 @@
|
||||
Adds an item into the specified inventory.
|
||||
|
||||
Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximum weight may be exceeded.
|
||||
|
||||
```lua
|
||||
exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb)
|
||||
```
|
||||
|
||||
- inv: `table` or `string` or `number`
|
||||
- The inventory's unique id, or a table with the id and owner.
|
||||
- playerId: `1`
|
||||
- inventoryId: `gloveVGH283`
|
||||
- `{ id = 'personallocker', owner = 'license:xxxxxx'}`
|
||||
- item: `string`
|
||||
- The name of the item to add to the target.
|
||||
- count: `number`
|
||||
- The number of items to add.
|
||||
- metadata?: `table` or `string`
|
||||
- A table of unique data to attach to the item object. A string will create a table with the "type" field.
|
||||
- slot?: `number`
|
||||
- A specific slot to add the item to. If the slot is invalid, the first available slot will be used instead.
|
||||
- cb?: function(success: `boolean`, response?: `string`)
|
||||
|
||||
If used for glovebox, trunk or stash you must first check the inventory is loaded with [GetInventory](./GetInventory.md)
|
||||
|
||||
Returns `success, response` if cb is undefined, otherwise they are used in the callback only.
|
||||
|
||||
**Example:**
|
||||
|
||||
```lua
|
||||
local success, response = exports.ox_inventory:AddItem('gloveVGH283', 'bread', 4)
|
||||
|
||||
if not success then
|
||||
-- if no slots are available, the value will be "inventory_full"
|
||||
return print(response)
|
||||
end
|
||||
|
||||
print(json.encode(response, {indent=true}))
|
||||
--[[
|
||||
{
|
||||
"metadata": [],
|
||||
"label": "Bread",
|
||||
"slot": 1,
|
||||
"stack": true,
|
||||
"close": true,
|
||||
"name": "bread",
|
||||
"count": 1,
|
||||
"weight": 150
|
||||
}
|
||||
]]
|
||||
```
|
||||
|
||||
**Possible value of the "response" argument, on failure:**
|
||||
|
||||
- "invalid_item": the item doesn't exist
|
||||
- "invalid_inventory": the inventory doesn't exist
|
||||
- "inventory_full": no free slots
|
||||
Reference in new issue
Block a user