This commit is contained in:
Luke committed 2023-06-04 15:15:21 +02:00
1 parent 3cebaf7fa5
commit b5eba8423f
229 files changed
+6238 -10690

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
---
title: Creating crafting points
---
Crafting locations, items and their ingredients are defined in [data/crafting.lua](https://github.com/overextended/ox_inventory/blob/main/data/crafting.lua).
## Crafting definition
```lua
{
items = {
{
name = 'lockpick',
ingredients = {
garbage = 3,
WEAPON_HAMMER = 0.1
},
duration = 5000,
count = 3,
metadata = { durability = 20 }
},
{
name = 'garbage',
ingredients = {
cola = 1
},
metadata = { description = 'An empty soda can.', weight = 20, image = 'trash_can' }
},
},
points = {
vec3(-1147.083008, -2002.662109, 13.180260),
},
zones = {
{
coords = vec3(-1146.2, -2002.05, 13.2),
size = vec3(3.8, 1.05, 0.15),
distance = 1.5,
rotation = 315.0,
},
},
blip = { id = 566, colour = 31, scale = 0.8 },
},
```
* items: `table`
* name: `string`
* ingredients: `table`
* Item ingredients can be seen in the item tooltip.
* Key-value pairs of item name and consume count
* key - Item name.
* value - If 1 or above it's the consume count, if below 1 and above 0 it's the durability consume amount, if
set to 0 then the item is required but not consumed.
* duration: `number`
* Crafting duration in milliseconds.
* count: `number`
* Item amount received upon crafting.
* metadata: `table`
* Metadata applied to the item being crafted.
* points: `vector3[]`
* Interaction locations that will open the crafting inventory.
* groups: `table`
* Key-value pairs of job name and minimum grade to access the crafting location.
* `{["police"] = 0, ["ambulance"] = 2}`
* zones: `table`
* ox_lib targeting zones used for ox_target.
* coords: `vector3`
* size: `vector3`
* distance: `number`
* rotation: `number`
* blip: `table`
* id: `number`
* Blip sprite number.
* colour: `number`
* scale: `number`
+265
View File
@@ -0,0 +1,265 @@
---
title: Creating items
---
import { Tabs, Tab } from 'nextra-theme-docs';
## Defining item data
Before being able to see or use an item in game it **must** first be defined.
All of the items are defined in the `/data/items.lua` file with key, value pairs.
Key is the name (not the label) of an item and the value is a table containing the
options for the item.
**Item options:**
* label: `string`
* weight?: `number`
* stack?: `boolean`
* If set to false will not allow the item to be stacked.
* degrade?: `number`
* Amount of time in minutes the item will degrade after.
* close?: `boolean`
* If set to false does not close the inventory on item use.
* description?: `string`
* Item description that will be shown in the tooltip
* consume?: `number`
* Item count needed and removed use.
* Default: 1
* If set to a decimal will consume durability instead (0.2 = 20%).
* allowArmed?: `boolean`
* If set to true will allow use of item while armed with a weapon.
* server?: `table`
* export?: `string`
* client?: `table`
* export?: `string`
* Export to be triggered after item use.
* event?: `string`
* Event to be triggered after item use.
* status?: `table`
* Adjust esx_status values after use.
* anim?: `table`
* Animation that will be played during the progress bar.
* dict: `string`
* clip: `string`
* prop?: `table`
* Attached prop that will be displayed during the progress bar.
* model: `string` or `hash`
* pos: `table` (x, y, z)
* rot: `table` (x, y, z)
* disable?: `table`
* Actions to be disabled during the progress bar
* move?: `boolean`
* car?: `boolean`
* combat?: `boolean`
* mouse?: `boolean`
* usetime?: `number`
* cancel?: `boolean`
* If set to true the player canc cancel item use.
* add?: `function`(total: `number`)
* Function that triggers when receiving an item
* Returns total item count as `total`
* remove?: `function`(total: `number`)
* Function that triggers when removing an item
* Returns total item count as `total`
* buttons?: `table`
* label: `string`
* action: `function`(slot: `number`)
* Callback function when button is clicked in context menu, returns item slot.
**Examples:**
<Tabs items={["Burger", "Burger with description", "Burger with notification"]}>
<Tab>
```lua
['burger'] = {
label = 'Burger',
weight = 220,
stack = true,
close = true,
client = {
status = { hunger = 200000 },
anim = { dict = 'mp_player_inteat@burger', clip = 'mp_player_int_eat_burger_fp' },
prop = {
model = 'prop_cs_burger_01',
pos = { x = 0.02, y = 0.02, y = -0.02},
rot = { x = 0.0, y = 0.0, y = 0.0}
},
usetime = 2500,
}
}
```
</Tab>
<Tab>
A modified burger item which includes a description.
```lua
['burger'] = {
label = 'Burger',
description = 'Just what is the secret formula?'
weight = 220,
stack = true,
close = true,
client = {
status = { hunger = 200000 },
anim = { dict = 'mp_player_inteat@burger', clip = 'mp_player_int_eat_burger_fp' },
prop = {
model = 'prop_cs_burger_01',
pos = { x = 0.02, y = 0.02, y = -0.02},
rot = { x = 0.0, y = 0.0, y = 0.0}
},
usetime = 2500,
}
}
```
</Tab>
<Tab>
A modified burger item, which gives you notifications on add and remove arguments.
```lua
['burger'] = {
label = 'Burger',
weight = 220,
stack = true,
consume = 0,
client = {
add = function(total)
if total > 0 then
lib.notify({description = 'Nice burger you got there!'})
end
end,
remove = function(total)
if total < 1 then
lib.notify({description = 'You lost all of your burgers!'})
end
end
}
}
```
</Tab>
</Tabs>
## Making the item usable
* If you are using ESX, you can continue using `ESX.RegisterUsableItem`.
* If you are using QBCore, you can continue using `QBCore.Functions.CreateUseableItem`.
Using the built-in system is more secure and provides much more functionality.
### Client callbacks
Item callbacks can be added by defining an export (recommended), or by adding it to [items/client.lua](https://github.com/overextended/ox_inventory/blob/main/modules/items/client.lua#L33).
When defining [item data](https://github.com/overextended/ox_inventory/blob/main/data/items.lua#L11), adding client.export will trigger an event on item use.
The correct formatting is `export = resourceName.exportName`.
```lua
exports('bandage', function(data, slot)
local playerPed = PlayerPedId()
local maxHealth = GetEntityMaxHealth(playerPed)
local health = GetEntityHealth(playerPed)
-- Does the ped need to heal? We can cancel the item from being used.
if health < maxHealth then
-- Triggers internal-code to correctly use items.
-- This adds security, removes the item on use, adds progressbar support, and is necessary for server callbacks.
exports.ox_inventory:useItem(data, function(data)
-- The server has verified the item can be used.
if data then
SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16)))
lib.notify({description = 'You feel better already'})
end
end)
else
-- Don't use the item
lib.notify({type = 'error', description = 'You don\'t need a bandage right now'})
end
end)
```
### Server callbacks
A callback function can be defined on the server to handle several events (usingItem, usedItem, buyItem).
This can either be an export (recommended), or added to the bottom of [items/server.lua](https://github.com/overextended/ox_inventory/blob/main/modules/items/server.lua).
When defining [item data](https://github.com/overextended/ox_inventory/blob/main/data/items.lua#L14), adding server.export will trigger an event for the actions above.
The correct formatting is `export = resourceName.exportName`.
```lua
exports('bandage', function(event, item, inventory, slot, data)
-- Player is attempting to use the item.
if event == 'usingItem' then
local playerPed = GetPlayerPed(inventory.id)
local maxHealth = GetEntityMaxHealth(playerPed)
local health = GetEntityHealth(playerPed)
-- Check if the player needs to be healed.
if health >= maxHealth then
TriggerClientEvent('ox_lib:notify', inventory.id, {type = 'error', description = 'You don\'t need a bandage right now'})
-- Returning 'false' will prevent the item from being used
return false
end
return
end
-- Player has finished using the item.
if event == 'usedItem' then
return TriggerClientEvent('ox_lib:notify', inventory.id, {description = 'You feel better already'})
end
-- Player is attempting to purchase the item.
if event == 'buying' then
return TriggerClientEvent('ox_lib:notify', inventory.id, {type = 'success', description = 'You bought a bandage'})
end
end)
```
## Creating container items
Like with other items the item must first be registered.
**Example:**
```lua
['paperbag'] = {
label = 'Paper Bag',
weight = 1,
stack = false,
close = false,
consume = 0
},
```
When registered you can define the item as a container in `/modules/items/containers.lua`
The key for the container is the `name` you gave it when registering the item.
You can also define the number of slots, the maximum weight, blacklist and whitelist items.
* itemName:
* slots: number
* The number represents the amount of slots
* maxWeight: number
* The number represents the maximum weight within the container
* blacklist:
* Supports single and multiple items
* `{ 'testburger', 'testburger2' }`
* whitelist:
* Supports single and multiple items
* `{ 'testburger', 'testburger2' }`
**Example:**
```lua
setContainerProperties('paperbag', {
slots = 5,
maxWeight = 1000,
blacklist = { 'testburger' }
})
```
+104
View File
@@ -0,0 +1,104 @@
---
title: Creating shops
---
Builtin shops 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 = {
-- Shop using a BoxZone
{
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
},
-- Shop using a ped
{
ped = `mp_m_shopkeep_01`,
scenario = 'WORLD_HUMAN_AA_COFFEE',
loc = vec3(24.407, -1347.283, 28.497),
heading = 270.311,
},
}
}
}
```
- 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.
- id: `number`
- colour: `number`
- scale: `number`
- 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`
- Item to be used as currency.
- count?: `number`
- Amount of the item in the stock.
- license?: `string`
- License required to purchase the item.
- metadata?: `table`
- grade?: `number` | `number[]`
- Grade required to purchase the item.
- locations?: `vector3[]`
- An array of coordinates to create unique instances of the shop archetype at, using markers.
- targets?: `table[]`
- An array of target settings to create unique instances of the shop archetype at, using peds or BoxZones (PolyZone data structure).
- 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
},
})
```
+88
View File
@@ -0,0 +1,88 @@
---
title: Creating custom stashes
---
import { GhButton } from '@components/button';
We can set up custom stashes from outside the resource utilising the exported RegisterStash function.
Firstly, we need to define the stashes properties.
### Stash properties
- id: `string`
- Unique name to identify the stash in the database.
- label: `string`
- Display name when viewing the stash.
- slots: `number`
- Number of slots the stash will have.
- weight: `number`
- Maximum weight of the stash inventory.
- owner?: `string` or `boolean`
- `true`: Each player has their own unique stash, but can request to open the stash of another player
- `false`: Only a single stash exists and is shared between all players
- `string`: The stash explicitly belongs to the given owner, usually a player identifier
- groups?: `table`
- Key-value pairs of job name and minimum grade to be able to access the stash. (`{["police"] = 0, ["ambulance"] = 2}`)
- name: `string`
- grade: `number`
- coords?: `vector3` or `table`
- You can set the stash coordinates to prevent the stash from being opened if the player isn't close enough.
- Vector or table containing the coordinates of the stash.
## Example
Below the value is hardset, but it could be loaded from the database (especially if there are unknown fields, i.e. owner)
```lua
-- Server
local stash = {
id = '42wallabyway',
label = '42 Wallaby Way',
slots = 50,
weight = 100000,
owner = 'char1:license'
}
AddEventHandler('onServerResourceStart', function(resourceName)
if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName() then
exports.ox_inventory:RegisterStash(stash.id, stash.label, stash.slots, stash.weight, stash.owner)
end
end)
-- Client
exports.ox_inventory:openInventory('stash', {id='42wallabyway', owner=property.owner})
```
The following sample is based on esx_property's db data.
```lua
-- Server
local properties
MySQL.query('SELECT * FROM `properties`', {}, function(result)
properties = result
end
RegisterNetEvent('ox:loadStashes', function(id)
local stash = properties[id]
if stash then
-- id: 1, name: WhispymoundDrive, label: 2677 Whispymound Drive, coords: {"x":118.748,"y":566.573,"z":175.697}
ox_inventory:RegisterStash(stash.name, stash.label, 50, 100000, true, false, json.encode(stash.room_menu))
end
end)
-- Client
local ox_inventory = exports.ox_inventory
if ox_inventory:openInventory('stash', property.id) == false then
TriggerServerEvent('ox:loadStashes')
ox_inventory:openInventory('stash', property.id)
end
```
## Example resource
We put together an example resource showcasing how to properly utilise the stash API:
<GhButton link="https://www.github.com/overextended/ox_inventory_examples" />