Events & Commands

This page is based on qb-inventory one, since we support almost all their exports to maximize the compatibility between us, qbcore and custom scripts from any developers.

All exports listed are SERVER only unless specified

Item Info

You can use SetItemData to achieve this

Items support additional information that can be added to them via an info attribute. This information will display on the item when the player hovers over it in a key,value pair format

Example:

Copy

RegisterCommand('addItemWithInfo', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    local info = {
        uniqueData1 = 'uniqueData1',
        uniqueData2 = 'uniqueData2',
        uniqueData3 = 'uniqueData3',
        uniqueData4 = 'uniqueData4',
    }
    exports['jpr-inventory']:AddItem(source, itemName, 1, false, info, 'jpr-inventory:testAdd')
end, true)

RegisterCommand('editItemWithInfo', function(source)
    local Player = QBCore.Functions.GetPlayer(source)
    if not Player then return end
    local items = Player.PlayerData.items
    local itemInfo = items[1]
    print(json.encode(itemInfo, { indent = true }))
    itemInfo.info = {
        newInfo = 'New Info'
    }
    print(json.encode(itemInfo, { indent = true }))
    items[1] = itemInfo
    Player.Functions.SetPlayerData('items', items)
end, true)

LoadInventory

This function will retrieve the players inventory from the database via their unique identifier aka citizenid

Copy

exports['jpr-inventory']:LoadInventory(source, citizenid)
  • source: number

  • citizenid: string

  • returns: table

Copy

RegisterCommand('getInv', function(source)
    local Player = QBCore.Functions.GetPlayer(source)
    local citizenId = Player.PlayerData.citizenid
    local items = exports['jpr-inventory']:LoadInventory(source, citizenid)
    print(json.encode(items, { indent = true }))
end)

SaveInventory

This function saves the players current items to the database

Copy

exports['jpr-inventory']:SaveInventory(source, offline)
  • source: number

  • offline: boolean

Example:

Copy

RegisterCommand('saveInv', function(source)
    exports['jpr-inventory']:SaveInventory(source, false)
end)

ClearInventory

Copy

exports['jpr-inventory']:ClearInventory(source, filterItems)
  • source: number

  • filterItems: string | table

Example:

Copy

RegisterCommand('clearInventoryExcludeItem', function(source, args)
    local filterItem = args[1]
    if not filterItem then return end
    exports['jpr-inventory']:ClearInventory(source, filterItem)
    print('Inventory cleared for player '..source..', excluding item: '..filterItem)
end, true)

RegisterCommand('clearInventoryExcludeItems', function(source)
    local filterItems = {'item1', 'item2'}
    exports['jpr-inventory']:ClearInventory(source, filterItems)
    print('Inventory cleared for player '..source..', excluding items: '..table.concat(filterItems, ', '))
end, true)

CloseInventory

Copy

exports['jpr-inventory']:CloseInventory(source, identifier)
  • source: number

  • identifier: string

Example:

Copy

RegisterCommand('closeInventory', function(source)
    exports['jpr-inventory']:CloseInventory(source)
    print('Inventory closed for player '..source)
end, true)

RegisterCommand('closeInventoryByName', function(source, identifier)
    exports['jpr-inventory']:CloseInventory(source, identifier)
    print('Inventory closed for player '..source..' and inventory '..identifier..' set to closed')
end, true)

OpenInventory

Copy

exports['jpr-inventory']:OpenInventory(source, identifier, data)
  • source: number

  • identifier: string | optional

  • data: table | optional

Example:

Copy

RegisterCommand('openinv', function(source)
    exports['jpr-inventory']:OpenInventory(source)
end, true)

RegisterCommand('openinvbyname', function(source, args)
    local inventoryName = args[1]
    exports['jpr-inventory']:OpenInventory(source, inventoryName)
end, true)

RegisterCommand('openinvbynamewithdata', function(source, args)
    local inventoryName = args[1]
    local data = { label = 'Custom Stash', maxweight = 400000, slots = 500 }
    exports['jpr-inventory']:OpenInventory(source, inventoryName, data)
end, true)

OpenInventoryById

Copy

exports['jpr-inventory']:OpenInventoryById(source, playerId)
  • source: number

  • playerId: number

Example:

Copy

RegisterCommand('openplayerinv', function(source, args)
    local playerId = tonumber(args[1])
    exports['jpr-inventory']:OpenInventoryById(source, playerId)
end, true)

OpenInventoryById will close the target players inventory (if open) and lock it via state. It will then unlock when the opening player closes it

CreateShop

Copy

exports['jpr-inventory']:CreateShop(shopData)
  • shopData: table

Copy

local items = {
    { name = 'sandwich', amount = 10, price = 5 }
}

RegisterCommand('createShop', function(source)
    local playerPed = GetPlayerPed(source)
    local playerCoords = GetEntityCoords(playerPed)
    exports['jpr-inventory']:CreateShop({
        name = 'testShop',
        label = 'Test Shop',
        coords = playerCoords, -- optional
        slots = #items,
        items = items
    })
end, true)

Coords being passed to createShop will be checked against the player's current coords when OpenShopis called if coords were provided during createShop

OpenShop

Copy

exports['jpr-inventory']:OpenShop(source, name)
  • source: number

  • name: string

Copy

RegisterCommand('openShop', function(source)
    exports['jpr-inventory']:OpenShop(source, 'testShop')
end)

AddItem

Copy

exports['jpr-inventory']:AddItem(identifier, item, amount, slot, info, reason)
  • identifier: number

  • item: string

  • amount: number

  • slot: number | boolean

  • info: table | boolean

  • reason: string

  • returns: boolean

Example:

Copy

RegisterCommand('addItem', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    exports['jpr-inventory']:AddItem(source, itemName, 1, false, false, 'jpr-inventory:testAdd')
end, true)

RemoveItem

Copy

exports['jpr-inventory']:RemoveItem(identifier, item, amount, slot, reason)
  • identifier: number

  • item: string

  • amount: number

  • slot: number | boolean

  • reason: string

  • returns: boolean

Copy

RegisterCommand('removeItem', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    exports['jpr-inventory']:RemoveItem(source, itemName, 1, false, 'jpr-inventory:testRemove')
end, true)

SetInventory

Copy

exports['jpr-inventory']:SetInventory(source, items)
  • source: number

  • items: table

Example:

Copy

RegisterCommand('setInventory', function(source)
    local items = {
        {
            name = 'sandwich',
            amount = 10,
            type = 'item',
            info = {},
            slot = 1
        },
        {
            name = 'water_bottle',
            amount = 10,
            type = 'item',
            info = {},
            slot = 2
        }
    }
    exports['jpr-inventory']:SetInventory(source, items)
end, true)

SetItemData

This function uses GetItemByName to find the itemName being passed

Copy

exports['jpr-inventory']:SetItemData(source, itemName, key, val)
  • source: number

  • itemName: string

  • key: string

  • val: string | table

  • returns: boolean

Example:

Copy

RegisterCommand('setItemData', function(source, args)
    local itemName = args[1]
    local key = args[2]
    local val = args[3]
    if not itemName or not key or not val then return end
    local success = exports['jpr-inventory']:SetItemData(source, itemName, key, val)
    if success then
        print('Set data for item '..itemName..': '..key..' = '..val)
    else
        print('Failed to set data for item '..itemName)
    end
end, true)

Item Info Example:

Copy

RegisterCommand('setItemData', function(source)
    local itemName = 'markedbills'
    local key = 'info'
    local val = { worth = 1000 }
    if not itemName or not key or not val then return end
    local success = exports['jpr-inventory']:SetItemData(source, itemName, key, val)
    if success then
        print('Set data for item '..itemName..': '..key..' = '..json.encode(val, { indent = true }))
    else
        print('Failed to set data for item '..itemName)
    end
end, true)

UseItem

Copy

exports['jpr-inventory']:UseItem(itemName, ...)
  • itemName: string

  • . . . : function

Example:

Copy

RegisterCommand('useItem', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    exports['jpr-inventory']:Useitem(itemName, function()
        print('Used item with the name of '..itemName)
    end)
end, true)

HasItem

This export is also available to use on the client

Copy

exports['jpr-inventory']:HasItem(source, items, amount)
  • source: number

  • items: string | table

  • amount: number

  • returns: boolean

Example:

Copy

RegisterCommand('hasSingleItem', function(source)
    local item = 'item1'
    local amount = 5
    local hasItem = exports['jpr-inventory']:HasItem(source, item, amount)
    if hasItem then
        print('Player '..source..' has '..amount..' of '..item)
    else
        print('Player '..source..' does not have '..amount..' of '..item)
    end
end, true)

RegisterCommand('hasMultipleItems', function(source)
    local items = {'item1', 'item2'}
    local amount = 5
    local hasItems = exports['jpr-inventory']:HasItem(source, items, amount)
    if hasItems then
        print('Player '..source..' has '..amount..' of each item: '..table.concat(items, ', '))
    else
        print('Player '..source..' does not have '..amount..' of each item: '..table.concat(items, ', '))
    end
end, true)

RegisterCommand('hasMultipleItemsWithAmounts', function(source)
    local itemsWithAmounts = {item1 = 5, item2 = 10}
    local hasItemsWithAmounts = exports['jpr-inventory']:HasItem(source, itemsWithAmounts)
    if hasItemsWithAmounts then
        print('Player '..source..' has the specified items with their amounts')
    else
        print('Player '..source..' does not have the specified items with their amounts')
    end
end, true)

GetSlotsByItem

Copy

exports['jpr-inventory']:GetSlotsByItem(items, itemName)
  • items: table

  • itemName: string

  • returns: table

Example:

Copy

RegisterCommand('getSlots', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    local Player = QBCore.Functions.GetPlayer(source)
    local items = Player.PlayerData.Items
    local slots = exports['jpr-inventory']:GetSlotsByItem(items, itemName)
    for _, slot in ipairs(slots) do
        print(slot)
    end
end, true)

GetFirstSlotByItem

Copy

exports['jpr-inventory']:GetFirstSlotByItem(items, itemName)
  • items: table

  • itemName: string

  • returns: number

Example:

Copy

RegisterCommand('getFirstSlot', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    local Player = QBCore.Functions.GetPlayer(source)
    local items = Player.PlayerData.Items
    local slot = exports['jpr-inventory']:GetFirstSlotByItem(items, itemName)
    if slot then
        print('First slot containing item '..itemName..' is: '..slot)
    else
        print('No slot found containing item '..itemName)
    end
end, true)

GetItemBySlot

Copy

exports['jpr-inventory']:GetItemBySlot(source, slot)
  • source: number

  • slot: number

  • returns: table

Example:

Copy

RegisterCommand('getItem', function(source, args)
    local slot = tonumber(args[1])
    if not slot then return end
    local item = exports['jpr-inventory']:GetItemBySlot(source, slot)
    if item then
        print('Item in slot '..slot..' is: '..item.name)
    else
        print('No item found in slot '..slot)
    end
end, true)

GetItemByName

Copy

exports['jpr-inventory']:GetItemByName(source, item)
  • source: number

  • item: string

  • returns: table

Example:

Copy

RegisterCommand('getItemByName', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    local item = exports['jpr-inventory']:GetItemByName(source, itemName)
    if item then
        print('First occurrence of item '..itemName..' is in slot: '..item.slot)
    else
        print('No item found with name '..itemName)
    end
end, true)

GetItemsByName

Copy

exports['jpr-inventory']:GetItemsByName(source, item)
  • source: number

  • item: string

  • returns: table

Example:

Copy

RegisterCommand('getItemsByName', function(source, args)
    local itemName = args[1]
    if not itemName then return end
    local items = exports['jpr-inventory']:GetItemsByName(source, itemName)
    if #items > 0 then
        print('Items named '..itemName..' found in slots:')
        for _, item in ipairs(items) do
            print(item.slot)
        end
    else
        print('No items found with name '..itemName)
    end
end, true)

Last updated