Inventories

How the wheel reads your inventory, and how to plug your own.

The wheel never touches the items itself: it reads the inventory of the player and asks the inventory to use the item, exactly like a hotbar would. Every rule of your inventory (durability, item callbacks, weapon animations) still applies.

InventoryItemsUseImages
ox_inventoryGetPlayerItemsuseSlotnui://ox_inventory/web/images/
qb-inventory 2.xPlayer dataqb-inventory:server:useItemnui://qb-inventory/html/images/
qb / ps / lj-inventory 1.xPlayer datainventory:server:UseItemSlotnui://<resource>/html/images/
qs-inventorygetUserInventoryinventory:server:UseItemSlotnui://qs-inventory/html/images/
ESX defaultinventory + loadoutesx:useItem / weapon in handnone, set Config.Images.path

Weapons or items#

An item goes on the weapons wheel when the inventory marks it as a weapon, or when its name starts with WEAPON_. Everything else goes on the items wheel.

Ammo#

For a weapon in hand, the ammo in the clip and the ammo left come from the game. Otherwise the wheel shows the ammo saved by the inventory (metadata.ammo on ox_inventory, info.ammo on qb-inventory). On ox_inventory the reserve is the amount of the ammo item of the weapon.

Custom inventory#

Set Config.Inventory = 'custom' and fill client/inventory/custom.lua:

client/inventory/custom.luaLua
Inventory.ImagePath = 'nui://my_inventory/html/images/'

function Inventory.GetItems()
    local items = {}

    for _, item in pairs(exports.my_inventory:GetItems()) do
        items[#items + 1] = {
            name = item.name,
            label = item.label,
            count = item.amount,
            slot = item.slot,
            weapon = item.type == 'weapon',
            ammo = item.info and item.info.ammo,
            image = item.image,
        }
    end

    return items
end

function Inventory.UseItem(item)
    TriggerServerEvent('my_inventory:useSlot', item.slot)
end

function Inventory.Disarm()
    SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`, true)
end

InventoryItem:

  • name: string - also used to save the wheel
  • label?: string
  • count: number - items at 0 are ignored
  • slot?: number - given back to Inventory.UseItem
  • weapon?: boolean
  • ammo?: number - ammo loaded in the weapon
  • reserve?: number - ammo left in the inventory
  • image?: string - file name (pistol.png) or full url (https://, nui://)
  • description?: string

Tell the wheel when the inventory changes so it removes the items the player lost:

Lua
TriggerEvent('cube_itemswheel:inventoryChanged')
Tip

The wheel also refreshes when it opens and after each use, so this event is optional - it only makes the cleanup instant.