mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
1 line
8.1 KiB
JavaScript
1 line
8.1 KiB
JavaScript
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9414],{3905:function(e,t,n){n.d(t,{Zo:function(){return p},kt:function(){return m}});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),u=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=u(e.components);return r.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},c=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),c=u(n),m=a,h=c["".concat(s,".").concat(m)]||c[m]||d[m]||o;return n?r.createElement(h,l(l({ref:t},p),{},{components:n})):r.createElement(h,l({ref:t},p))}));function m(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,l=new Array(o);l[0]=c;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i.mdxType="string"==typeof e?e:a,l[1]=i;for(var u=2;u<o;u++)l[u]=n[u];return r.createElement.apply(null,l)}return r.createElement.apply(null,n)}c.displayName="MDXCreateElement"},3528:function(e,t,n){n.r(t),n.d(t,{frontMatter:function(){return i},contentTitle:function(){return s},metadata:function(){return u},assets:function(){return p},toc:function(){return d},default:function(){return m}});var r=n(7462),a=n(3366),o=(n(7294),n(3905)),l=["components"],i={title:"Creating custom stashes"},s=void 0,u={unversionedId:"ox_inventory/Guides/stashes",id:"ox_inventory/Guides/stashes",title:"Creating custom stashes",description:"We can set up custom stashes from outside the resource utilising the exported RegisterStash function. Firstly, we need to define the stashes properties.",source:"@site/docs/ox_inventory/Guides/stashes.md",sourceDirName:"ox_inventory/Guides",slug:"/ox_inventory/Guides/stashes",permalink:"/docs/ox_inventory/Guides/stashes",editUrl:"https://github.com/overextended/overextended.github.io/tree/main/docs/ox_inventory/Guides/stashes.md",tags:[],version:"current",frontMatter:{title:"Creating custom stashes"},sidebar:"docs",previous:{title:"Building inventory UI",permalink:"/docs/ox_inventory/Guides/inventory_ui"},next:{title:"Items",permalink:"/docs/ox_inventory/Functions/External/Client/Items"}},p={},d=[{value:"Example",id:"example",level:2}],c={toc:d};function m(e){var t=e.components,n=(0,a.Z)(e,l);return(0,o.kt)("wrapper",(0,r.Z)({},c,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"We can set up custom stashes from outside the resource utilising the exported RegisterStash function. Firstly, we need to define the stashes properties. "),(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Argument"),(0,o.kt)("th",{parentName:"tr",align:null},"Type"),(0,o.kt)("th",{parentName:"tr",align:null},"Optional"),(0,o.kt)("th",{parentName:"tr",align:null},"Explanation"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"id"),(0,o.kt)("td",{parentName:"tr",align:null},"string"),(0,o.kt)("td",{parentName:"tr",align:null},"no"),(0,o.kt)("td",{parentName:"tr",align:null},"A unique name to identify the stash in the database")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"label"),(0,o.kt)("td",{parentName:"tr",align:null},"string"),(0,o.kt)("td",{parentName:"tr",align:null},"no"),(0,o.kt)("td",{parentName:"tr",align:null},"A display name when viewing the inventory")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"slots"),(0,o.kt)("td",{parentName:"tr",align:null},"integer"),(0,o.kt)("td",{parentName:"tr",align:null},"no"),(0,o.kt)("td",{parentName:"tr",align:null},"Number of slots")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"weight"),(0,o.kt)("td",{parentName:"tr",align:null},"integer"),(0,o.kt)("td",{parentName:"tr",align:null},"no"),(0,o.kt)("td",{parentName:"tr",align:null},"Maximum weight")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"owner"),(0,o.kt)("td",{parentName:"tr",align:null},"str/bool"),(0,o.kt)("td",{parentName:"tr",align:null},"yes"),(0,o.kt)("td",{parentName:"tr",align:null},"See below")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"job"),(0,o.kt)("td",{parentName:"tr",align:null},"table"),(0,o.kt)("td",{parentName:"tr",align:null},"yes"),(0,o.kt)("td",{parentName:"tr",align:null},"Key-value pairs of job name and minimum grade to access")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"coords"),(0,o.kt)("td",{parentName:"tr",align:null},"vector"),(0,o.kt)("td",{parentName:"tr",align:null},"yes"),(0,o.kt)("td",{parentName:"tr",align:null},"A vector (or table) containing x, y, z coordinates")))),(0,o.kt)("p",null,"The owner field will set permissions for stash access, with stashes registering to specific identifiers."),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"true: Each player has their own unique stash, but can request to open the stash of another player"),(0,o.kt)("li",{parentName:"ul"},"false: Only a single stash exists and is shared between all players"),(0,o.kt)("li",{parentName:"ul"},"string: The stash explicitly belongs to the given owner, usually a player identifier")),(0,o.kt)("p",null,"You can set the stash coordinates to prevent the stash from being opened if the player isn't close enough."),(0,o.kt)("h2",{id:"example"},"Example"),(0,o.kt)("p",null,"Below the value is hardset, but it could be loaded from the database (especially if there are unknown fields, i.e. owner)"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-lua"},"-- Server\nlocal stash = {\n id = '42wallabyway',\n label = '42 Wallaby Way',\n slots = 50,\n weight = 100000,\n owner = 'char1:license'\n}\n\nAddEventHandler('onServerResourceStart', function(resourceName)\n if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName() then\n exports.ox_inventory:RegisterStash(stash.id, stash.label, stash.slots, stash.weight, stash.owner)\n end\nend)\n\n-- Client\nexports.ox_inventory:openInventory('stash', {id='42wallabyway', owner=property.owner})\n")),(0,o.kt)("p",null,"The following sample is based on esx_property's db data."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-lua"},"-- Server\nlocal properties\n\nMySQL.query('SELECT * FROM `properties`', {}, function(result)\n properties = result\nend\n\nRegisterNetEvent('ox:loadStashes', function(id)\nlocal stash = properties[id]\n if stash then\n -- id: 1, name: WhispymoundDrive, label: 2677 Whispymound Drive, coords: {\"x\":118.748,\"y\":566.573,\"z\":175.697}\n ox_inventory:RegisterStash(stash.name, stash.label, 50, 100000, true, false, json.encode(stash.room_menu))\n end\nend)\n\n-- Client\nlocal ox_inventory = exports.ox_inventory\n\nif ox_inventory:openInventory('stash', property.id) == false then\n TriggerServerEvent('ox:loadStashes')\n ox_inventory:openInventory('stash', property.id)\nend\n")))}m.isMDXComponent=!0}}]); |