attempt to make luke happy

Lazy and poorly "typed" shops guide.
Update AddItem and RemoveItem typings and improve examples.
Add hooks.
This commit is contained in:
Linden committed 2022-11-07 08:26:27 +11:00
1 parent 9f803f6a99
commit 2bfdefcc9d
4 files changed
+253 -42

No files matched your search

@@ -3,43 +3,51 @@ Adds an item into the specified inventory.
Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximum weight may be exceeded.
```lua
-- inv: string or number
-- item: table or string
-- count: number
-- metadata: table or string (optional)
-- slot: number (optional)
-- cb: function (optional)
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 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
- 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`)
print(reason)
-- for example if all slots are taken it will give us "inventory_full"
end
end)
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 "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
**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