Client
openInventory#
Opens an inventory using the passed data.
exports.ox_inventory:openInventory(invType, data)- invType:
string'player''shop''stash''crafting''container''drop''glovebox''trunk''dumpster'
- data:
numberorstringortable
<u>Examples</u>
Open the target player's inventory.
exports.ox_inventory:openInventory('player', 3)Open the fourth "General Store" location.
exports.ox_inventory:openInventory('shop', { type = 'General', id = 4 })Open the first stash in data/stashes.
exports.ox_inventory:openInventory('stash', 1)Open a custom stash (created on the server with RegisterStash).
exports.ox_inventory:openInventory('stash', 'society_police')Open a stash with a specific owner.
exports.ox_inventory:openInventory('stash', { id = 'police_locker', owner = 'license:xxxxxxxx' })Opens the second location of the debug_crafting recipe.
exports.ox_inventory:openInventory('crafting', { id = 'debug_crafting', id = 2 })Opens the number 1 evidence locker.
exports.ox_inventory:openInventory('policeevidence', 1)Opens a dialog to select the evidence locker.
exports.ox_inventory:openInventory('policeevidence')Opens the glovebox of a vehicle.
local netid = NetworkGetNetworkIdFromEntity(cache.vehicle)
exports.ox_inventory:openInventory('glovebox', { netid = netid })Opens the trunk of a vehicle.
local netid = NetworkGetNetworkIdFromEntity(cache.vehicle)
exports.ox_inventory:openInventory('trunk', { netid = netid })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.).
exports.ox_inventory:useItem(data, cb)- data:
table - cb?:
function
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.
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.
exports.ox_inventory:setStashTarget(id, owner)- id:
stringornumber- Stash id.
- owner?:
stringornumber
<u>Example</u>
exports.ox_inventory:setStashTarget('motel5', 'bobsmith')getCurrentWeapon#
Get data for the currently equipped weapon.
exports.ox_inventory:getCurrentWeapon()You can also listen for changes to the current weapon using an event handler.
AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon)
CurrentWeapon = currentWeapon
end)- currentWeapon?:
table- ammo?:
stringName of the item used as ammo. - hash:
number - label:
string - melee:
boolean - metadata:
table- ammo?:
numberAmount of ammo loaded into the weapon. - components?:
tableArray of component item names, used to apply weapon components. - durability?:
number - registered?:
stringName of the player that bought the weapon at a shop. - serial?:
string
- ammo?:
- name:
stringName of the item. - slot:
number - weight:
number
- ammo?:
displayMetadata#
Sets a metadata property to display in the tooltip.
exports.ox_inventory:displayMetadata(metadata, value)- metadata:
stringortable<string, string>or{ [string], [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.
- Can be an array of string arrays, i.e.
{ {'key', 'label' }, {'key2', 'label2' }to set the display order.
- value?:
string- Label for the string metadata property to be displayed.
<u>Example</u>
exports.ox_inventory:displayMetadata('mustard', 'Mustard')exports.ox_inventory:displayMetadata({
mustard = 'Mustard',
ketchup = 'Ketchup'
})giveItemToTarget#
Gives an item from the player's inventory to another player.
exports.ox_inventory:giveItemToTarget(serverId, slotId, count)- serverId:
number- The serverId of the target player.
- slotId:
number- The slotId of the item to give.
- count?:
number- The amount of the item to give, with
nil,0or a value above the slot count giving the entire stack away.
- The amount of the item to give, with
weaponWheel#
Enables the weapon wheel, but disables the use of inventory weapons.
Mostly used for weaponised vehicles, though could be called for "minigames"
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.
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 itemsreturns key-value pairs of itemName = count.
- item:
tableorstring- Can be a single item name or array of item names.
- metadata?:
tableorstring- If metadata is provided as a string it will search the item's
metadata.typeproperty.
- If metadata is provided as a string it will search the item's
Count#
local count = exports.ox_inventory:Search('count', 'water')
print('You have '..count.. ' water')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
endSlots#
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')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
endGetItemCount#
Get the total item count for all items in the player's inventory with the given name and metadata.
exports.ox_inventory:GetItemCount(itemName, metadata, strict)- itemName:
string - metadata?:
table - strict?:
boolean- Strictly match metadata properties, otherwise use partial matching.
Return:
- count:
number
GetPlayerItems#
Get all items in the player's inventory.
exports.ox_inventory:GetPlayerItems()Return:
- items:
table
GetPlayerWeight#
Get the total weight of all items in the player's inventory.
exports.ox_inventory:GetPlayerWeight()Return:
- totalWeight:
number
GetPlayerMaxWeight#
Get the maximum carry weight of the player's inventory.
exports.ox_inventory:GetPlayerMaxWeight()Return:
- maxWeight:
number
GetSlotIdWithItem#
Get a slot id in the player's inventory matching the given name and metadata.
exports.ox_inventory:GetSlotIdWithItem(itemName, metadata, strict)- itemName:
string - metadata?:
table - strict?:
boolean- Strictly match metadata properties, otherwise use partial matching.
Return:
- slotId:
number?
GetSlotsIdWithItem#
Get all slot ids in the player's inventory matching the given name and metadata.
exports.ox_inventory:GetSlotIdsWithItem(itemName, metadata, strict)- itemName:
string - metadata?:
table - strict?:
boolean- Strictly match metadata properties, otherwise use partial matching.
Return:
- slotIds:
number[]?
GetSlotWithItem#
Get data for a slot in the player's inventory matching the given name and metadata.
exports.ox_inventory:GetSlotWithItem(itemName, metadata, strict)- itemName:
string - metadata?:
table - strict?:
boolean- Strictly match metadata properties, otherwise use partial matching.
Return:
- slotData:
table?
GetSlotsWithItem#
Get data all slots in the player's inventory matching the given name and metadata.
exports.ox_inventory:GetSlotsWithItem(itemName, metadata, strict)- itemName:
string - metadata?:
table - strict?:
boolean- Strictly match metadata properties, otherwise use partial matching.
Return:
- slotsData:
table[]?
supressItemNotifications#
Allows you to enable or disable NUI item notifications
exports.ox_inventory:suppressItemNotifications(value)- value:
boolean
setGetPlayerNameMethod#
Allows you to define a custom function to display the player name when giving with the playerlist.
exports.ox_inventory:setGetPlayerNameMethod(function (serverId --[[ @as number ]])
local playerName = GetPlayerName(serverID)
return ('[%d] %s'):format(serverID, playerName)
end)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
local invBusy = LocalPlayer.state.invBusy
if invBusy then
-- Do stuff when busy
else
-- Do stuff when not busy
endDisable opening inventory#
LocalPlayer.state.invBusy = trueinvHotkeys#
Allows you to enable/disable a player's access to inventory hotkeys.
- invHotkeys:
boolean
LocalPlayer.state.invHotkeys = falseinvOpen#
Returns whether the player's inventory is currently open or not.
- invOpen:
boolean
local invOpen = LocalPlayer.state.invOpen
if invOpen then
-- Do stuff when open
else
-- Do stuff when closed
endinstance#
Is used to define if a player is in a specific instance (i.e. property, arena) where drops should be isolated.
- instance:
string|number|nil
LocalPlayer.state.instance = "property_1"canUseWeapons#
Allows you to enable/disable the use of weapons for a player.
LocalPlayer.state.canUseWeapons = false