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
**Examples**
<Tabs items={['Player', 'Shop', 'Stash']}> Open the target player's inventory.
Open the fourth "General Store" [location](https://github.com/overextended/ox_inventory/blob/main/data/shops.lua#L14).
Open the first stash in [data/stashes](https://github.com/overextended/ox_inventory/blob/main/data/stashes.lua#L2-L19).
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.
closeInventory
Closes the player's inventory.
Items
Returns a table of all registered items. The format is as defined in data/items.lua.
Optionally takes the name of an item, returning only data for that item (getting all data is not recommended).
itemName?:
string
The following snippet can be used in crafting resources such as okokCrafting or core_crafting, rather than retrieving information from the server.
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.).
data:
tablecb?:
function
useSlot
Uses the item in the given inventory 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.
id:
stringornumberStash id.
owner?:
stringornumber
**Example**
getCurrentWeapon
Get data for the currently equipped weapon.
You can also listen for changes to the current weapon using an event handler.
currentWeapon?:
tableammo?:
stringName of the item used as ammo.hash:
numberlabel:
stringmelee:
booleanmetadata:
tableammo?:
numberAmount of ammo loaded into the weapon.components?:
tableArray of component item names, used to apply weapon components.durability?:
numberregistered?:
stringName of the player that bought the weapon at a shop.serial?:
string
name:
stringName of the item.slot:
numberweight:
number
displayMetadata
Sets a metadata property to display in the tooltip.
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?:
stringLabel for the string metadata property to be displayed.
**Example**
giveItemToTarget
Gives an item from the player's inventory to another player.
serverId:
numberThe serverId of the target player.
slotId:
numberThe slotId of the item to give.
count?:
numberThe amount of the item to give, with
nil,0or a value above the slot count giving the entire stack away.
weaponWheel
Enables the weapon wheel, but disables the use of inventory weapons.
Mostly used for weaponised vehicles, though could be called for "minigames"
state:
boolean
Search
Searches the inventory for an item, or list of items, with the result varying based on the first argument.
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:
tableorstringCan be a single item name or array of item names.
metadata?:
tableorstringIf metadata is provided as a string it will search the item's
metadata.typeproperty.
Count
<Tabs items={["Single item", "Multiple items"]}> 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"})
Slots
<Tabs items={["Single item", "Multiple items"]}> ```lua local water = exports.ox_inventory:Search('slots', 'water') local count = 0
```lua local items = exports.ox_inventory:Search('slots', {'meat', 'skin'}, 'deer')
GetItemCount
Get the total item count for all items in the player's inventory with the given name and metadata.
itemName:
stringmetadata?:
tablestrict?:
booleanStrictly match metadata properties, otherwise use partial matching.
Return:
count:
number
GetPlayerItems
Get all items in the player's inventory.
Return:
items:
table
GetPlayerWeight
Get the total weight of all items in the player's inventory.
Return:
totalWeight:
number
GetPlayerMaxWeight
Get the maximum carry weight of the player's inventory.
Return:
maxWeight:
number
GetSlotIdWithItem
Get a slot id in the player's inventory matching the given name and metadata.
itemName:
stringmetadata?:
tablestrict?:
booleanStrictly 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.
itemName:
stringmetadata?:
tablestrict?:
booleanStrictly 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.
itemName:
stringmetadata?:
tablestrict?:
booleanStrictly 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.
itemName:
stringmetadata?:
tablestrict?:
booleanStrictly match metadata properties, otherwise use partial matching.
Return:
slotsData:
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
Disable opening inventory
invHotkeys
Allows you to enable/disable a player's access to inventory hotkeys.
invHotkeys:
boolean
invOpen
Returns whether the player's inventory is currently open or not.
invOpen:
boolean
canUseWeapons
Allows you to enable/disable the use of weapons for a player.
Last updated