From 0a351cc450e1ba914b686354f1aa13a3e04aaa22 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 4 Mar 2022 10:12:37 +1100 Subject: [PATCH] Minor formatting change to stash guide --- docs/ox_inventory/Guides/stashes.md | 43 +++++++++++++---------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/docs/ox_inventory/Guides/stashes.md b/docs/ox_inventory/Guides/stashes.md index 712259f7..c2210e2b 100644 --- a/docs/ox_inventory/Guides/stashes.md +++ b/docs/ox_inventory/Guides/stashes.md @@ -2,9 +2,7 @@ title: Creating custom stashes --- -We can set up custom stashes from outside the resource utilising the exported RegisterStash function. Firstly, we need to define the stashes properties. - -:::info +We can set up custom stashes from outside the resource utilising the exported RegisterStash function. Firstly, we need to define the stashes properties. | Argument | Type | Optional | Explanation | ---------- | -------- | -------- | ----------- | @@ -22,26 +20,24 @@ The owner field will set permissions for stash access, with stashes registering - string: The stash explicitly belongs to the given owner, usually a player identifier You can set the stash coordinates to prevent the stash from being opened if the player isn't close enough. -::: -## Example ## +## 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' + 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 -Wait(0) -exports.ox_inventory:RegisterStash(stash.id, stash.label, stash.slots, stash.weight, stash.owner) -end + 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 @@ -54,23 +50,22 @@ The following sample is based on esx_property's db data. local properties MySQL.query('SELECT * FROM `properties`', {}, function(result) -properties = 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 + 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) + TriggerServerEvent('ox:loadStashes') + ox_inventory:openInventory('stash', property.id) end ``` -For our actual implementation of esx_property support, you can refer to these files: -- [client](https://github.com/overextended/esx-legacy/blob/main/%5Besx_addons%5D/esx_property/client/main.lua#L588-L619) -- [server](https://github.com/overextended/esx-legacy/blob/main/[esx_addons]/esx_property/server/main.lua#L62-L151)