From 77666c92fb8e3b55b7438548e17de3d3352d9bdd Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Thu, 8 Jun 2023 22:32:30 +0200 Subject: [PATCH] move inventory functions into single file --- pages/ox_inventory/Functions/Client.mdx | 475 ++++++++++ .../Client/Inventory/GetItemCount.mdx | 16 - .../Client/Inventory/GetPlayerItems.mdx | 7 - .../Client/Inventory/GetPlayerMaxWeight.mdx | 7 - .../Client/Inventory/GetPlayerWeight.mdx | 7 - .../Client/Inventory/GetSlotIdWithItem.mdx | 12 - .../Client/Inventory/GetSlotIdsWithItem.mdx | 12 - .../Client/Inventory/GetSlotWithItem.mdx | 12 - .../Client/Inventory/GetSlotsWithItem.mdx | 12 - .../Functions/Client/Inventory/Search.mdx | 84 -- pages/ox_inventory/Functions/Client/Items.mdx | 15 - .../Functions/Client/Statebags/invBusy.mdx | 17 - .../Functions/Client/Statebags/invHotkeys.mdx | 15 - .../Functions/Client/Statebags/invOpen.mdx | 16 - .../Functions/Client/Utils/weaponWheel.mdx | 9 - .../Functions/Client/closeInventory.mdx | 5 - .../Functions/Client/displayMetadata.mdx | 24 - .../Functions/Client/getCurrentWeapon.mdx | 28 - .../Functions/Client/openInventory.mdx | 61 -- .../Functions/Client/openNearbyInventory.mdx | 9 - .../Functions/Client/setStashTarget.mdx | 15 - .../ox_inventory/Functions/Client/useItem.mdx | 32 - .../ox_inventory/Functions/Client/useSlot.mdx | 7 - pages/ox_inventory/Functions/Server.mdx | 883 ++++++++++++++++++ .../Functions/Server/Inventory/AddItem.mdx | 57 -- .../Server/Inventory/CanCarryAmount.mdx | 18 - .../Server/Inventory/CanCarryItem.mdx | 25 - .../Server/Inventory/CanCarryWeight.mdx | 26 - .../Server/Inventory/CanSwapItem.mdx | 11 - .../Server/Inventory/ClearInventory.mdx | 8 - .../Server/Inventory/ConfiscateInventory.mdx | 10 - .../Server/Inventory/ConvertItems.mdx | 16 - .../Server/Inventory/CreateDropFromPlayer.mdx | 18 - .../Server/Inventory/CreateTemporaryStash.mdx | 43 - .../Functions/Server/Inventory/CustomDrop.mdx | 30 - .../Server/Inventory/GetContainerFromSlot.mdx | 10 - .../Server/Inventory/GetCurrentWeapon.mdx | 8 - .../Server/Inventory/GetEmptySlot.mdx | 9 - .../Server/Inventory/GetInventory.mdx | 27 - .../Server/Inventory/GetInventoryItems.mdx | 14 - .../Functions/Server/Inventory/GetItem.mdx | 36 - .../Server/Inventory/GetItemCount.mdx | 13 - .../Server/Inventory/GetItemSlots.mdx | 9 - .../Functions/Server/Inventory/GetSlot.mdx | 29 - .../Server/Inventory/GetSlotForItem.mdx | 11 - .../Server/Inventory/GetSlotIdWithItem.mdx | 13 - .../Server/Inventory/GetSlotIdsWithItem.mdx | 13 - .../Server/Inventory/GetSlotWithItem.mdx | 13 - .../Server/Inventory/GetSlotsWithItem.mdx | 13 - .../Server/Inventory/RegisterStash.mdx | 33 - .../Functions/Server/Inventory/RemoveItem.mdx | 35 - .../Server/Inventory/ReturnInventory.mdx | 9 - .../Functions/Server/Inventory/Search.mdx | 13 - .../Server/Inventory/SetDurability.mdx | 27 - .../Server/Inventory/SetMaxWeight.mdx | 17 - .../Server/Inventory/SetMetadata.mdx | 27 - .../Server/Inventory/SetSlotCount.mdx | 17 - .../Functions/Server/Inventory/SwapSlots.mdx | 10 - pages/ox_inventory/Functions/Server/Items.mdx | 20 - .../Functions/Server/UpdateVehicle.mdx | 10 - .../Functions/Server/forceOpenInventory.mdx | 60 -- .../Functions/Server/setPlayerInventory.mdx | 15 - pages/ox_inventory/Guides/crafting.mdx | 60 +- pages/ox_inventory/Guides/stashes.mdx | 2 +- 64 files changed, 1389 insertions(+), 1226 deletions(-) create mode 100644 pages/ox_inventory/Functions/Client.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetItemCount.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetPlayerItems.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetPlayerMaxWeight.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetPlayerWeight.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetSlotIdWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetSlotIdsWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetSlotWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/GetSlotsWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Inventory/Search.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Items.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Statebags/invBusy.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Statebags/invHotkeys.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Statebags/invOpen.mdx delete mode 100644 pages/ox_inventory/Functions/Client/Utils/weaponWheel.mdx delete mode 100644 pages/ox_inventory/Functions/Client/closeInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Client/displayMetadata.mdx delete mode 100644 pages/ox_inventory/Functions/Client/getCurrentWeapon.mdx delete mode 100644 pages/ox_inventory/Functions/Client/openInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Client/openNearbyInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Client/setStashTarget.mdx delete mode 100644 pages/ox_inventory/Functions/Client/useItem.mdx delete mode 100644 pages/ox_inventory/Functions/Client/useSlot.mdx create mode 100644 pages/ox_inventory/Functions/Server.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/AddItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CanCarryAmount.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CanCarryItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CanCarryWeight.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CanSwapItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/ClearInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/ConvertItems.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CreateDropFromPlayer.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CreateTemporaryStash.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/CustomDrop.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetContainerFromSlot.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetEmptySlot.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetInventoryItems.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetItemCount.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetItemSlots.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetSlot.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetSlotForItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetSlotIdWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetSlotIdsWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetSlotWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/GetSlotsWithItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/RegisterStash.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/RemoveItem.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/ReturnInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/Search.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/SetDurability.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/SetMaxWeight.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/SetMetadata.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/SetSlotCount.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Inventory/SwapSlots.mdx delete mode 100644 pages/ox_inventory/Functions/Server/Items.mdx delete mode 100644 pages/ox_inventory/Functions/Server/UpdateVehicle.mdx delete mode 100644 pages/ox_inventory/Functions/Server/forceOpenInventory.mdx delete mode 100644 pages/ox_inventory/Functions/Server/setPlayerInventory.mdx diff --git a/pages/ox_inventory/Functions/Client.mdx b/pages/ox_inventory/Functions/Client.mdx new file mode 100644 index 00000000..8dc5bd20 --- /dev/null +++ b/pages/ox_inventory/Functions/Client.mdx @@ -0,0 +1,475 @@ +import { Tabs, Tab } from 'nextra-theme-docs'; + +## openInventory + +Opens an inventory using the passed data. + +```lua +exports.ox_inventory:openInventory(invType, data) +``` + +- invType: `string` + - `'player'` + - `'shop'` + - `'stash'` + - `'crafting'` + - `'container'` + - `'drop'` + - `'glovebox'` + - `'trunk'` + - `'dumpster'` +- data: `number` or `string` or `table` + + + + +**Open the target player's inventory.** + +```lua +exports.ox_inventory:openInventory('player', 3) +``` + + + + +**Open the fourth "General Store" [location](https://github.com/overextended/ox_inventory/blob/main/data/shops.lua#L14).** + +```lua +exports.ox_inventory:openInventory('shop', { type = 'General', id = 4 }) +``` + + + + +**Open the first stash in [data/stashes](https://github.com/overextended/ox_inventory/blob/main/data/stashes.lua#L2-L19).** + +```lua +exports.ox_inventory:openInventory('stash', 1) +``` + +**Open a custom stash (created on the server with RegisterStash).** + +```lua +exports.ox_inventory:openInventory('stash', 'society_police') +``` + +**Open a stash with a specific owner.** + +```lua +exports.ox_inventory:openInventory('stash', { id = 'police_locker', owner = 'license:xxxxxxxx' }) +``` + + + + +## openNearbyInventory + +If possible opens the nearby player's inventory. + +The player trying to open the inventory must be able to open their own and +if the player does not have a police job, the target player must be fatally injured or +playing one of the death anims. + +```lua +exports.ox_inventory:openNearbyInventory() +``` + +## closeInventory + +Closes the player's inventory. + +```lua +exports.ox_inventory:closeInventory() +``` + +## Items + +Returns a table of all registered items. The format is as defined in [data/items.lua](https://github.com/overextended/ox_inventory/blob/main/data/items.lua). + +```lua +exports.ox_inventory:Items() +``` + +The following snippet can be used in crafting resources such as okokCrafting or core_crafting, rather than retrieving information from the server. + +```lua +local itemNames = {} + +for item, data in pairs(exports.ox_inventory:Items()) do + itemNames[item] = data.label +end +``` + +## useItem + +Uses the passed item, then triggers the callback function. +Should be calling during item callbacks to utilise the builtin methods (server checks, progress bar, etc.). + +```lua +exports.ox_inventory:useItem(data, cb) +``` + +- data: `table` +- cb?: `function` + +```lua +exports('bandage', function(data, slot) + local playerPed = PlayerPedId() + local maxHealth = GetEntityMaxHealth(playerPed) + local health = GetEntityHealth(playerPed) + + -- Does the ped need to heal? + if health < maxHealth then + -- Use the bandage + exports.ox_inventory:useItem(data, function(data) + -- The item has been used, so trigger the effects + if data then + SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16))) + lib.notify({description = 'You feel better already'}) + end + end) + else + -- Don't use the item + lib.notify({type = 'error', description = 'You don\'t need a bandage right now'}) + end +end) +``` + +## useSlot + +Uses the item in the given inventory slot. + +```lua +exports.ox_inventory:useSlot(slot) +``` + +- slot: `number` + +## setStashTarget + +Forces the secondary-inventory key to open the passed inventory. Can be useful to enable inventory access while standing inside a marker. + +```lua +exports.ox_inventory:setStashTarget(id, owner) +``` + +- id: `string` or `number` + - Stash id. +- owner?: `string` or `number` + +**Example:** + +```lua +exports.ox_inventory:setStashTarget('motel5', 'bobsmith') +``` + +## getCurrentWeapon + +Get data for the currently equipped weapon. + +```lua +exports.ox_inventory:getCurrentWeapon() +``` + +You can also listen for changes to the current weapon using an event handler. + +```lua +AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon) + CurrentWeapon = currentWeapon +end) +``` + +- currentWeapon?: `table` + - ammo?: `string` Name of the item used as ammo. + - hash: `number` + - label: `string` + - melee: `boolean` + - metadata: `table` + - ammo?: `number` Amount of ammo loaded into the weapon. + - components?: `table` Array of component item names, used to apply weapon components. + - durability?: `number` + - registered?: `string` Name of the player that bought the weapon at a shop. + - serial?: `string` + - name: `string` Name of the item. + - slot: `number` + - weight: `number` + +## displayMetadata + +Sets a metadata property to display in the tooltip. + +```lua +exports.ox_inventory:displayMetadata(metadata, value) +``` + +- metadata: `table` or `string` + - If metadata is a string then it's the metadata property you want to display, value is **not** optional then. + - Can be a table of key-value pairs, key being the metadata property and value being the label for that property. +- value?: `string` + - Label for the string metadata property to be displayed. + +**Example:** + +```lua +exports.ox_inventory:displayMetadata('mustard', 'Mustard') +``` + +```lua +exports.ox_inventory:displayMetadata({ + mustard = 'Mustard', + ketchup = 'Ketchup' +}) +``` + +## weaponWheel + +Enables the weapon wheel, but disables the use of inventory items. + +Mostly used for weaponised vehicles, though could be called for "minigames" + +```lua +local exports.ox_inventory:weaponWheel(state) +``` + +- state: `boolean` + +## Search + +Searches the inventory for an item, or list of items, with the result varying based on the first argument. + +```lua +exports.ox_inventory:Search(search, item, metadata) +``` + +- search: `'slots'` or `'count'` + - `'slots'` returns a table of slots where the item was found at. + - `'count'` returns the count of the specified item in player's inventory. If searching for multiple items + returns key-value pairs of itemName = count. +- item: `table` or `string` + - Can be a single item name or array of item names. +- metadata?: `table` or `string` + - If metadata is provided as a string it will search the item's `metadata.type` property. + +**Count** + + + + +```lua +local count = exports.ox_inventory:Search('count', 'water') +print('You have '..count.. ' water') +``` + + + + +```lua +local inventory = exports.ox_inventory:Search('count', {'meat', 'skin'}, {grade="1"}) + +if inventory then + for name, count in pairs(inventory) do + print('You have '..count..' '..name) + end +end +``` + + + + +**Slots** + + + + +```lua +local water = exports.ox_inventory:Search('slots', 'water') +local count = 0 +for _, v in pairs(water) do + print(v.slot..' contains '..v.count..' water '..json.encode(v.metadata)) + count = count + v.count +end +print('You have '..count..' water') +``` + + + + +```lua +local items = exports.ox_inventory:Search('slots', {'meat', 'skin'}, 'deer') + +if items then + for name, data in pairs(items) do + local count = 0 + for _, v in pairs(data) do + if v.slot then + print(v.slot..' contains '..v.count..' '..name..' '..json.encode(v.metadata)) + count = count + v.count + end + end + print('You have '..count..' '..name) + end +end +``` + + + + +## GetItemCount + +Get the total item count for all items in the player's inventory with the given name and metadata. + +```lua +exports.ox_inventory:GetItemCount(itemName, metadata, strict) +``` + +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `number?` + +## GetPlayerItems + +Get all items in the player's inventory. + +```lua +exports.ox_inventory:GetPlayerItems() +``` + +**Returns:** `table` + +## GetPlayerWeight + +Get the total weight of all items in the player's inventory. + +```lua +exports.ox_inventory:GetPlayerWeight() +``` + +**Returns:** `number` + +## GetPlayerMaxWeight + +Get the maximum carry weight of the player's inventory. + +```lua +exports.ox_inventory:GetPlayerMaxWeight() +``` + +**Returns:** `number` + +## GetSlotIdWithItem + +Get a slot id in the player's inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotIdWithItem(itemName, metadata, strict) +``` + +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `number?` + +## GetSlotsIdWithItem + +Get all slot ids in the player's inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotIdsWithItem(itemName, metadata, strict) +``` + +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `number[]?` + +## GetSlotWithItem + +Get data for a slot in the player's inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotWithItem(itemName, metadata, strict) +``` + +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `table?` + +## GetSlotsWithItem + +Get data all slots in the player's inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotsWithItem(itemName, metadata, strict) +``` + +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `table[]?` + +## Statebags + +### invBusy + +Returns whether the player's inventory is currently running an action (i.e. using an item). +Can be set to true to disable opening the inventory. + +- invBusy: `boolean` + +```lua +local invBusy = LocalPlayer.state.invBusy + +if invBusy then + -- Do stuff when busy +else + -- Do stuff when not busy +end +``` + +**Disable opening inventory** + +```lua +LocalPlayer.state.invBusy = true +``` + +### invHotkeys + +Allows you to enable/disable a player's access to inventory hotkeys. + +- invHotkeys: `boolean` + +```lua +LocalPlayer.state.invHotkeys = false +``` + +```lua +LocalPlayer.state.invHotkeys = true +``` + +### invOpen + +Returns whether the player's inventory is currently open or not. + +- invOpen: `boolean` + +```lua +local invOpen = LocalPlayer.state.invOpen + +if invOpen then + -- Do stuff when open +else + -- Do stuff when closed +end +``` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetItemCount.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetItemCount.mdx deleted file mode 100644 index 666063e8..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetItemCount.mdx +++ /dev/null @@ -1,16 +0,0 @@ ---- -keywords: ['hasitem'] ---- - -Get the total item count for all items in the player's inventory with the given name and metadata. - -```lua -exports.ox_inventory:GetItemCount(itemName, metadata, strict) -``` - -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `number?` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetPlayerItems.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetPlayerItems.mdx deleted file mode 100644 index 2f459f75..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetPlayerItems.mdx +++ /dev/null @@ -1,7 +0,0 @@ -Get all items in the player's inventory. - -```lua -exports.ox_inventory:GetPlayerItems() -``` - -**Returns:** `table` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetPlayerMaxWeight.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetPlayerMaxWeight.mdx deleted file mode 100644 index b3e1cf8c..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetPlayerMaxWeight.mdx +++ /dev/null @@ -1,7 +0,0 @@ -Get the maximum carry weight of the player's inventory. - -```lua -exports.ox_inventory:GetPlayerMaxWeight() -``` - -**Returns:** `number` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetPlayerWeight.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetPlayerWeight.mdx deleted file mode 100644 index 5490027d..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetPlayerWeight.mdx +++ /dev/null @@ -1,7 +0,0 @@ -Get the total weight of all items in the player's inventory. - -```lua -exports.ox_inventory:GetPlayerWeight() -``` - -**Returns:** `number` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetSlotIdWithItem.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetSlotIdWithItem.mdx deleted file mode 100644 index fb4aff70..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetSlotIdWithItem.mdx +++ /dev/null @@ -1,12 +0,0 @@ -Get a slot id in the player's inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotIdWithItem(itemName, metadata, strict) -``` - -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `number?` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetSlotIdsWithItem.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetSlotIdsWithItem.mdx deleted file mode 100644 index 8170f145..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetSlotIdsWithItem.mdx +++ /dev/null @@ -1,12 +0,0 @@ -Get all slot ids in the player's inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotIdsWithItem(itemName, metadata, strict) -``` - -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `number[]?` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetSlotWithItem.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetSlotWithItem.mdx deleted file mode 100644 index 09174654..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetSlotWithItem.mdx +++ /dev/null @@ -1,12 +0,0 @@ -Get data for a slot in the player's inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotWithItem(itemName, metadata, strict) -``` - -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `table?` diff --git a/pages/ox_inventory/Functions/Client/Inventory/GetSlotsWithItem.mdx b/pages/ox_inventory/Functions/Client/Inventory/GetSlotsWithItem.mdx deleted file mode 100644 index 59d33852..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/GetSlotsWithItem.mdx +++ /dev/null @@ -1,12 +0,0 @@ -Get data all slots in the player's inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotsWithItem(itemName, metadata, strict) -``` - -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `table[]?` diff --git a/pages/ox_inventory/Functions/Client/Inventory/Search.mdx b/pages/ox_inventory/Functions/Client/Inventory/Search.mdx deleted file mode 100644 index 995fb2f1..00000000 --- a/pages/ox_inventory/Functions/Client/Inventory/Search.mdx +++ /dev/null @@ -1,84 +0,0 @@ ---- -keywords: ['hasitem'] ---- - -import { Tabs, Tab } from 'nextra-theme-docs'; - -Searches the inventory for an item, or list of items, with the result varying based on the first argument. - -```lua -exports.ox_inventory:Search(search, item, metadata) -``` - -* search: `'slots'` or `'count'` - * `'slots'` returns a table of slots where the item was found at. - * `'count'` returns the count of the specified item in player's inventory. If searching for multiple items - returns key-value pairs of itemName = count. -* item: `table` or `string` - * Can be a single item name or array of item names. -* metadata?: `table` or `string` - * If metadata is provided as a string it will search the item's `metadata.type` property. - -### Count - - - - -```lua -local count = exports.ox_inventory:Search('count', 'water') -print('You have '..count.. ' water') -``` - - - - -```lua -local inventory = exports.ox_inventory:Search('count', {'meat', 'skin'}, {grade="1"}) - -if inventory then - for name, count in pairs(inventory) do - print('You have '..count..' '..name) - end -end -``` - - - - -### Slots - - - - -```lua -local water = exports.ox_inventory:Search('slots', 'water') -local count = 0 -for _, v in pairs(water) do - print(v.slot..' contains '..v.count..' water '..json.encode(v.metadata)) - count = count + v.count -end -print('You have '..count..' water') -``` - - - - -```lua -local items = exports.ox_inventory:Search('slots', {'meat', 'skin'}, 'deer') - -if items then - for name, data in pairs(items) do - local count = 0 - for _, v in pairs(data) do - if v.slot then - print(v.slot..' contains '..v.count..' '..name..' '..json.encode(v.metadata)) - count = count + v.count - end - end - print('You have '..count..' '..name) - end -end -``` - - - diff --git a/pages/ox_inventory/Functions/Client/Items.mdx b/pages/ox_inventory/Functions/Client/Items.mdx deleted file mode 100644 index 0fe82d8e..00000000 --- a/pages/ox_inventory/Functions/Client/Items.mdx +++ /dev/null @@ -1,15 +0,0 @@ -Returns a table of all registered items. The format is as defined in [data/items.lua](https://github.com/overextended/ox_inventory/blob/main/data/items.lua). - -```lua -exports.ox_inventory:Items() -``` - -The following snippet can be used in crafting resources such as okokCrafting or core_crafting, rather than retrieving information from the server. - -```lua -local itemNames = {} - -for item, data in pairs(exports.ox_inventory:Items()) do - itemNames[item] = data.label -end -``` diff --git a/pages/ox_inventory/Functions/Client/Statebags/invBusy.mdx b/pages/ox_inventory/Functions/Client/Statebags/invBusy.mdx deleted file mode 100644 index e488bf43..00000000 --- a/pages/ox_inventory/Functions/Client/Statebags/invBusy.mdx +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: invBusy ---- - -Returns whether the player's inventory is currently running an action (i.e. using an item) - -* invBusy: `boolean` - -```lua -local isInventoryBusy = LocalPlayer.state.invBusy - -if isInventoryBusy then - -- Do stuff when busy -else - -- Do stuff when not busy -end -``` diff --git a/pages/ox_inventory/Functions/Client/Statebags/invHotkeys.mdx b/pages/ox_inventory/Functions/Client/Statebags/invHotkeys.mdx deleted file mode 100644 index 5f626006..00000000 --- a/pages/ox_inventory/Functions/Client/Statebags/invHotkeys.mdx +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: invHotkeys ---- - -Allows you to enable/disable a player's access to inventory hotkeys. - -* invHotkeys: `boolean` - -```lua -LocalPlayer.state.invHotkeys = false -``` - -```lua -LocalPlayer.state.invHotkeys = true -``` diff --git a/pages/ox_inventory/Functions/Client/Statebags/invOpen.mdx b/pages/ox_inventory/Functions/Client/Statebags/invOpen.mdx deleted file mode 100644 index 8a1b3c20..00000000 --- a/pages/ox_inventory/Functions/Client/Statebags/invOpen.mdx +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: invOpen ---- - -Returns whether the player's inventory is currently open or not. - -* invOpen: `boolean` - -```lua -local isInventoryOpen = LocalPlayer.state.invOpen - -if isInventoryOpen then - -- Do stuff when open -else - -- Do stuff when closed -end diff --git a/pages/ox_inventory/Functions/Client/Utils/weaponWheel.mdx b/pages/ox_inventory/Functions/Client/Utils/weaponWheel.mdx deleted file mode 100644 index 065a3072..00000000 --- a/pages/ox_inventory/Functions/Client/Utils/weaponWheel.mdx +++ /dev/null @@ -1,9 +0,0 @@ -Enables the weapon wheel, but disables the use of inventory items. - -Mostly used for weaponised vehicles, though could be called for "minigames" - -```lua -local exports.ox_inventory:weaponWheel(state) -``` - -* state: `boolean` diff --git a/pages/ox_inventory/Functions/Client/closeInventory.mdx b/pages/ox_inventory/Functions/Client/closeInventory.mdx deleted file mode 100644 index 5f7e76d9..00000000 --- a/pages/ox_inventory/Functions/Client/closeInventory.mdx +++ /dev/null @@ -1,5 +0,0 @@ -Closes the player's inventory. - -```lua -exports.ox_inventory:closeInventory() -``` diff --git a/pages/ox_inventory/Functions/Client/displayMetadata.mdx b/pages/ox_inventory/Functions/Client/displayMetadata.mdx deleted file mode 100644 index 085fccb7..00000000 --- a/pages/ox_inventory/Functions/Client/displayMetadata.mdx +++ /dev/null @@ -1,24 +0,0 @@ -Sets a metadata property to display in the tooltip. - -```lua -exports.ox_inventory:displayMetadata(metadata, value) -``` - -* metadata: `table` or `string` - * If metadata is a string then it's the metadata property you want to display, value is **not** optional then. - * Can be a table of key-value pairs, key being the metadata property and value being the label for that property. -* value?: `string` - * Label for the string metadata property to be displayed. - -**Example:** - -```lua -exports.ox_inventory:displayMetadata('mustard', 'Mustard') -``` - -```lua -exports.ox_inventory:displayMetadata({ - mustard = 'Mustard', - ketchup = 'Ketchup' -}) -``` diff --git a/pages/ox_inventory/Functions/Client/getCurrentWeapon.mdx b/pages/ox_inventory/Functions/Client/getCurrentWeapon.mdx deleted file mode 100644 index 6337ff9b..00000000 --- a/pages/ox_inventory/Functions/Client/getCurrentWeapon.mdx +++ /dev/null @@ -1,28 +0,0 @@ -Get data for the currently equipped weapon. - -```lua -exports.ox_inventory:getCurrentWeapon() -``` - -You can also listen for changes to the current weapon using an event handler. - -```lua -AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon) - CurrentWeapon = currentWeapon -end) -``` - -- currentWeapon?: `table` - - ammo?: `string` Name of the item used as ammo. - - hash: `number` - - label: `string` - - melee: `boolean` - - metadata: `table` - - ammo?: `number` Amount of ammo loaded into the weapon. - - components?: `table` Array of component item names, used to apply weapon components. - - durability?: `number` - - registered?: `string` Name of the player that bought the weapon at a shop. - - serial?: `string` - - name: `string` Name of the item. - - slot: `number` - - weight: `number` diff --git a/pages/ox_inventory/Functions/Client/openInventory.mdx b/pages/ox_inventory/Functions/Client/openInventory.mdx deleted file mode 100644 index 0b0d0df8..00000000 --- a/pages/ox_inventory/Functions/Client/openInventory.mdx +++ /dev/null @@ -1,61 +0,0 @@ -import { Tabs, Tab } from 'nextra-theme-docs'; - -Opens an inventory using the passed data. - -```lua -exports.ox_inventory:openInventory(invType, data) -``` - -* invType: `string` - * `'player'` - * `'shop'` - * `'stash'` - * `'crafting'` - * `'container'` - * `'drop'` - * `'glovebox'` - * `'trunk'` - * `'dumpster'` -* data: `number` or `string` or `table` - - - - -**Open the target player's inventory.** - -```lua -exports.ox_inventory:openInventory('player', 3) -``` - - - - -**Open the fourth "General Store" [location](https://github.com/overextended/ox_inventory/blob/main/data/shops.lua#L14).** - -```lua -exports.ox_inventory:openInventory('shop', { type = 'General', id = 4 }) -``` - - - - -**Open the first stash in [data/stashes](https://github.com/overextended/ox_inventory/blob/main/data/stashes.lua#L2-L19).** - -```lua -exports.ox_inventory:openInventory('stash', 1) -``` - -**Open a custom stash (created on the server with RegisterStash).** - -```lua -exports.ox_inventory:openInventory('stash', 'society_police') -``` - -**Open a stash with a specific owner.** - -```lua -exports.ox_inventory:openInventory('stash', { id = 'police_locker', owner = 'license:xxxxxxxx' }) -``` - - - diff --git a/pages/ox_inventory/Functions/Client/openNearbyInventory.mdx b/pages/ox_inventory/Functions/Client/openNearbyInventory.mdx deleted file mode 100644 index d6efd961..00000000 --- a/pages/ox_inventory/Functions/Client/openNearbyInventory.mdx +++ /dev/null @@ -1,9 +0,0 @@ -If possible opens the nearby player's inventory. - -The player trying to open the inventory must be able to open their own and -if the player does not have a police job, the target player must be fatally injured or -playing one of the death anims. - -```lua -exports.ox_inventory:openNearbyInventory() -``` diff --git a/pages/ox_inventory/Functions/Client/setStashTarget.mdx b/pages/ox_inventory/Functions/Client/setStashTarget.mdx deleted file mode 100644 index c3537969..00000000 --- a/pages/ox_inventory/Functions/Client/setStashTarget.mdx +++ /dev/null @@ -1,15 +0,0 @@ -Forces the secondary-inventory key to open the passed inventory. Can be useful to enable inventory access while standing inside a marker. - -```lua -exports.ox_inventory:setStashTarget(id, owner) -``` - -* id: `string` or `number` - * Stash id. -* owner?: `string` or `number` - -**Example:** - -```lua -exports.ox_inventory:setStashTarget('motel5', 'bobsmith') -``` diff --git a/pages/ox_inventory/Functions/Client/useItem.mdx b/pages/ox_inventory/Functions/Client/useItem.mdx deleted file mode 100644 index 76a4e3d0..00000000 --- a/pages/ox_inventory/Functions/Client/useItem.mdx +++ /dev/null @@ -1,32 +0,0 @@ -Uses the passed item, then triggers the callback function. -Should be calling during item callbacks to utilise the builtin methods (server checks, progress bar, etc.). - -```lua -exports.ox_inventory:useItem(data, cb) -``` - -* data: `table` -* cb?: `function` - -```lua -exports('bandage', function(data, slot) - local playerPed = PlayerPedId() - local maxHealth = GetEntityMaxHealth(playerPed) - local health = GetEntityHealth(playerPed) - - -- Does the ped need to heal? - if health < maxHealth then - -- Use the bandage - exports.ox_inventory:useItem(data, function(data) - -- The item has been used, so trigger the effects - if data then - SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16))) - lib.notify({description = 'You feel better already'}) - end - end) - else - -- Don't use the item - lib.notify({type = 'error', description = 'You don\'t need a bandage right now'}) - end -end) -``` diff --git a/pages/ox_inventory/Functions/Client/useSlot.mdx b/pages/ox_inventory/Functions/Client/useSlot.mdx deleted file mode 100644 index bb7c9cbd..00000000 --- a/pages/ox_inventory/Functions/Client/useSlot.mdx +++ /dev/null @@ -1,7 +0,0 @@ -Uses the item in the given inventory slot. - -```lua -exports.ox_inventory:useSlot(slot) -``` - -* slot: `number` diff --git a/pages/ox_inventory/Functions/Server.mdx b/pages/ox_inventory/Functions/Server.mdx new file mode 100644 index 00000000..e4b0aed5 --- /dev/null +++ b/pages/ox_inventory/Functions/Server.mdx @@ -0,0 +1,883 @@ +import { Tabs, Tab } from 'nextra-theme-docs'; +import { Callout } from 'nextra/components'; + +```lua +local itemNames +ESX.RegisterServerCallback('crafting:itemNames', function(source, cb) + if not itemNames then + itemNames = {} + for item, data in pairs(exports.ox_inventory:Items()) do + itemNames[item] = data.label + end + end + cb(itemNames) +end) +``` + +## setPlayerInventory + +Creates and sets the player's inventory. + +```lua +exports.ox_inventory:setPlayerInventory(player, data) +``` + +- player: `table` + - source: `number` + - identifier: `string` + - name: `string` + - groups?: `table` + - sex?: `string` + - dateofbirth?: `string` +- data?: `table` + - If not provided will load player's inventory data from the db. + +## forceOpenInventory + +Opens an inventory using the passed data. +Forces a player to open an inventory, without usual security checks (groups, coords). + +```lua +exports.ox_inventory:forceOpenInventory(playerId, invType, data) +``` + +- playerId: `number` +- invType: `string` + - `'player'` + - `'stash'` + - `'container'` + - `'drop'` + - `'glovebox'` + - `'trunk'` + - `'dumpster'` +- data: `number` or `string` or `table` + + + + +**Open the target player's inventory.** + +```lua +exports.ox_inventory:forceOpenInventory(1, 'player', 3) +``` + +**Admin command to open a player's inventory.** + +```lua +RegisterCommand('openplayerinv', function(source, args) + exports.ox_inventory:forceOpenInventory(source, 'player', tonumber(args[1])) +end, true) +``` + + + + +**Open the first stash in [data/stashes](https://github.com/overextended/ox_inventory/blob/main/data/stashes.lua#L2-L19).** + +```lua +exports.ox_inventory:forceOpenInventory(1, 'stash', 'apartment420') +``` + +**Open a custom stash (created on the server with RegisterStash).** + +```lua +exports.ox_inventory:forceOpenInventory(1, 'stash', 'society_police') +``` + +**Open a stash with a specific owner.** + +```lua +exports.ox_inventory:forceOpenInventory(1, 'stash', { id = 'police_locker', owner = 'license:xxxxxxxx' }) +``` + + + + +## UpdateVehicle + +Update the internal reference to vehicle stashes, without triggering a save or updating the database. + +```lua +exports.ox_inventory:UpdateVehicle(oldPlate, newPlate) +``` + +- oldPlate: `string` +- newPlate: `string` + +## Items + +Returns a table of all registered items. The format is as defined in [data/items.lua](https://github.com/overextended/ox_inventory/blob/main/data/items.lua). + +```lua +exports.ox_inventory:Items() +``` + +The following snippet can be used in crafting resources such as okokCrafting or core_crafting, rather than querying the database. + +## AddItem + +Adds an item into the specified inventory. + +Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximum weight may be exceeded. + +```lua +exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb) +``` + +- inv: `table` or `string` or `number` + - The inventory's unique id, or a table with the id and owner. + - playerId: `1` + - inventoryId: `gloveVGH283` + - `{ id = 'personallocker', owner = 'license:xxxxxx'}` +- item: `string` + - The name of the item to add to the target. +- count: `number` + - The number of items to add. +- metadata?: `table` or `string` + - A table of unique data to attach to the item object. A string will create a table with the "type" field. +- slot?: `number` + - A specific slot to add the item to. If the slot is invalid, the first available slot will be used instead. +- cb?: function(success: `boolean`, response?: `string`) + +If used for glovebox, trunk or stash you must first check the inventory is loaded with [GetInventory](./GetInventory.md) + +Returns `success, response` if cb is undefined, otherwise they are used in the callback only. + +**Example:** + +```lua +local success, response = exports.ox_inventory:AddItem('gloveVGH283', 'bread', 4) + +if not success then + -- if no slots are available, the value will be "inventory_full" + return print(response) +end + +print(json.encode(response, {indent=true})) +--[[ + { + "metadata": [], + "label": "Bread", + "slot": 1, + "stack": true, + "close": true, + "name": "bread", + "count": 1, + "weight": 150 + } +]] +``` + +**Possible value of the "response" argument, on failure:** + +- "invalid_item": the item doesn't exist +- "invalid_inventory": the inventory doesn't exist +- "inventory_full": no free slots + +## RemoveItem + +Removes the specified item from the specified inventory. + +```lua +exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot) +``` + +- inv: `table` or `string` or `number` + - The inventory's unique id, or a table with the id and owner. + - playerId: `1` + - inventoryId: `gloveVGH283` + - `{ id = 'personallocker', owner = 'license:xxxxxx'}` +- item: `string` + - The name of the item to remove from the target. +- count: `number` + - The number of items to remove. +- metadata?: `table` or `string` + - Only remove items with matching metadata properties. +- slot?: `number` + - A specific slot to remove the item from. If the slot is invalid, the first available slot will be used instead. +- cb?: function(success: `boolean`, response?: `string`) + +Returns success: `boolean`, response: `string?`. + +**Possible value of "response" on failure:** + +- "invalid_item": the item doesn't exist +- "invalid_inventory": the inventory doesn't exist +- "not_enough_items": inventory did not contain enough of the given item + +**Example:** + +```lua +-- Removes 2 water from the glovebox for the given plate. +local success = exports.ox_inventory:RemoveItem('gloveVGH283', 'water', 2) +``` + +## GetItem + +Returns _generic_ item data from the specified inventory, with the total count. + +```lua +exports.ox_inventory:GetItem(inv, item, metadata, returnsCount) +``` + +- inv: `table` or `string` or `number` +- item: `table` or `string` + - Can be items array. +- metadata?: `any` + - Only returns the count of items that strictly match the given metadata. +- returnsCount?: `boolean` + +If `returnsCount` is set to true, the returned value will be the `count` based on +how many times the item was found. + +Otherwise returns the data related to the item _and_ its total count found in the inventory. + +**Example**: + +```lua +local item = ox_inventory:GetItem(source, 'water', nil, false) + +print(json.encode(item, {indent=true})) +--[[ + { + "consume": 1, + "count": 15, + "stack": true, + "name": "water", + "weight": 500, + "label": "Water", + "close": true + } +]] +``` + +## ConvertItems + +Takes traditional item data and updates it to support ox_inventory. + +```lua +exports.ox_inventory:ConvertItems(playerId, items) +``` + +- playerId: `number` +- items: `table` + +Data conversion example: + +```lua +Old: [{"cola":1, "bread":3}] +New: [{"slot":1,"name":"cola","count":1}, +{"slot":2,"name":"bread","count":3}] +``` + +## CanCarryItem + +Returns true or false depending if the inventory can carry the specified item. + +The function checks for inventory weight and available slots. + +```lua +exports.ox_inventory:CanCarryItem(inv, item, count, metadata) +``` + +- inv: `table` or `string` or `number` +- item `table` or `string` + - Can be array of items. +- count: `number` +- metadata?: `table` or `string` + - If metadata is passed as string then `metadata.type` will be checked. + +**Example:** + +```lua +-- Checks if the player calling the event can carry 3 water items +if exports.ox_inventory:CanCarryItem(source, 'water', 3) then + -- Do stuff if can carry +else + -- Do stuff if can't carry +end +``` + +## CanCarryAmount + +Returns the amount a player can hold based on available weight. + +```lua +exports.ox_inventory:CanCarryAmount(inv, item) +``` + +- inv: `table` or `string` or `number` +- item: `table` or `string` + - Can be array to check multiple items. + +Example: + +```lua +-- Checks how much you can carry +amountToAdd = exports.ox_inventory:CanCarryAmount(inv, 'stone') +-- Adds the amount +exports.ox_inventory:AddItem(inv, 'stone', amountToAdd) +``` + +## CanCarryWeight + +Returns if inventory can carry specified weight and free inventory weight. + +```lua +exports.ox_inventory:CanCarryWeight(inv, weight) +``` + +- inv: `table` or `string` or `number` +- weight: `number` + +Example: + +```lua +-- Checks if player can carry 1000 grams. +local fillAmount = 1000 +local canCarryWeight, freeWeight = ox_inventory:CanCarryWeight(playerId, fillAmount) + +if freeWeight == 0 then + -- Player can't carry weight. + return +elseif not canCarryWeight then + -- Modify fillAmount, because inventory can't carry specified weight + fillAmount = freeWeight +end + +-- Do something +``` + +## SetMaxWeight + +Sets the maximum weight available for an inventory. + +```lua +exports.ox_inventory:SetMaxWeight(inv, maxWeight) +``` + +- inv: `table` or `string` or `number` +- maxWeight: `number` + +**Example:** + +```lua +local ox_inventory = exports.ox_inventory + +-- Set the max weight for player 1's inventory to 20kg. +ox_inventory:SetMaxWeight(1, 20000) +``` + +## CanSwapItem + +Returns true if the item swap is possible based on inventory weight. + +```lua +exports.ox_inventory:CanSwapItem(inv, firstItem, firstItemCount, testItem, testItemCount) +``` + +- inv: `table` or `string` or `number` +- firstItem: `string` +- firstItemCount: `number` +- testItem: `string` +- testItemCount: `number` + +## GetItemCount + +Get the total item count for all items in an inventory with the given name and metadata. + +```lua +exports.ox_inventory:GetItemCount(inv, itemName, metadata, strict) +``` + +- inv: `table` or `string` or `number` +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `number?` + +## GetItemSlots + +Returns the number of slots the specified item is in, the item's total count and the remaining empty slots. + +```lua +exports.ox_inventory:GetItemSlots(inv, item, metadata) +``` + +- inv: `table` or `string` or `number` +- item: `table` or `string` +- metadata?: `table` + +## GetSlot + +Returns the specified slot data as a table. + +```lua + +exports.ox_inventory:GetSlot(inv, slot) +``` + +- inv: `table` or `string` or `number` +- slot: `number` + +**Example:** + +```lua +local slot = exports.ox_inventory:GetSlot(source, 1) + +print(json.encode(slot, {indent=true})) +--[[ + { + "weight": 2000, + "name": "water", + "metadata": [], + "slot": 1, + "label": "Water", + "close": true, + "stack": true, + "count: 4 + } +]] +``` + +## GetSlotForItem + +Get the slot id of an existing item matching the given data, or an empty slot. + +```lua +exports.ox_inventory:GetSlotForItem(inv, itemName, metadata) +``` + +- inv: `table` or `string` or `number` +- itemName: `string` +- metadata: `table?` + +**Returns:** `number?` + +## GetSlotIdWithItem + +Get a slot id in an inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotIdWithItem(inv, itemName, metadata, strict) +``` + +- inv: `table` or `string` or `number` +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `number?` + +## GetSlotIdsWithItem + +Get all slot ids in an inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotIdsWithItem(inv, itemName, metadata, strict) +``` + +- inv: `table` or `string` or `number` +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `number[]?` + +## GetSlotWithItem + +Get data for a slot in an inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotWithItem(inv, itemName, metadata, strict) +``` + +- inv: `table` or `string` or `number` +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `table?` + +## GetSlotsWithItem + +Get data all slots in an inventory matching the given name and metadata. + +```lua +exports.ox_inventory:GetSlotsWithItem(inv, itemName, metadata, strict) +``` + +- inv: `table` or `string` or `number` +- itemName: `string` +- metadata?: `table` +- strict?: `boolean` + - Strictly match metadata properties, otherwise use partial matching. + +**Returns:** `table[]?` + +## GetEmptySlot + +Get the first available empty slot in an inventory. + +```lua +exports.ox_inventory:GetEmptySlot(inv) +``` + +- inv: `table` or `string` or `number` + +**Returns:** `number?` + +## GetContainerFromSlot + +Returns the inventory associated with the container linked in the slot of the given inventory. + +```lua +exports.ox_inventory:GetContainerFromSlot(inv, slotId) +``` + +- inv: `table` or `string` or `number` +- slotId: `number` + +**Returns:** `table?` + +## SetSlotCount + +Sets the number of slots available for an inventory. + +```lua +exports.ox_inventory:SetSlotCount(inv, slots) +``` + +- inv: `table` or `string` or `number` +- slots: `number` + +**Example:** + +```lua +local ox_inventory = exports.ox_inventory + +-- Set the slot count for player 1's inventory to 10. +ox_inventory:SetSlotCount(1, 10) +``` + +## GetInventory + +Returns the inventory associated with the ID (and owner if defined). Otherwise returns null. + +```lua +exports.ox_inventory:GetInventory(inv, owner) +``` + +- inv: `number` or `table` +- owner?: `string` or `boolean` + +**Example:** + +```lua +local inventory = exports.ox_inventory:GetInventory('example_stash', false) +print(json.encode(inventory, {indent = true})) +--[[ + { + "id": "example_stash, + "label": "Police Stash", + "type": "stash, + "slots": 50, + "weight": 0, + "maxWeight": 100000, + "owner": false, + ... + } +]] +``` + +## GetInventoryItems + +Returns all slots with items in a inventory. + +```lua +exports.ox_inventory:GetInventoryItems(inv, owner) +``` + +- inv: `number` or `table` +- owner?: `string` or `boolean` + +**Example:** + +```lua +local playerItems = exports.ox_inventory:GetInventoryItems(source) +``` + +## ConfiscateInventory + +Clears a player's inventory and saves it to a stash. + +Use [ReturnInventory](./Server/#returninventory) to return the confiscated inventory back to +the player. + +```lua +exports.ox_inventory:ConfiscateInventory(source) +``` + +- source: `number` + +## ReturnInventory + +Returns the confiscated inventory back to the player. + +Use it alongside [ConfiscateInventory](./Server/#confiscateinventory.md). + +```lua +exports.ox_inventory:ReturnInventory(source) +``` + +- source: `number` + +## ClearInventory + +Clears the specified inventory. The `keep` argument is either a string or an array of strings containing the name(s) of the item(s) to keep in the inventory after clearing. + +```lua +exports.ox_inventory:ClearInventory(inv, keep) +``` + +- inv: `table` or `string` or `number` +- keep?: `string` or `string[]` + +## Search + +Searches an inventory for a specified item. + +```lua +exports.ox_inventory:Search(inv, search, item, metadata) +``` + +- inv: `table` or `string` or `number` +- search: `string` +- item: `table` or `string` +- metadata?: `table` or `string` + +`search` can be either `'slots'` or `'count'`, where slots will return a table of data +and count will return the found amount of the specified item. + +## SwapSlots + +Swaps slots in specified inventories. + +```lua +exports.ox_inventory:SwapSlots(fromInventory, toInventory, slot1, slot2) +``` + +- fromInventory: `table` or `string` or `number` +- toInventory: `table` or `string` or `number` +- slot1: `number` +- slot2: `number` + +## RegisterStash + +Creates a new custom stash. + +```lua +exports.ox_inventory:RegisterStash(id, label, slots, maxWeight, owner, groups, coords) +``` + +- id: `string` or `number` + - Stash identifier when loading from the database. +- label: `string` + - Display name when inventory is open. +- slots: `number` +- maxWeight: `number` +- owner: `string` or `boolean` or `nil` + - `string`: Can only access the stash linked to the owner. + - `true`: Each player has a unique stash but can request other player's stashes. + - `nil`: Always shared. +- groups: `table` + - Table of player groups (jobs) able to access the stash. + - Table of group names where the numeric value is the minimum grade required. + - `{['police'] = 0, ['ambulance'] = 2}` +- coords?: `vector3` or `vector3[]` + + + +This function needs to be triggered before a player can open the stash. + + + +**Example:** + +For a use case example on this function check out the written [Guide](../../../Guides/stashes.md) for it. + +## CreateTemporaryStash + +# CreateTemporaryStash + +Creates a temporary stash which will be removed after some time. + +```lua +exports.ox_inventory:CreateTemporaryStash(properties) +``` + +- properties: `table` + - label: `string` + - slots: `number` + - maxWeight: `number` + - owner?: `string` `number` or `boolean` + - `string`: Can only access the stash linked to the owner. + - `true`: Each player has a unique stash but can request other player's stashes. + - The inventory is always shared if `false` or `nil`. + - groups?: `table` + - Table of group names (e.g. jobs) where the numeric value is the minimum grade required. + - `{['police'] = 0, ['ambulance'] = 2}` + - coords?: `vector3` + - Stash can only be accessed while nearby. + - items?: `{ [number]: string, [number]: number, [number]?: table }[]` + - An array of tables, containing a sequence of itemName, count, metadata. + +Return: + +- inventoryId: `string` + +**Example** + +```lua +local mystash = exports.ox_inventory:CreateTemporaryStash({ + label = 'mystash', + slots = 5, + maxWeight = 5000, + items = { + { 'WEAPON_MINISMG', 1 }, + { 'ammo-9', 69 }, + { 'water', 2, { label = 'Mineral water' } } + } +}) + +TriggerClientEvent('ox_inventory:openInventory', 1, 'stash', mystash) +``` + +## CustomDrop + +Drops can be created from other resources, containing a variety of items and utilising a custom label (instead of 'Drop 32648'). + +```lua +exports.ox_inventory:CustomDrop(prefix, items, coords, slots, maxWeight, instance, model) +``` + +- prefix: `string` +- items: `table` + - name: `string` + - count: `number` + - metadata?: `table` +- coords: `vector3` +- slots?: `number` +- maxWeight?: `number` +- instance?: `string` or `number` +- model?: `number` + +```lua +-- Create a generic drop with a marker +exports.ox_inventory:CustomDrop('Carcass', { + {'meat', 5, { grade = 2, type = 'deer' }}, + {'hide', 5, { grade = 2, type = 'deer' }} +}, coords) + +-- Create a drop with an entity +exports.ox_inventory:CustomDrop('SMG', { + { 'WEAPON_MINISMG', 1 }, + { 'ammo-9', 69 }, +}, GetEntityCoords(GetPlayerPed(1)), 5, 10000, nil, `w_sb_minismg`) +``` + +## CreateDropFromPlayer + +Creates a new drop with the contents of a player's inventory. + +```lua +exports.ox_inventory:CreateDropFromPlayer(playerId) +``` + +- playerId: `number` + +Return: + +- dropId: `string` + +**Example** + +```lua +local dropId = exports.ox_inventory:CreateDropFromPlayer(1) +``` + +## GetCurrentWeapon + +Returns the player's currently equipped weapon as a table. + +```lua +-- inv: string or number +exports.ox_inventory:GetCurrentWeapon(inv) +``` + +- inv: `table` or `string` or `number` + +## SetDurability + +Sets durability onto the specified slot. + +Can be used for repairing weapons. + +```lua +exports.ox_inventory:SetDurability(inv, slot, durability) +``` + +- inv: `table` or `string` or `number` +- slot: `number` +- durability: `number` + +**Example:** + +```lua +local ox_inventory = exports.ox_inventory + +-- Set the durability of the item in slot 3 of source player's inventory to 100 +ox_inventory:SetDurability(source, 3, 100) + +-- Set the durability of the source player's current weapon to 100 +local weapon = ox_inventory:GetCurrentWeapon(source) + +if weapon then + ox_inventory:SetDurability(source, weapon.slot, 100) +end +``` + +## SetMetadata + +Sets metadata on the specified slot. + +```lua +ox_inventory:SetMetadata(inv, slot, metadata) +``` + +- inv: `table` or `string` or `number` +- slot: `number` +- metadata: `table` + +**Example:** + +```lua +local ox_inventory = exports.ox_inventory + +local water = ox_inventory:Search(source, 1, 'water') +for k, v in pairs(water) do + print('\n______________'..'\n- index '..k) + print(v.name, 'slot: '..v.slot, 'metadata: '..json.encode(v.metadata)) + water = v + break +end + +water.metadata.type = 'clean' +ox_inventory:SetMetadata(source, water.slot, water.metadata) +print(('modified %sx water in slot %s with new metadata'):format(water.count, water.slot)) +``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/AddItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/AddItem.mdx deleted file mode 100644 index 1d876c57..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/AddItem.mdx +++ /dev/null @@ -1,57 +0,0 @@ -Adds an item into the specified inventory. - -Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximum weight may be exceeded. - -```lua -exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb) -``` - -- inv: `table` or `string` or `number` - - The inventory's unique id, or a table with the id and owner. - - playerId: `1` - - inventoryId: `gloveVGH283` - - `{ id = 'personallocker', owner = 'license:xxxxxx'}` -- item: `string` - - The name of the item to add to the target. -- count: `number` - - The number of items to add. -- metadata?: `table` or `string` - - A table of unique data to attach to the item object. A string will create a table with the "type" field. -- slot?: `number` - - A specific slot to add the item to. If the slot is invalid, the first available slot will be used instead. -- cb?: function(success: `boolean`, response?: `string`) - -If used for glovebox, trunk or stash you must first check the inventory is loaded with [GetInventory](./GetInventory.md) - -Returns `success, response` if cb is undefined, otherwise they are used in the callback only. - -**Example:** - -```lua -local success, response = exports.ox_inventory:AddItem('gloveVGH283', 'bread', 4) - -if not success then - -- if no slots are available, the value will be "inventory_full" - return print(response) -end - -print(json.encode(response, {indent=true})) ---[[ - { - "metadata": [], - "label": "Bread", - "slot": 1, - "stack": true, - "close": true, - "name": "bread", - "count": 1, - "weight": 150 - } -]] -``` - -**Possible value of the "response" argument, on failure:** - -- "invalid_item": the item doesn't exist -- "invalid_inventory": the inventory doesn't exist -- "inventory_full": no free slots diff --git a/pages/ox_inventory/Functions/Server/Inventory/CanCarryAmount.mdx b/pages/ox_inventory/Functions/Server/Inventory/CanCarryAmount.mdx deleted file mode 100644 index 85413b5a..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CanCarryAmount.mdx +++ /dev/null @@ -1,18 +0,0 @@ -Returns the amount a player can hold based on available weight. - -```lua -exports.ox_inventory:CanCarryAmount(inv, item) -``` - -* inv: `table` or `string` or `number` -* item: `table` or `string` - * Can be array to check multiple items. - -Example: - -```lua --- Checks how much you can carry -amountToAdd = exports.ox_inventory:CanCarryAmount(inv, 'stone') --- Adds the amount -exports.ox_inventory:AddItem(inv, 'stone', amountToAdd) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/CanCarryItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/CanCarryItem.mdx deleted file mode 100644 index c6122c06..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CanCarryItem.mdx +++ /dev/null @@ -1,25 +0,0 @@ -Returns true or false depending if the inventory can carry the specified item. - -The function checks for inventory weight and available slots. - -```lua -exports.ox_inventory:CanCarryItem(inv, item, count, metadata) -``` - -* inv: `table` or `string` or `number` -* item `table` or `string` - * Can be array of items. -* count: `number` -* metadata?: `table` or `string` - * If metadata is passed as string then `metadata.type` will be checked. - -**Example:** - -```lua --- Checks if the player calling the event can carry 3 water items -if exports.ox_inventory:CanCarryItem(source, 'water', 3) then - -- Do stuff if can carry -else - -- Do stuff if can't carry -end -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/CanCarryWeight.mdx b/pages/ox_inventory/Functions/Server/Inventory/CanCarryWeight.mdx deleted file mode 100644 index 1762b63f..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CanCarryWeight.mdx +++ /dev/null @@ -1,26 +0,0 @@ -Returns if inventory can carry specified weight and free inventory weight. - -```lua -exports.ox_inventory:CanCarryWeight(inv, weight) -``` - -* inv: `table` or `string` or `number` -* weight: `number` - -Example: - -```lua --- Checks if player can carry 1000 grams. -local fillAmount = 1000 -local canCarryWeight, freeWeight = ox_inventory:CanCarryWeight(playerId, fillAmount) - -if freeWeight == 0 then - -- Player can't carry weight. - return -elseif not canCarryWeight then - -- Modify fillAmount, because inventory can't carry specified weight - fillAmount = freeWeight -end - --- Do something -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/CanSwapItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/CanSwapItem.mdx deleted file mode 100644 index deb20111..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CanSwapItem.mdx +++ /dev/null @@ -1,11 +0,0 @@ -Returns true if the item swap is possible based on inventory weight. - -```lua -exports.ox_inventory:CanSwapItem(inv, firstItem, firstItemCount, testItem, testItemCount) -``` - -* inv: `table` or `string` or `number` -* firstItem: `string` -* firstItemCount: `number` -* testItem: `string` -* testItemCount: `number` diff --git a/pages/ox_inventory/Functions/Server/Inventory/ClearInventory.mdx b/pages/ox_inventory/Functions/Server/Inventory/ClearInventory.mdx deleted file mode 100644 index e541ff94..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/ClearInventory.mdx +++ /dev/null @@ -1,8 +0,0 @@ -Clears the specified inventory. The `keep` argument is either a string or an array of strings containing the name(s) of the item(s) to keep in the inventory after clearing. - -```lua -exports.ox_inventory:ClearInventory(inv, keep) -``` - -* inv: `table` or `string` or `number` -* keep?: `string` or `string[]` diff --git a/pages/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.mdx b/pages/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.mdx deleted file mode 100644 index aaf9dac9..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.mdx +++ /dev/null @@ -1,10 +0,0 @@ -Clears a player's inventory and saves it to a stash. - -Use [ReturnInventory](./ReturnInventory.md) to return the confiscated inventory back to -the player. - -```lua -exports.ox_inventory:ConfiscateInventory(source) -``` - -* source: `number` diff --git a/pages/ox_inventory/Functions/Server/Inventory/ConvertItems.mdx b/pages/ox_inventory/Functions/Server/Inventory/ConvertItems.mdx deleted file mode 100644 index f9e24d08..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/ConvertItems.mdx +++ /dev/null @@ -1,16 +0,0 @@ -Takes traditional item data and updates it to support ox_inventory. - -```lua -exports.ox_inventory:ConvertItems(playerId, items) -``` - -* playerId: `number` -* items: `table` - -Data conversion example: - -```lua -Old: [{"cola":1, "bread":3}] -New: [{"slot":1,"name":"cola","count":1}, -{"slot":2,"name":"bread","count":3}] -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/CreateDropFromPlayer.mdx b/pages/ox_inventory/Functions/Server/Inventory/CreateDropFromPlayer.mdx deleted file mode 100644 index ebb6575d..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CreateDropFromPlayer.mdx +++ /dev/null @@ -1,18 +0,0 @@ -# CreateDropFromPlayer - -Creates a new drop with the contents of a player's inventory. - -```lua -exports.ox_inventory:CreateDropFromPlayer(playerId) -``` - -- playerId: `number` - -Return: -- dropId: `string` - -**Example** - -```lua -local dropId = exports.ox_inventory:CreateDropFromPlayer(1) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/CreateTemporaryStash.mdx b/pages/ox_inventory/Functions/Server/Inventory/CreateTemporaryStash.mdx deleted file mode 100644 index aa3bd0ff..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CreateTemporaryStash.mdx +++ /dev/null @@ -1,43 +0,0 @@ -# CreateTemporaryStash - -Creates a temporary stash which will be removed after some time. - -```lua -exports.ox_inventory:CreateTemporaryStash(properties) -``` - -- properties: `table` - - label: `string` - - slots: `number` - - maxWeight: `number` - - owner?: `string` `number` or `boolean` - - `string`: Can only access the stash linked to the owner. - - `true`: Each player has a unique stash but can request other player's stashes. - - The inventory is always shared if `false` or `nil`. - - groups?: `table` - - Table of group names (e.g. jobs) where the numeric value is the minimum grade required. - - `{['police'] = 0, ['ambulance'] = 2}` - - coords?: `vector3` - - Stash can only be accessed while nearby. - - items?: `{ [number]: string, [number]: number, [number]?: table }[]` - - An array of tables, containing a sequence of itemName, count, metadata. - -Return: -- inventoryId: `string` - -**Example** - -```lua -local mystash = exports.ox_inventory:CreateTemporaryStash({ - label = 'mystash', - slots = 5, - maxWeight = 5000, - items = { - { 'WEAPON_MINISMG', 1 }, - { 'ammo-9', 69 }, - { 'water', 2, { label = 'Mineral water' } } - } -}) - -TriggerClientEvent('ox_inventory:openInventory', 1, 'stash', mystash) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/CustomDrop.mdx b/pages/ox_inventory/Functions/Server/Inventory/CustomDrop.mdx deleted file mode 100644 index 79b6d22e..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/CustomDrop.mdx +++ /dev/null @@ -1,30 +0,0 @@ -Drops can be created from other resources, containing a variety of items and utilising a custom label (instead of 'Drop 32648'). - -```lua -exports.ox_inventory:CustomDrop(prefix, items, coords, slots, maxWeight, instance, model) -``` - -- prefix: `string` -- items: `table` - - name: `string` - - count: `number` - - metadata?: `table` -- coords: `vector3` -- slots?: `number` -- maxWeight?: `number` -- instance?: `string` or `number` -- model?: `number` - -```lua --- Create a generic drop with a marker -exports.ox_inventory:CustomDrop('Carcass', { - {'meat', 5, { grade = 2, type = 'deer' }}, - {'hide', 5, { grade = 2, type = 'deer' }} -}, coords) - --- Create a drop with an entity -exports.ox_inventory:CustomDrop('SMG', { - { 'WEAPON_MINISMG', 1 }, - { 'ammo-9', 69 }, -}, GetEntityCoords(GetPlayerPed(1)), 5, 10000, nil, `w_sb_minismg`) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetContainerFromSlot.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetContainerFromSlot.mdx deleted file mode 100644 index 8e5f8af3..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetContainerFromSlot.mdx +++ /dev/null @@ -1,10 +0,0 @@ -Returns the inventory associated with the container linked in the slot of the given inventory. - -```lua -exports.ox_inventory:GetContainerFromSlot(inv, slotId) -``` - -- inv: `table` or `string` or `number` -- slotId: `number` - -**Returns:** `table?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.mdx deleted file mode 100644 index 94c0a815..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.mdx +++ /dev/null @@ -1,8 +0,0 @@ -Returns the player's currently equipped weapon as a table. - -```lua --- inv: string or number -exports.ox_inventory:GetCurrentWeapon(inv) -``` - -* inv: `table` or `string` or `number` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetEmptySlot.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetEmptySlot.mdx deleted file mode 100644 index 412179cc..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetEmptySlot.mdx +++ /dev/null @@ -1,9 +0,0 @@ -Get the first available empty slot in an inventory. - -```lua -exports.ox_inventory:GetEmptySlot(inv) -``` - -- inv: `table` or `string` or `number` - -**Returns:** `number?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetInventory.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetInventory.mdx deleted file mode 100644 index f71bcf39..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetInventory.mdx +++ /dev/null @@ -1,27 +0,0 @@ -Returns the inventory associated with the ID (and owner if defined). Otherwise returns null. - -```lua -exports.ox_inventory:GetInventory(inv, owner) -``` - -* inv: `number` or `table` -* owner?: `string` or `boolean` - -**Example:** - -```lua -local inventory = exports.ox_inventory:GetInventory('example_stash', false) -print(json.encode(inventory, {indent = true})) ---[[ - { - "id": "example_stash, - "label": "Police Stash", - "type": "stash, - "slots": 50, - "weight": 0, - "maxWeight": 100000, - "owner": false, - ... - } -]] -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetInventoryItems.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetInventoryItems.mdx deleted file mode 100644 index f74b656b..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetInventoryItems.mdx +++ /dev/null @@ -1,14 +0,0 @@ -Returns all slots with items in a inventory. - -```lua -exports.ox_inventory:GetInventoryItems(inv, owner) -``` - -* inv: `number` or `table` -* owner?: `string` or `boolean` - -**Example:** - -```lua -local playerItems = exports.ox_inventory:GetInventoryItems(source) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetItem.mdx deleted file mode 100644 index 00f5493f..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetItem.mdx +++ /dev/null @@ -1,36 +0,0 @@ -Returns _generic_ item data from the specified inventory, with the total count. - -```lua -exports.ox_inventory:GetItem(inv, item, metadata, returnsCount) -``` - -* inv: `table` or `string` or `number` -* item: `table` or `string` - * Can be items array. -* metadata?: `any` - * Only returns the count of items that strictly match the given metadata. -* returnsCount?: `boolean` - -If `returnsCount` is set to true, the returned value will be the `count` based on -how many times the item was found. - -Otherwise returns the data related to the item _and_ its total count found in the inventory. - -**Example**: - -```lua -local item = ox_inventory:GetItem(source, 'water', nil, false) - -print(json.encode(item, {indent=true})) ---[[ - { - "consume": 1, - "count": 15, - "stack": true, - "name": "water", - "weight": 500, - "label": "Water", - "close": true - } -]] -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetItemCount.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetItemCount.mdx deleted file mode 100644 index c97393bf..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetItemCount.mdx +++ /dev/null @@ -1,13 +0,0 @@ -Get the total item count for all items in an inventory with the given name and metadata. - -```lua -exports.ox_inventory:GetItemCount(inv, itemName, metadata, strict) -``` - -- inv: `table` or `string` or `number` -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `number?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetItemSlots.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetItemSlots.mdx deleted file mode 100644 index fa65bae0..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetItemSlots.mdx +++ /dev/null @@ -1,9 +0,0 @@ -Returns the number of slots the specified item is in, the item's total count and the remaining empty slots. - -```lua -exports.ox_inventory:GetItemSlots(inv, item, metadata) -``` - -* inv: `table` or `string` or `number` -* item: `table` or `string` -* metadata?: `table` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetSlot.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetSlot.mdx deleted file mode 100644 index 37336962..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetSlot.mdx +++ /dev/null @@ -1,29 +0,0 @@ -Returns the specified slot data as a table. - -```lua - -exports.ox_inventory:GetSlot(inv, slot) -``` - -* inv: `table` or `string` or `number` -* slot: `number` - -**Example:** - -```lua -local slot = exports.ox_inventory:GetSlot(source, 1) - -print(json.encode(slot, {indent=true})) ---[[ - { - "weight": 2000, - "name": "water", - "metadata": [], - "slot": 1, - "label": "Water", - "close": true, - "stack": true, - "count: 4 - } -]] -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetSlotForItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetSlotForItem.mdx deleted file mode 100644 index 029a44dc..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetSlotForItem.mdx +++ /dev/null @@ -1,11 +0,0 @@ -Get the slot id of an existing item matching the given data, or an empty slot. - -```lua -exports.ox_inventory:GetSlotForItem(inv, itemName, metadata) -``` - -- inv: `table` or `string` or `number` -- itemName: `string` -- metadata: `table?` - -**Returns:** `number?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetSlotIdWithItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetSlotIdWithItem.mdx deleted file mode 100644 index ce0cb404..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetSlotIdWithItem.mdx +++ /dev/null @@ -1,13 +0,0 @@ -Get a slot id in an inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotIdWithItem(inv, itemName, metadata, strict) -``` - -- inv: `table` or `string` or `number` -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `number?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetSlotIdsWithItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetSlotIdsWithItem.mdx deleted file mode 100644 index f77878cd..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetSlotIdsWithItem.mdx +++ /dev/null @@ -1,13 +0,0 @@ -Get all slot ids in an inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotIdsWithItem(inv, itemName, metadata, strict) -``` - -- inv: `table` or `string` or `number` -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `number[]?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetSlotWithItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetSlotWithItem.mdx deleted file mode 100644 index cf0628a7..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetSlotWithItem.mdx +++ /dev/null @@ -1,13 +0,0 @@ -Get data for a slot in an inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotWithItem(inv, itemName, metadata, strict) -``` - -- inv: `table` or `string` or `number` -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `table?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/GetSlotsWithItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/GetSlotsWithItem.mdx deleted file mode 100644 index 812f87c2..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/GetSlotsWithItem.mdx +++ /dev/null @@ -1,13 +0,0 @@ -Get data all slots in an inventory matching the given name and metadata. - -```lua -exports.ox_inventory:GetSlotsWithItem(inv, itemName, metadata, strict) -``` - -- inv: `table` or `string` or `number` -- itemName: `string` -- metadata?: `table` -- strict?: `boolean` - - Strictly match metadata properties, otherwise use partial matching. - -**Returns:** `table[]?` diff --git a/pages/ox_inventory/Functions/Server/Inventory/RegisterStash.mdx b/pages/ox_inventory/Functions/Server/Inventory/RegisterStash.mdx deleted file mode 100644 index 58b6fe0f..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/RegisterStash.mdx +++ /dev/null @@ -1,33 +0,0 @@ -import { Callout } from 'nextra/components'; - -Creates a new custom stash. - -```lua -exports.ox_inventory:RegisterStash(id, label, slots, maxWeight, owner, groups, coords) -``` - -- id: `string` or `number` - - Stash identifier when loading from the database. -- label: `string` - - Display name when inventory is open. -- slots: `number` -- maxWeight: `number` -- owner: `string` or `boolean` or `nil` - - `string`: Can only access the stash linked to the owner. - - `true`: Each player has a unique stash but can request other player's stashes. - - `nil`: Always shared. -- groups: `table` - - Table of player groups (jobs) able to access the stash. - - Table of group names where the numeric value is the minimum grade required. - - `{['police'] = 0, ['ambulance'] = 2}` -- coords?: `vector3` or `vector3[]` - - - -This function needs to be triggered before a player can open the stash. - - - -**Example:** - -For a use case example on this function check out the written [Guide](../../../Guides/stashes.md) for it. diff --git a/pages/ox_inventory/Functions/Server/Inventory/RemoveItem.mdx b/pages/ox_inventory/Functions/Server/Inventory/RemoveItem.mdx deleted file mode 100644 index 484c6a2e..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/RemoveItem.mdx +++ /dev/null @@ -1,35 +0,0 @@ -Removes the specified item from the specified inventory. - -```lua -exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot) -``` - -- inv: `table` or `string` or `number` - - The inventory's unique id, or a table with the id and owner. - - playerId: `1` - - inventoryId: `gloveVGH283` - - `{ id = 'personallocker', owner = 'license:xxxxxx'}` -- item: `string` - - The name of the item to remove from the target. -- count: `number` - - The number of items to remove. -- metadata?: `table` or `string` - - Only remove items with matching metadata properties. -- slot?: `number` - - A specific slot to remove the item from. If the slot is invalid, the first available slot will be used instead. -- cb?: function(success: `boolean`, response?: `string`) - -Returns success: `boolean`, response: `string?`. - -**Possible value of "response" on failure:** - -- "invalid_item": the item doesn't exist -- "invalid_inventory": the inventory doesn't exist -- "not_enough_items": inventory did not contain enough of the given item - -**Example:** - -```lua --- Removes 2 water from the glovebox for the given plate. -local success = exports.ox_inventory:RemoveItem('gloveVGH283', 'water', 2) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/ReturnInventory.mdx b/pages/ox_inventory/Functions/Server/Inventory/ReturnInventory.mdx deleted file mode 100644 index 455b93d3..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/ReturnInventory.mdx +++ /dev/null @@ -1,9 +0,0 @@ -Returns the confiscated inventory back to the player. - -Use it alongside [ConfiscateInventory](./ConfiscateInventory.md). - -```lua -exports.ox_inventory:ReturnInventory(source) -``` - -* source: `number` diff --git a/pages/ox_inventory/Functions/Server/Inventory/Search.mdx b/pages/ox_inventory/Functions/Server/Inventory/Search.mdx deleted file mode 100644 index 62bd5cc9..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/Search.mdx +++ /dev/null @@ -1,13 +0,0 @@ -Searches an inventory for a specified item. - -```lua -exports.ox_inventory:Search(inv, search, item, metadata) -``` - -* inv: `table` or `string` or `number` -* search: `string` -* item: `table` or `string` -* metadata?: `table` or `string` - -`search` can be either `'slots'` or `'count'`, where slots will return a table of data -and count will return the found amount of the specified item. diff --git a/pages/ox_inventory/Functions/Server/Inventory/SetDurability.mdx b/pages/ox_inventory/Functions/Server/Inventory/SetDurability.mdx deleted file mode 100644 index 1d3105a3..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/SetDurability.mdx +++ /dev/null @@ -1,27 +0,0 @@ -Sets durability onto the specified slot. - -Can be used for repairing weapons. - -```lua -exports.ox_inventory:SetDurability(inv, slot, durability) -``` - -* inv: `table` or `string` or `number` -* slot: `number` -* durability: `number` - -**Example:** - -```lua -local ox_inventory = exports.ox_inventory - --- Set the durability of the item in slot 3 of source player's inventory to 100 -ox_inventory:SetDurability(source, 3, 100) - --- Set the durability of the source player's current weapon to 100 -local weapon = ox_inventory:GetCurrentWeapon(source) - -if weapon then - ox_inventory:SetDurability(source, weapon.slot, 100) -end -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/SetMaxWeight.mdx b/pages/ox_inventory/Functions/Server/Inventory/SetMaxWeight.mdx deleted file mode 100644 index f0f8c5d2..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/SetMaxWeight.mdx +++ /dev/null @@ -1,17 +0,0 @@ -Sets the maximum weight available for an inventory. - -```lua -exports.ox_inventory:SetMaxWeight(inv, maxWeight) -``` - -* inv: `table` or `string` or `number` -* maxWeight: `number` - -**Example:** - -```lua -local ox_inventory = exports.ox_inventory - --- Set the max weight for player 1's inventory to 20kg. -ox_inventory:SetMaxWeight(1, 20000) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/SetMetadata.mdx b/pages/ox_inventory/Functions/Server/Inventory/SetMetadata.mdx deleted file mode 100644 index 06d4f160..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/SetMetadata.mdx +++ /dev/null @@ -1,27 +0,0 @@ -Sets metadata on the specified slot. - -```lua -ox_inventory:SetMetadata(inv, slot, metadata) -``` - -* inv: `table` or `string` or `number` -* slot: `number` -* metadata: `table` - -**Example:** - -```lua -local ox_inventory = exports.ox_inventory - -local water = ox_inventory:Search(source, 1, 'water') -for k, v in pairs(water) do - print('\n______________'..'\n- index '..k) - print(v.name, 'slot: '..v.slot, 'metadata: '..json.encode(v.metadata)) - water = v - break -end - -water.metadata.type = 'clean' -ox_inventory:SetMetadata(source, water.slot, water.metadata) -print(('modified %sx water in slot %s with new metadata'):format(water.count, water.slot)) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/SetSlotCount.mdx b/pages/ox_inventory/Functions/Server/Inventory/SetSlotCount.mdx deleted file mode 100644 index 0af88cd5..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/SetSlotCount.mdx +++ /dev/null @@ -1,17 +0,0 @@ -Sets the number of slots available for an inventory. - -```lua -exports.ox_inventory:SetSlotCount(inv, slots) -``` - -* inv: `table` or `string` or `number` -* slots: `number` - -**Example:** - -```lua -local ox_inventory = exports.ox_inventory - --- Set the slot count for player 1's inventory to 10. -ox_inventory:SetSlotCount(1, 10) -``` diff --git a/pages/ox_inventory/Functions/Server/Inventory/SwapSlots.mdx b/pages/ox_inventory/Functions/Server/Inventory/SwapSlots.mdx deleted file mode 100644 index dbed8b34..00000000 --- a/pages/ox_inventory/Functions/Server/Inventory/SwapSlots.mdx +++ /dev/null @@ -1,10 +0,0 @@ -Swaps slots in specified inventories. - -```lua -exports.ox_inventory:SwapSlots(fromInventory, toInventory, slot1, slot2) -``` - -* fromInventory: `table` or `string` or `number` -* toInventory: `table` or `string` or `number` -* slot1: `number` -* slot2: `number` diff --git a/pages/ox_inventory/Functions/Server/Items.mdx b/pages/ox_inventory/Functions/Server/Items.mdx deleted file mode 100644 index 1c1e4d42..00000000 --- a/pages/ox_inventory/Functions/Server/Items.mdx +++ /dev/null @@ -1,20 +0,0 @@ -Returns a table of all registered items. The format is as defined in [data/items.lua](https://github.com/overextended/ox_inventory/blob/main/data/items.lua). - -```lua -exports.ox_inventory:Items() -``` - -The following snippet can be used in crafting resources such as okokCrafting or core_crafting, rather than querying the database. - -```lua -local itemNames -ESX.RegisterServerCallback('crafting:itemNames', function(source, cb) - if not itemNames then - itemNames = {} - for item, data in pairs(exports.ox_inventory:Items()) do - itemNames[item] = data.label - end - end - cb(itemNames) -end) -``` diff --git a/pages/ox_inventory/Functions/Server/UpdateVehicle.mdx b/pages/ox_inventory/Functions/Server/UpdateVehicle.mdx deleted file mode 100644 index 03795194..00000000 --- a/pages/ox_inventory/Functions/Server/UpdateVehicle.mdx +++ /dev/null @@ -1,10 +0,0 @@ -# UpdateVehicle - -Update the internal reference to vehicle stashes, without triggering a save or updating the database. - -```lua -exports.ox_inventory:UpdateVehicle(oldPlate, newPlate) -``` - -* oldPlate: `string` -* newPlate: `string` diff --git a/pages/ox_inventory/Functions/Server/forceOpenInventory.mdx b/pages/ox_inventory/Functions/Server/forceOpenInventory.mdx deleted file mode 100644 index b1521ba6..00000000 --- a/pages/ox_inventory/Functions/Server/forceOpenInventory.mdx +++ /dev/null @@ -1,60 +0,0 @@ -import { Tabs, Tab } from 'nextra-theme-docs'; - -Opens an inventory using the passed data. -Forces a player to open an inventory, without usual security checks (groups, coords). - -```lua -exports.ox_inventory:forceOpenInventory(playerId, invType, data) -``` - -- playerId: `number` -- invType: `string` - - `'player'` - - `'stash'` - - `'container'` - - `'drop'` - - `'glovebox'` - - `'trunk'` - - `'dumpster'` -- data: `number` or `string` or `table` - - - - -**Open the target player's inventory.** - -```lua -exports.ox_inventory:forceOpenInventory(1, 'player', 3) -``` - -**Admin command to open a player's inventory.** - -```lua -RegisterCommand('openplayerinv', function(source, args) - exports.ox_inventory:forceOpenInventory(source, 'player', tonumber(args[1])) -end, true) -``` - - - - -**Open the first stash in [data/stashes](https://github.com/overextended/ox_inventory/blob/main/data/stashes.lua#L2-L19).** - -```lua -exports.ox_inventory:forceOpenInventory(1, 'stash', 'apartment420') -``` - -**Open a custom stash (created on the server with RegisterStash).** - -```lua -exports.ox_inventory:forceOpenInventory(1, 'stash', 'society_police') -``` - -**Open a stash with a specific owner.** - -```lua -exports.ox_inventory:forceOpenInventory(1, 'stash', { id = 'police_locker', owner = 'license:xxxxxxxx' }) -``` - - - diff --git a/pages/ox_inventory/Functions/Server/setPlayerInventory.mdx b/pages/ox_inventory/Functions/Server/setPlayerInventory.mdx deleted file mode 100644 index dcac7677..00000000 --- a/pages/ox_inventory/Functions/Server/setPlayerInventory.mdx +++ /dev/null @@ -1,15 +0,0 @@ -Creates and sets the player's inventory. - -```lua -exports.ox_inventory:setPlayerInventory(player, data) -``` - -* player: `table` - * source: `number` - * identifier: `string` - * name: `string` - * groups?: `table` - * sex?: `string` - * dateofbirth?: `string` -* data?: `table` - * If not provided will load player's inventory data from the db. diff --git a/pages/ox_inventory/Guides/crafting.mdx b/pages/ox_inventory/Guides/crafting.mdx index 69ff1a9c..e9199a33 100644 --- a/pages/ox_inventory/Guides/crafting.mdx +++ b/pages/ox_inventory/Guides/crafting.mdx @@ -1,5 +1,5 @@ --- -title: Creating crafting points +title: Crafting --- Crafting locations, items and their ingredients are defined in [data/crafting.lua](https://github.com/overextended/ox_inventory/blob/main/data/crafting.lua). @@ -42,33 +42,33 @@ Crafting locations, items and their ingredients are defined in [data/crafting.lu }, ``` -* items: `table` - * name: `string` - * ingredients: `table` - * Item ingredients can be seen in the item tooltip. - * Key-value pairs of item name and consume count - * key - Item name. - * value - If 1 or above it's the consume count, if below 1 and above 0 it's the durability consume amount, if +- items: `table` + - name: `string` + - ingredients: `table` + - Item ingredients can be seen in the item tooltip. + - Key-value pairs of item name and consume count + - key - Item name. + - value - If 1 or above it's the consume count, if below 1 and above 0 it's the durability consume amount, if set to 0 then the item is required but not consumed. - * duration: `number` - * Crafting duration in milliseconds. - * count: `number` - * Item amount received upon crafting. - * metadata: `table` - * Metadata applied to the item being crafted. -* points: `vector3[]` - * Interaction locations that will open the crafting inventory. -* groups: `table` - * Key-value pairs of job name and minimum grade to access the crafting location. - * `{["police"] = 0, ["ambulance"] = 2}` -* zones: `table` - * ox_lib targeting zones used for ox_target. - * coords: `vector3` - * size: `vector3` - * distance: `number` - * rotation: `number` -* blip: `table` - * id: `number` - * Blip sprite number. - * colour: `number` - * scale: `number` + - duration: `number` + - Crafting duration in milliseconds. + - count: `number` + - Item amount received upon crafting. + - metadata: `table` + - Metadata applied to the item being crafted. +- points: `vector3[]` + - Interaction locations that will open the crafting inventory. +- groups: `table` + - Key-value pairs of job name and minimum grade to access the crafting location. + - `{["police"] = 0, ["ambulance"] = 2}` +- zones: `table` + - ox_lib targeting zones used for ox_target. + - coords: `vector3` + - size: `vector3` + - distance: `number` + - rotation: `number` +- blip: `table` + - id: `number` + - Blip sprite number. + - colour: `number` + - scale: `number` diff --git a/pages/ox_inventory/Guides/stashes.mdx b/pages/ox_inventory/Guides/stashes.mdx index f94e822e..bd310756 100644 --- a/pages/ox_inventory/Guides/stashes.mdx +++ b/pages/ox_inventory/Guides/stashes.mdx @@ -1,5 +1,5 @@ --- -title: Creating custom stashes +title: Custom stashes --- import { GhButton } from '@components/button';