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
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)
RegisterCommand('setItemData', function(source,args)local itemName = args[1]local key = args[2]local val = args[3]ifnot itemName ornot key ornot val thenreturnendlocal success = exports['jpr-inventory']:SetItemData(source, itemName, key, val)if success thenprint('Set data for item '..itemName..': '..key..' = '..val)elseprint('Failed to set data for item '..itemName)endend, true)
Item Info Example:
Copy
RegisterCommand('setItemData', function(source)local itemName ='markedbills'local key ='info'local val = { worth =1000 }ifnot itemName ornot key ornot val thenreturnendlocal success = exports['jpr-inventory']:SetItemData(source, itemName, key, val)if success thenprint('Set data for item '..itemName..': '..key..' = '..json.encode(val, { indent =true }))elseprint('Failed to set data for item '..itemName)endend, true)
UseItem
Copy
exports['jpr-inventory']:UseItem(itemName, ...)
itemName: string
. . . : function
Example:
Copy
RegisterCommand('useItem', function(source,args)local itemName = args[1]ifnot itemName thenreturnend 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
RegisterCommand('hasSingleItem', function(source)local item ='item1'local amount =5local hasItem = exports['jpr-inventory']:HasItem(source, item, amount)if hasItem thenprint('Player '..source..' has '..amount..' of '..item)elseprint('Player '..source..' does not have '..amount..' of '..item)endend, true)RegisterCommand('hasMultipleItems', function(source)local items = {'item1', 'item2'}local amount =5local hasItems = exports['jpr-inventory']:HasItem(source, items, amount)if hasItems thenprint('Player '..source..' has '..amount..' of each item: '..table.concat(items, ', '))elseprint('Player '..source..' does not have '..amount..' of each item: '..table.concat(items, ', '))endend, true)RegisterCommand('hasMultipleItemsWithAmounts', function(source)local itemsWithAmounts = {item1 =5, item2 =10}local hasItemsWithAmounts = exports['jpr-inventory']:HasItem(source, itemsWithAmounts)if hasItemsWithAmounts thenprint('Player '..source..' has the specified items with their amounts')elseprint('Player '..source..' does not have the specified items with their amounts')endend, true)
RegisterCommand('getItemByName', function(source,args)local itemName = args[1]ifnot itemName thenreturnendlocal item = exports['jpr-inventory']:GetItemByName(source, itemName)if item thenprint('First occurrence of item '..itemName..' is in slot: '..item.slot)elseprint('No item found with name '..itemName)endend, true)
RegisterCommand('getItemsByName', function(source,args)local itemName = args[1]ifnot itemName thenreturnendlocal items = exports['jpr-inventory']:GetItemsByName(source, itemName)if#items >0thenprint('Items named '..itemName..' found in slots:')for _, item inipairs(items) doprint(item.slot)endelseprint('No items found with name '..itemName)endend, true)