qb-inventory Events & Functions Reference
qb-inventory exposes a robust event API for spawning inventories, tracking item changes, and managing item boxes. This reference covers server-side and client-side events, exports, and common integration patterns with other QBCore resources.
Server Events
| Event Name | Parameters | Description |
|---|---|---|
qb-inventory:server:OpenInventory | inventoryType, inventoryId | Opens an inventory of a given type (player, trunk, stash, etc.) |
qb-inventory:server:CloseInventory | (none) | Closes the current inventory |
qb-inventory:server:AddItem | itemName, amount, slot, info | Adds an item to the playerβs inventory |
qb-inventory:server:RemoveItem | itemName, amount, slot | Removes an item from the playerβs inventory |
qb-inventory:server:SetInventoryData | fromInventory, fromData, toInventory, toData | Updates inventory slot data |
qb-inventory:server:GiveItem | targetId, itemName, amount, slot, info | Transfers an item to another player |
qb-inventory:server:TradeItems | targetId, items | Initiates a trade with another player |
Inventory:Server:OpenInventory
Triggers when a player opens any inventory type. Use this to enforce access rules, log stash access, or inject custom data.
RegisterNetEvent('qb-inventory:server:OpenInventory', function(inventoryType, inventoryId)
local src = source
if inventoryType == 'stash' then
print('^3[Inventory] ^7' .. GetPlayerName(src) .. ' opened stash: ' .. inventoryId)
end
end)qb-inventory:server:AddItem
Called when an item is being added. Hook into this for anti-dupe checks, logging, or rewarding achievements.
RegisterNetEvent('qb-inventory:server:AddItem', function(itemName, amount, slot, info)
local src = source
-- Audit rare items
if itemName == 'weapon_pistol' then
local Player = QBCore.Functions.GetPlayer(src)
print('^1[Inventory] ^7' .. Player.PlayerData.charinfo.firstname .. ' received a pistol')
end
end)qb-inventory:server:RemoveItem
Fires when an item is being removed. Validate the removal, update external systems, or trigger cleanup.
RegisterNetEvent('qb-inventory:server:RemoveItem', function(itemName, amount, slot)
local src = source
if amount > 100 then
print('^3[Inventory] ^7Bulk removal: ' .. itemName .. ' x' .. amount)
end
end)qb-inventory:server:GiveItem
Transfers an item between two players. The inventory validates both inventories before completing the trade.
RegisterNetEvent('qb-inventory:server:GiveItem', function(targetId, itemName, amount, slot, info)
local src = source
local Target = QBCore.Functions.GetPlayer(targetId)
if Target then
-- Log item transfers
print(GetPlayerName(src) .. ' gave ' .. itemName .. ' to ' ..
Target.PlayerData.charinfo.firstname)
end
end)Client Events
| Event Name | Parameters | Description |
|---|---|---|
qb-inventory:client:OpenInventory | inventoryType, inventoryId | Triggers the inventory UI to open on the client |
qb-inventory:client:CloseInventory | (none) | Closes the inventory UI |
qb-inventory:client:ItemBox | itemData, type | Shows an animated item box (add/remove notification) |
qb-inventory:client:UseItem | itemName, item | Fires when a player uses an item from the inventory |
qb-inventory:client:UpdateInventory | inventoryData | Pushes updated inventory data to the client |
qb-inventory:client:ShowWeaponSerial | weaponData | Displays the weapon serial number on pickup |
Inventory:Client:ItemBox
Displays the floating item notification when items are added or removed. Customize the display by hooking this event.
RegisterNetEvent('qb-inventory:client:ItemBox', function(itemData, type)
if type == 'add' then
print('Received: ' .. itemData.label .. ' x' .. itemData.amount)
elseif type == 'remove' then
print('Lost: ' .. itemData.label .. ' x' .. itemData.amount)
end
end)qb-inventory:client:UseItem
The main item usage event. Every usable item triggers this β perfect for adding custom item behaviors.
RegisterNetEvent('qb-inventory:client:UseItem', function(itemName, item)
if itemName == 'lockpick' then
-- Trigger lockpicking minigame
TriggerEvent('lockpick:client:startMinigame')
elseif itemName == 'repairkit' then
-- Repair nearest vehicle
local vehicle = QBCore.Functions.GetClosestVehicle()
if vehicle then
SetVehicleEngineHealth(vehicle, 1000)
QBCore.Functions.Notify('Vehicle repaired', 'success')
end
end
end)Server Exports (Functions)
| Export | Parameters | Description |
|---|---|---|
exports['qb-inventory']:AddItem(src, item, amount, slot, info) | src, item (string), amount, slot?, info? | Adds an item to a playerβs inventory |
exports['qb-inventory']:RemoveItem(src, item, amount, slot) | src, item, amount, slot? | Removes an item from inventory |
exports['qb-inventory']:GetItemsByName(src, item) | src, item | Returns all items of a given name |
exports['qb-inventory']:GetItemByName(src, item) | src, item | Returns the first matching item |
exports['qb-inventory']:HasItem(src, item, amount) | src, item, amount? | Checks if a player has an item |
AddItem
-- Basic item
exports['qb-inventory']:AddItem(source, 'bread', 5)
-- Item with metadata (weapon)
exports['qb-inventory']:AddItem(source, 'weapon_pistol', 1, false, {
durability = 100,
ammo = 12,
serial = 'ABC123'
})
-- Item with metadata (ID card)
exports['qb-inventory']:AddItem(source, 'id_card', 1, false, {
citizenid = Player.PlayerData.citizenid,
firstname = Player.PlayerData.charinfo.firstname,
lastname = Player.PlayerData.charinfo.lastname
})RemoveItem
-- Remove by name
exports['qb-inventory']:RemoveItem(source, 'bread', 2)
-- Remove from specific slot
exports['qb-inventory']:RemoveItem(source, 'phone', 1, 5)HasItem
if exports['qb-inventory']:HasItem(source, 'lockpick') then
TriggerClientEvent('QBCore:Notify', source, 'You can pick locks', 'success')
endClient Exports
| Export | Parameters | Description |
|---|---|---|
exports['qb-inventory']:OpenInventory() | (none) | Opens the playerβs own inventory |
exports['qb-inventory']:GetItemCount(item) | item (string) | Returns count of a specific item |
exports['qb-inventory']:HasItem(item, amount) | item, amount? | Checks if player has an item |
exports['qb-inventory']:GetCurrentWeight() | (none) | Returns current carry weight |
OpenInventory
-- Open player's own inventory
exports['qb-inventory']:OpenInventory()
-- Open trunk via exports
exports['qb-inventory']:OpenInventory('trunk', vehiclePlate)qs-inventory Compatibility
qb-inventory is the successor to qs-inventory. If youβre migrating from qs-inventory, most event names follow the same pattern. Key differences:
- Event prefix:
qb-inventory:instead ofqs-inventory: - Export namespace:
qb-inventoryinstead ofqs-inventory - Added durability system for weapons
- Updated database schema with
metadataandinfocolumns
-- qs-inventory (legacy)
exports['qs-inventory']:AddItem(source, 'bread', 1)
-- qb-inventory (current)
exports['qb-inventory']:AddItem(source, 'bread', 1)The qb-inventory resource must be started after qb-core and before any resources that depend on inventory functions, such as qb-shops, qb-houses, or qb-weapons.
Related Resources
- qb-inventory Full Documentation β Installation, configuration, and API
- qb-core Events β Core framework event reference
- qb-core Framework β Core function and system reference