🧬
API
Integrate this awsome inventory with more of your scripts
Use these exports in server side from other scripts :
exports['core_inventory']:openHolder(source, inventoryname, inventorytype, x, y, open, content)
open the UI with the holder or preload the holder data if
open = false
Name | Type | Description |
---|---|---|
source | number | server id of the player |
inventoryname | string | inventory name like 'primary-'.. citizenid / identifier:gsub(':','') |
inventorytype | string | inventory type like 'primary' or 'secondry' |
x | number | position in pixel on the screen horizontally |
y | number | position in pixel on the screen vertically |
open | boolean | define if the holder should be open (display) or just preopen (load) |
content | table | the default content of the holder (return the content of the holder if it already exist) |
exports['core_inventory']:openInventory(source, inventoryname, inventorytype, x, y, open, content)
Open the UI with the inventory or preload the inventory data if
open = false
Name | Type | Description |
---|---|---|
source | number | server id of the player |
inventoryname | string | inventory name like :
'content-'.. citizenid / identifier:gsub(':','')
or
'stash-'.. citizenid / identifier:gsub(':','') |
inventorytype | string | inventory type like 'content' or 'stash' |
x | number | position in pixel on the screen horizontally |
y | number | position in pixel on the screen vertically |
open | boolean | define if the inventory should be open (display) or just preopen (load) |
content | table | the default content of the inventory (return the content of the inventory if it already exist) |
exports['core_inventory']:getInventory(inventory)
The inventory data in a table
Name | Type | Description |
---|---|---|
inventory | string | inventory name like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
exports['core_inventory']:addItem(inventory, item, amount, metadata, inventoryType)
If you want to add an item in an inventory never open / load, add the inventory type as last parameter, so the inventory will be load and the item will be add in the inventory.
A table with all the items add with their values
Name | Type | Description |
---|---|---|
inventory | string | inventory name like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
item | string | the item name you want to add |
amount | number | the amount of item to remove |
metadata | table | metadata of the item modify |
inventoryType | string | inventory type like 'content' or 'stash' |
exports['core_inventory']:removeItemExact(inventory, itemId, amount)
Name | Type | Description |
---|---|---|
inventory | string | inventory name like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
itemId | string | The item id, not the item name like weapon_pistol-123456 |
amount | number | the amount of item to remove |
exports['core_inventory']:removeDurability(inventory, itemId, amount)
Name | Type | Description |
---|---|---|
inventory | string | inventory name where item is located like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
itemId | string | The item id, not the item name like weapon_pistol-123456 |
amount | number | The durability to remove from the item. make sure that you the amount is not greater than the remaining durability |
exports['core_inventory']:setDurability(inventory, itemId, amount)
Name | Type | Description |
---|---|---|
inventory | string | inventory name where item is located like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
itemId | string | The item id, not the item name like weapon_pistol-123456 |
amount | number | The durability set to the item. Can't be greater than 100 |
exports['core_inventory']:updateMetadata(inventory, itemId, metadata)
Name | Type | Description |
---|---|---|
inventory | string | inventory name where item is located like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
itemId | number | The item id, not the item name like weapon_pistol-123456 |
metadata | table | metadata of the item modify |
Loot inventory is a temporary inventory that can be triggered to reward the player with an item.
exports['core_inventory']:openLoot(source, inventorytype, lootTable, minItems, maxItems)
open the UI with the generated loot inventory with the item in it
Name | Type | Description |
---|---|---|
source | number | server id of the player |
inventorytype | string | any inventory type you have in your core inventory config file like :
'content'
'stash'
'big_storage' etc. |
loottable | table | a table like :
{ { 'itemName', chanceToBeEarn }, { 'itemName', chanceToBeEarn} }
for example :
{{"water_bottle", 30},{"weapon_assaultrifle", 5},{"iron", 50}}
Here you have 30% chance to have water bottle , 5% chance to have assault rifle , 50% chance to have iron |
minItems | number | minimum item add in the inventory if the player have chance to earn it |
maxItems | number | maximum item add to the inventory if the player have chance to earn it |
exports['core_inventory']:getItem(inventory, itemName)
Returns item quantity and general information but only returns one items metadata
Name | Type | Description |
---|---|---|
inventory | string | inventory name where item is located like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
itemName | string | name of the item you want to retrieve |
exports['core_inventory']:getItems(inventory, item)
Retuns every item (or stack) with their own specific metadata in a tablehea
Name | Type | Description |
---|---|---|
inventory | string | inventory name where item is located like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','') |
itemName | string | name of the item you want to retrieve |
Use callback in client side from other scripts
ESX
QB
ESX.TriggerServerCallback('core_inventory:server:getInventory', function(inventory)
for _,v in ipairs(inventory) do
print(v.id)
print(v.name)
print(v.metadata)
end
end)
QBCore.TriggerCallback('core_inventory:server:getInventory', function(inventory)
for _,v in ipairs(inventory) do
print(v.id)
print(v.name)
print(v.metadata)
end
end)
For now there are 2 ways of getting clothing to your inventory. The first one is using Core Clothing script. Another is to use a command or export to add item with example metadata shown below.
/giveitem (id) torso 1 {"mTorso":15,"mID":11,"mTexture":1,"mModel":14}
Items that are not registered in items.lua or in items table. They can be added with a trigger where you define label, category, x, y, description... in itemData field
TriggerServerEvent('core_inventory:server:addDynamicItem', item, amount, metadata, inventory, itemData)
Opening an inventory is super easy and can be done for anything.
Make sure inventory type exists in config
To open private inventory no one can access with same trigger add identifier/citizenid to inventory name "cupboard-" .. Player.PlayerData.citizenid
TriggerServerEvent('core_inventory:server:openInventory', inventoryname, inventorytype)
Name | Type | Description |
---|---|---|
inventoryname | string | inventory name like
'police_storage'
'cupboard-' .. citizenid |
inventorytype | string | any inventory type you have in your core inventory config file like :
'content'
'stash'
'big_storage' etc. |
Can be added to your radial menu or any other script you use works by default with qb-core
TriggerServerEvent('core_inventory:server:openInventory', playerid, 'otherplayer', nil, nil, withCloth)
Name | Type | Description |
---|---|---|
playerid | number | server id of the player you want to search |
withCloth | boolean | true will open the other player cloth slot if Disable clothing is not set to true in the config |
Last modified 5mo ago