mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
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:
1 parent
9f803f6a99
commit
2bfdefcc9d
4 files changed
+253
-42
No files matched your search
@@ -0,0 +1,106 @@
|
|||||||
|
Event hooks allow 3rd party resources to define new behaviour without modifying the inventory code directly.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
exports.ox_inventory:registerHook(eventName, function(payload) end, options)
|
||||||
|
```
|
||||||
|
|
||||||
|
- eventName: `string`
|
||||||
|
- payload: `table`
|
||||||
|
- options?: `table`
|
||||||
|
- print?: `boolean`
|
||||||
|
- Print to the console when triggering the event.
|
||||||
|
- itemFilter?: `{ [string]: true }`
|
||||||
|
- The event will only trigger for items defined as keys in a set.
|
||||||
|
- inventoryFilter?: `string[]`
|
||||||
|
- The event will only trigger for inventories that match one of the [patterns](<http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_(Regular_Expressions)>) in the array.
|
||||||
|
|
||||||
|
## swapItems
|
||||||
|
|
||||||
|
Triggered when moving any item from one slot to another, or when "giving" an item.
|
||||||
|
By returning `false`, you can cancel the action and revert the inventory state.
|
||||||
|
|
||||||
|
**Payload:**
|
||||||
|
|
||||||
|
- source: `number`
|
||||||
|
- action: `move` or `stack` or `swap` or `give`
|
||||||
|
- fromInventory: `number` or `string`
|
||||||
|
- toInventory:` number` or `string`
|
||||||
|
- fromType: `string`
|
||||||
|
- toType: `string`
|
||||||
|
- fromSlot: `table`
|
||||||
|
- toSlot?: `table` or `number`
|
||||||
|
- count: `number`
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```lua
|
||||||
|
exports.ox_inventory:registerHook('swapItems', function(payload)
|
||||||
|
print(json.encode(payload, { indent = true }))
|
||||||
|
return false
|
||||||
|
end, {
|
||||||
|
print = true,
|
||||||
|
itemFilter = {
|
||||||
|
water = true,
|
||||||
|
},
|
||||||
|
inventoryFilter = {
|
||||||
|
'^glove[%w]+',
|
||||||
|
'^trunk[%w]+',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Blacklists "water" from being moved into or from gloveboxes and trunks.
|
||||||
|
|
||||||
|
## openInventory
|
||||||
|
|
||||||
|
**Payload:**
|
||||||
|
|
||||||
|
- source: `number`
|
||||||
|
- inventoryId: `number` or `string`
|
||||||
|
- inventoryType: `string`
|
||||||
|
|
||||||
|
Triggered when a player tries to open a secondary inventory.
|
||||||
|
By returning `false`, you can cancel the action and keep the player's inventory closed.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
exports.ox_inventory:registerHook('openInventory', function(payload)
|
||||||
|
print(json.encode(payload, { indent = true }))
|
||||||
|
return false
|
||||||
|
end, {
|
||||||
|
print = true,
|
||||||
|
inventoryFilter = {
|
||||||
|
'^glove[%w]+',
|
||||||
|
'^trunk[%w]+',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Disables gloveboxes and trunks.
|
||||||
|
|
||||||
|
## createItem
|
||||||
|
|
||||||
|
**Payload:**
|
||||||
|
|
||||||
|
- inventoryId?: `number` or `string`
|
||||||
|
- metadata: `table`
|
||||||
|
- item: `table`
|
||||||
|
- count: `number`
|
||||||
|
|
||||||
|
Triggered when an item is created, either by buying it, using AddItem, or when converting inventory data.
|
||||||
|
By returning a table you can modify or replace the metadata given to an item.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
exports.ox_inventory:registerHook('openInventory', function(payload)
|
||||||
|
print(json.encode(payload, { indent = true }))
|
||||||
|
local metadata = payload.metadata
|
||||||
|
metadata.label = 'Mineral Water'
|
||||||
|
return metadata
|
||||||
|
end, {
|
||||||
|
print = true,
|
||||||
|
itemFilter = {
|
||||||
|
water = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets the label for "water" to "Mineral Water".
|
||||||
@@ -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.
|
Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximum weight may be exceeded.
|
||||||
|
|
||||||
```lua
|
```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)
|
exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb)
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example:**
|
- inv: `table` or `string` or `number`
|
||||||
```lua
|
- The inventory's unique id, or a table with the id and owner.
|
||||||
exports.ox_inventory:AddItem(1, 'bread', 4, nil, nil, function(success, reason)
|
- playerId: `1`, inventoryId: `gloveVGH283`, `{ id = 'personallocker', owner = 'license:xxxxxx'}`
|
||||||
if success then
|
- item: `string`
|
||||||
print(json.encode(reason, {indent=true}))
|
- The name of the item to add to the target.
|
||||||
--[[
|
- count: `number`
|
||||||
{
|
- The number of items to add.
|
||||||
"metadata": [],
|
- metadata?: `table` or `string`
|
||||||
"label": "Bread",
|
- A table of unique data to attach to the item object. A string will create a table with the "type" field.
|
||||||
"slot": 1,
|
- slot?: `number`
|
||||||
"stack": true,
|
- A specific slot to add the item to. If the slot is invalid, the first available slot will be used instead.
|
||||||
"close": true,
|
- cb?: function(success: `boolean`, response?: `string`)
|
||||||
"name": "bread",
|
|
||||||
"count": 1,
|
|
||||||
"weight": 150
|
|
||||||
}
|
|
||||||
]]
|
|
||||||
else
|
|
||||||
print(success)
|
|
||||||
-- nil
|
|
||||||
|
|
||||||
print(reason)
|
Returns `success, response` if cb is undefined, otherwise they are used in the callback only.
|
||||||
-- for example if all slots are taken it will give us "inventory_full"
|
|
||||||
end
|
**Example:**
|
||||||
end)
|
|
||||||
|
```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:**
|
**Possible value of the "response" argument, on failure:**
|
||||||
+ "invalid_item": the item doesn't exist
|
|
||||||
+ "invalid_inventory": the inventory doesn't exist
|
- "invalid_item": the item doesn't exist
|
||||||
+ "inventory_full": no free slots
|
- "invalid_inventory": the inventory doesn't exist
|
||||||
|
- "inventory_full": no free slots
|
||||||
@@ -1,16 +1,27 @@
|
|||||||
Removes the specified item from the specified inventory.
|
Removes the specified item from the specified inventory.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- inv: string or table
|
|
||||||
-- item: table or string
|
|
||||||
-- count: number
|
|
||||||
-- metadata: table or string (optional)
|
|
||||||
-- slot: number (optional)
|
|
||||||
exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot)
|
exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- 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 remove from the target.
|
||||||
|
- count: `number`
|
||||||
|
- The number of items to remove.
|
||||||
|
- metadata?: `table` or `string`
|
||||||
|
- Only remove items with matching metadata properties.
|
||||||
|
- slot?: `number`
|
||||||
|
- A specific slot to remove the item from. If the slot is invalid, the first available slot will be used instead.
|
||||||
|
- cb?: function(success: `boolean`, response?: `string`)
|
||||||
|
|
||||||
|
Returns `success` as a boolean, stating whether the item was successfully removed.
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Removes 1 water from the inventory
|
-- Removes 2 water from the glovebox for the given plate.
|
||||||
exports.ox_inventory:RemoveItem(source, 'water', 1)
|
local success = exports.ox_inventory:RemoveItem('gloveVGH283', 'water', 2)
|
||||||
```
|
```
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
---
|
||||||
|
title: Creating shops
|
||||||
|
---
|
||||||
|
|
||||||
|
import IconButton from '@site/src/components/IconButton'
|
||||||
|
import { BsGithub } from 'react-icons/bs'
|
||||||
|
|
||||||
|
Builtin hops are defined in [data/shops.lua](https://github.com/overextended/ox_inventory/blob/main/data/shops.lua), and more can be added here to benefit from the built-in markers or zones support.
|
||||||
|
|
||||||
|
## Shop definition
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
General = {
|
||||||
|
name = 'Shop',
|
||||||
|
blip = {
|
||||||
|
id = 59,
|
||||||
|
colour = 69,
|
||||||
|
scale = 0.8
|
||||||
|
},
|
||||||
|
inventory = {
|
||||||
|
{ name = 'burger', price = 10 },
|
||||||
|
{ name = 'water', price = 10 },
|
||||||
|
{ name = 'cola', price = 10 },
|
||||||
|
},
|
||||||
|
locations = {
|
||||||
|
vec3(25.7, -1347.3, 29.49),
|
||||||
|
},
|
||||||
|
targets = {
|
||||||
|
{
|
||||||
|
loc = vec3(25.06, -1347.32, 29.5),
|
||||||
|
length = 0.7,
|
||||||
|
width = 0.5,
|
||||||
|
heading = 0.0,
|
||||||
|
minZ = 29.5,
|
||||||
|
maxZ = 29.9,
|
||||||
|
distance = 1.5
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
luke i hate this pls fix
|
||||||
|
|
||||||
|
- name: `string`
|
||||||
|
- The label to display when the shop is open.
|
||||||
|
- blip?: `table`
|
||||||
|
- Creates a blip with the given settings. Leave it undefined for no blip to be created.
|
||||||
|
- groups?: `table`
|
||||||
|
- Key-value pairs of job name and minimum grade to access the shop.
|
||||||
|
- `{["police"] = 0, ["ambulance"] = 2}`
|
||||||
|
- inventory: `table`
|
||||||
|
- { name: `string`, price: `number`, currency?: `string`, count?: `number`, license?: `string`, metadata?: `table`, grade?: `number` }
|
||||||
|
- locations?: `vector3[]`
|
||||||
|
- An array of coordinates to create unique instances of the shop archetype at, using markers.
|
||||||
|
- targets?: `table[]`
|
||||||
|
- An array of BoxZone settings to create unique instances of the shop archetype at.
|
||||||
|
- model?: `number[]`
|
||||||
|
- An array of models that can be targetted to open a shop. Used for vending machines.
|
||||||
|
|
||||||
|
Targets and model are only available when using a targeting resource like ox_target.
|
||||||
|
|
||||||
|
## Register during runtime
|
||||||
|
|
||||||
|
Shops can be added using `exports.ox_inventory:RegisterShop` on the server, however they cannot utilise any client-only features.
|
||||||
|
- Blips, markers, and zones will not be created.
|
||||||
|
- Must use "locations" and not "targets" to define each shop using the archetype.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
```lua
|
||||||
|
exports.ox_inventory:RegisterShop('TestShop', {
|
||||||
|
name = 'Test shop',
|
||||||
|
inventory = {
|
||||||
|
{ name = 'burger', price = 10 },
|
||||||
|
{ name = 'water', price = 10 },
|
||||||
|
{ name = 'cola', price = 10 },
|
||||||
|
},
|
||||||
|
locations = {
|
||||||
|
vec3(223.832962, -792.619751, 30.695190),
|
||||||
|
},
|
||||||
|
groups = {
|
||||||
|
police = 0
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
Reference in new issue
Block a user