├── .editorconfig ├── README.md ├── client.lua ├── fxmanifest.lua └── server.lua /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = false 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | indent_size = 2 12 | indent_style = space 13 | 14 | [*.lua] 15 | indent_size = 4 16 | indent_style = tab -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Showcase some different functions for third-party integration of ox_inventory -------------------------------------------------------------------------------- /client.lua: -------------------------------------------------------------------------------- 1 | local ox_inventory = exports.ox_inventory 2 | 3 | RegisterCommand('policestash', function() 4 | ox_inventory:openInventory('stash', 'example_stash') 5 | end) 6 | 7 | RegisterCommand('ownedstash', function() 8 | ox_inventory:openInventory('stash', {id='example_stash_2', owner=1}) 9 | end) 10 | 11 | RegisterCommand('pstash', function(src, args) 12 | ox_inventory:openInventory('stash', {id='example_stash_3', owner=tonumber(args[1]) or 1}) 13 | end) 14 | 15 | RegisterCommand('lazystash', function() 16 | if ox_inventory:openInventory('stash', 'lazyStash') == false then 17 | TriggerServerEvent('ox:lazyStash') 18 | ox_inventory:openInventory('stash', 'lazyStash') 19 | end 20 | end) 21 | 22 | exports('testburger', function(data, slot) 23 | print(json.encode(slot, {indent=true})) 24 | ox_inventory:useItem(data, function(data) 25 | if data then 26 | print(json.encode(data, {indent=true})) 27 | ox_inventory:notify({text = 'You ate a delicious '..data.name}) 28 | end 29 | end) 30 | end) 31 | -------------------------------------------------------------------------------- /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | --[[ FX Information ]]-- 2 | fx_version 'cerulean' 3 | game 'gta5' 4 | 5 | --[[ Resource Information ]]-- 6 | name 'ox_test' 7 | author 'Linden' 8 | version '1.0.0' 9 | repository '' 10 | description '' 11 | 12 | --[[ Manifest ]]-- 13 | dependencies { 14 | '/onesync', 15 | } 16 | 17 | server_scripts { 18 | 'server.lua' 19 | } 20 | 21 | client_scripts { 22 | 'client.lua' 23 | } -------------------------------------------------------------------------------- /server.lua: -------------------------------------------------------------------------------- 1 | local GetCurrentResourceName = GetCurrentResourceName() 2 | local ox_inventory = exports.ox_inventory 3 | 4 | -- These stashes are all created on resource start 5 | local stashes = { 6 | { 7 | -- Police stash 8 | id = 'example_stash', 9 | label = 'Police Stash', 10 | slots = 50, 11 | weight = 100000, 12 | owner = false, 13 | jobs = 'police' 14 | }, 15 | { 16 | -- Owned stash 17 | id = 'example_stash_2', 18 | label = 'Stash', 19 | slots = 50, 20 | weight = 100000, 21 | owner = 'bobsmith', 22 | }, 23 | { 24 | -- Personal stashes 25 | id = 'example_stash_3', 26 | label = 'Stash', 27 | slots = 50, 28 | weight = 100000, 29 | owner = true, 30 | }, 31 | } 32 | 33 | AddEventHandler('onServerResourceStart', function(resourceName) 34 | if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName then 35 | for i=1, #stashes do 36 | local stash = stashes[i] 37 | ox_inventory:RegisterStash(stash.id, stash.label, stash.slots, stash.weight, stash.owner, stash.jobs) 38 | end 39 | end 40 | 41 | Wait(500) 42 | 43 | local inventory = ox_inventory:GetInventory({id = 'example_stash_3', owner = 115}) 44 | ox_inventory:AddItem(inventory.id, 'water', 1) 45 | end) 46 | 47 | -- Register this stash only when this event is called 48 | RegisterNetEvent('ox:lazyStash', function() 49 | ox_inventory:RegisterStash('lazyStash', 'Stash', 20, 20000, true) 50 | end) 51 | 52 | exports('testburger', function(event, item, inventory, slot, data) 53 | if event == 'usingItem' then 54 | if ox_inventory:GetItem(inventory, item, inventory.items[slot].metadata, true) > 0 then 55 | -- if we return false here, we can cancel item use 56 | return { 57 | inventory.label, event, 'external item use poggies' 58 | } 59 | end 60 | 61 | elseif event == 'usedItem' then 62 | print(('%s just ate a %s from slot %s'):format(inventory.label, item.label, slot)) 63 | 64 | elseif event == 'buying' then 65 | print(data.id, data.coords, json.encode(data.items[slot], {indent=true})) 66 | end 67 | end) --------------------------------------------------------------------------------