mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-03 06:28:53 +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,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" />
|
||||
Reference in new issue
Block a user