From 6470d98a9d2dd99d7c112735f2456c98817b45da Mon Sep 17 00:00:00 2001 From: N-fire <55892717+N-fire@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:09:13 +0100 Subject: [PATCH] import inventory guides --- docs/ox_inventory/Guides/index.md | 10 ++++ docs/ox_inventory/Guides/inventory_ui.md | 33 ++++++++++ docs/ox_inventory/Guides/placeholder.md | 3 - docs/ox_inventory/Guides/stashes.md | 76 ++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 docs/ox_inventory/Guides/index.md create mode 100644 docs/ox_inventory/Guides/inventory_ui.md delete mode 100644 docs/ox_inventory/Guides/placeholder.md create mode 100644 docs/ox_inventory/Guides/stashes.md diff --git a/docs/ox_inventory/Guides/index.md b/docs/ox_inventory/Guides/index.md new file mode 100644 index 00000000..c87c91df --- /dev/null +++ b/docs/ox_inventory/Guides/index.md @@ -0,0 +1,10 @@ +--- +title: Overview +--- + +:::info + +Providing examples and explaining certain inventory API into more detail. + +If you have trouble understanding how some of the API works check out our [___example resource___](https://github.com/overextended/ox_inventory_examples). +::: \ No newline at end of file diff --git a/docs/ox_inventory/Guides/inventory_ui.md b/docs/ox_inventory/Guides/inventory_ui.md new file mode 100644 index 00000000..ec43ee20 --- /dev/null +++ b/docs/ox_inventory/Guides/inventory_ui.md @@ -0,0 +1,33 @@ +--- +title: Building inventory UI +--- + +:::info Requirements to build: + +* Node.js +* Yarn +::: +:::info Installing Node.js: + +* Download the LTS version of Node.js from [___here___](https://www.nodejs.org). +* Go through the install and make sure you install all of the features. +* Run node --version in cmd and make sure that it gives you the version number. If it doesn't then you didn't install it correctly. +::: + +:::info Installing Yarn: + +* Now that you've installed Node.js you can install Yarn by running `npm install --global yarn` in cmd. +::: +:::info Building the inventory UI: + +* cd into the web directory of ox_inventory +* In your cmd type `yarn` and in will start downloading the node modules. +* After it's done downloading node modules you can run `yarn build` to build the UI. +::: +:::tip Hot reloads +When working in the browser you can run `yarn start`, which supports hot reloads meaning that +you will see your changes after saving your file. + +If you want to work in game you can run `yarn start:game` which writes changes to disk, so +the only thing you have to do is restart the resource for it take affect. +::: \ No newline at end of file diff --git a/docs/ox_inventory/Guides/placeholder.md b/docs/ox_inventory/Guides/placeholder.md deleted file mode 100644 index 458256c8..00000000 --- a/docs/ox_inventory/Guides/placeholder.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: Placeholder ---- \ No newline at end of file diff --git a/docs/ox_inventory/Guides/stashes.md b/docs/ox_inventory/Guides/stashes.md new file mode 100644 index 00000000..712259f7 --- /dev/null +++ b/docs/ox_inventory/Guides/stashes.md @@ -0,0 +1,76 @@ +--- +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 + +| Argument | Type | Optional | Explanation | +---------- | -------- | -------- | ----------- | +id | string | no | A unique name to identify the stash in the database | +label | string | no | A display name when viewing the inventory | +slots | integer | no | Number of slots | +weight | integer | no | Maximum weight | +owner | str/bool | yes | See below | +job | table | yes | Key-value pairs of job name and minimum grade to access | +coords | vector | yes | A vector (or table) containing x, y, z coordinates | + +The owner field will set permissions for stash access, with stashes registering to specific identifiers. +- 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 + +You can set the stash coordinates to prevent the stash from being opened if the player isn't close enough. +::: + +## 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 +Wait(0) +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 +if ox_inventory:openInventory('stash', property.id) == false then +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)