exports.core_inventory:getItem(playerid, 'water')-- ORexports.core_inventory:getItem('stash-'.. Player.PlayerData.citizenid, 'water')-- OR exports.core_inventory:getItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water')
Return :
// if water is in the targeted inventory :{"image":"water_bottle.png","label":"Bottle of Water","amount":1,"unique":false,"description":"For all the thirsty out there","y":1,"x":1,"name":"water_bottle","metadata": {"id":"water_bottle-172736774735962" },"type":"item","slots": [6 ],"info": {"id":"water_bottle-172736774735962" },"count":1,"shouldClose":true,"weight":500,"useable":true,"ids": ["water_bottle-172736774735962" ]}// if water is not in the targeted inventory :// QBcore :nil// ESX :Same result as item is in ivnentory but amount / count will be set to 0// if item or inventory doesn't existnil
Parameters :
Name
Type
Description
inventory
string or number
string : the inventory name / number : the player id
itemName
string
name of the item you want to be retrieved
getItems
Return all items stack in a table or item with its specific informations (metadata, amount etc.)
exports.core_inventory:getItems(playerid, 'water')-- ORexports.core_inventory:getItems('stash-'.. Player.PlayerData.citizenid, 'water')-- OR exports.core_inventory:getItems('stash-'.. Player.getIdentifier():gsub(':',''), 'water')
Return :
// if water is in the targeted inventory :[ {"amount":1,"weight":500,"label":"Bottle of Water","image":"water_bottle.png","unique":false,"id":"water_bottle-172736774735962","name":"water_bottle","useable":true,"type":"item","info": {"id":"water_bottle-172736774735962" },"description":"For all the thirsty out there","shouldClose":true,"metadata": {"id":"water_bottle-172736774735962" },"count":1,"slot":6 }, {"amount":2,"weight":500,"label":"Bottle of Water","image":"water_bottle.png","unique":false,"id":"water_bottle-172736791061149","name":"water_bottle","useable":true,"type":"item","info": {"id":"water_bottle-172736791061149" },"description":"For all the thirsty out there","shouldClose":true,"metadata": {"id":"water_bottle-172736791061149" },"count":2,"slot":7 }]// if water is not in the targeted inventory :[]
Parameters :
Name
Type
Description
inventory
string or number
string : the inventory name / number : the player id
exports.core_inventory:getItemBySlot(playerid, 0)-- ORexports.core_inventory:getItemBySlot('stash-'.. Player.PlayerData.citizenid, 5)-- OR exports.core_inventory:getItemBySlot('stash-'.. Player.getIdentifier():gsub(':',''), 3)
Return :
// if there is an item in slot 0:{"type":"item","unique":false,"weight":500,"slot":0,"info": [],"id":"water_bottle-172736828738747","count":2,"shouldClose":true,"metadata": [],"description":"For all the thirsty out there","image":"water_bottle.png","label":"Bottle of Water","amount":2,"useable":true,"name":"water_bottle"}// if there is not an item in slot 0:nil
Parameters :
Name
Type
Description
inventory
string or number
string : the inventory name / number : the player id
slot
number
slot you want to retrieve in the inventory
getItemCount
Return count of specify item or items
Usage :
local count = exports.core_inventory:getItemCount(inventory, items)
exports.core_inventory:getFirstSlotByItem(playerid, 'water')-- ORexports.core_inventory:getFirstSlotByItem('stash-'.. Player.PlayerData.citizenid, 'water')-- OR exports.core_inventory:getFirstSlotByItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water')
Return :
// if water is in the targeted inventory in slot 7 and 33 :7// if water is not in the targeted inventory :nil
Parameters :
Name
Type
Description
inventory
string or number
string : the inventory name / number : the player id
item
string
name of the item you want to be retrieved
getItemsList
Return the list of items from items.lua / item dataabse and also the dynamic items create with registerDynamicItem export
Usage :
local items = exports.core_inventory:getItemsList()
Example :
local items = exports.core_inventory:getItemsList()
getInventory
Return all inventory items of the inventory
Usage :
exports.core_inventory:getInventory(inventory)
Example :
exports.core_inventory:getInventory(playerid)-- ORexports.core_inventory:getInventory('stash-'.. Player.PlayerData.citizenid)-- OR exports.core_inventory:getInventory('stash-'.. Player.getIdentifier():gsub(':',''))
Return :
// Example with items in inventory :[ {"ammotype":"AMMO_RIFLE","metadata": {"ammo":0,"serial":"AE701417","attachments": [],"aquired":"content-KXD43680","durability":100 },"count":1,"amount":1,"image":"weapon_assaultrifle_mk2.png","info": {"ammo":0,"serial":"AE701417","attachments": [],"aquired":"content-KXD43680","durability":100 },"category":"weapons","label":"Assault Rifle Mk II","useable":true,"unique":true,"slot":1,"weight":1000,"description":"Assault Rifle MK2","type":"weapon","name":"weapon_assaultrifle_mk2","id":"weapon_assaultrifle_mk2-172719708021772" }, {"id":"water_bottle-17273686944580","shouldClose":true,"info": [],"unique":false,"image":"water_bottle.png","count":2,"weight":500,"label":"Bottle of Water","ids": ["water_bottle-17273686944580" ],"slots": [0 ],"amount":2,"metadata": [],"description":"For all the thirsty out there","type":"item","name":"water_bottle","useable":true }]
Parameters :
Name
Type
Description
inventory
string or number
string : the inventory name / number : the player id
addItem
Add Item to a specific inventory
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. However, add will return false since item can't be added in inventory not loaded
Usage :
local itemsAdd = exports.core_inventory:addItem(inventory, item, amount, metadata, inventoryType)
// Empty table if only stack are increase // OR all created new stack on inventory// OR false if it can't be added // (inventory not load and type not define / no space in inventory)
Parameters :
Name
Type
Description
inventory
number or string
string : the inventory name / number : the player id
item
string
the item name you want to add
amount
number
the amount of item to add
metadata
table
metadata of the item on add
inventoryType
string
inventory type like 'content' or 'stash'
removeItem
Remove item in the inventory
Usage :
local removed = exports.core_inventory:removeItem(inventory, item, amount, inventoryType)
exports.core_inventory:clearAllInventory(Player.PlayerData.citizenid, Player.source)
-- OR
exports.core_inventory:clearAllInventory(Player.getIdentifier():gsub(':',''), source)
Parameters :
Name
Type
Description
identifier
string
hte player identifier without ':'
source
number?
if player is connected, pass the source to send the clear event if inventory is open, cna be nil
openLoot
Open a UI inventory with the loot item generated from what it was pass to it. This export will only generate a minimum and a maximum amount of item shared for each item listed in the table.
If you want to set minimun and maximum for each item, use openLootAdvanced
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
openLootAdvanced
Open a UI inventory with the loot item generated from what it was pass to it. This export allow you to set a minimum and maximum amount on each item if the chance is reached
Usage :
local inventoryName, lkootGenerated = exports.core_inventory:openLootAdvanced(source, inventoryType, lootTable, addAllSameItem, inventory, shouldRegenerate)
Example :
local inventoryName, lkootGenerated = exports.core_inventory:openLootAdvanced(playerid, 'stash',
{
{ name = "water_bottle", chance = 30, min = 3, max = 10},
{ name = "weapon_assaultrifle", chance = 5, max = 1, metadata = { ammo = 100, durability = 25.0 } },
{ name = "iron", chance = 50, min = 10, max = 20 }
}, false, nil, true)
Parameters :
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 :
{ { name = 'itemName', chance = chanceToBeEarn, min = minimumAmount, max = maximumAmount, metadata = { metadatas } }, { name = 'itemName', chance = chanceToBeEarn, min = minimumAmount, max = maximumAmount } }
for example :
{ name = "water_bottle", chance = 30, min = 3, max = 10}, { name = "weapon_assaultrifle", chance = 5, max = 1}}
Here you have 30% chance to have water bottle, 5% chance to have assault rifle
addAllSameItem
boolean
instead of adding item by item (if set to false), it will add the full amount of item directly for each item (full stacks of items)
inventory
string
name yo uwnat to give to the inventory if you plan to allow player to reopen loot inventory without regenerate the content
shouldRegenerate
boolean
if true, will regenerate the content of the loot inventory, if false and inventory set, will reopen the loot inventory in the state it have been closed
setDurability
Set the durabiltiy of an item if durability is set on hte metadata item
exports.core_inventory:setDurability('content-' .. Player.PlayerData.citizenid, 'weapon_pistol-34523', 50.0)
-- OR
exports.core_inventory:setDurability('primary-'.. Player.PlayerData.citizenid, 'weapon_pistol-34523', 100.0)
-- OR
exports.core_inventory:setDurability('stash-'.. Player.getIdentifier():gsub(':',''), 'weapon_pistol-34523', 10)
Parameters :
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:removeDurability('content-' .. Player.PlayerData.citizenid, 'weapon_pistol-34523', 50)
-- OR
exports.core_inventory:removeDurability('primary-'.. Player.PlayerData.citizenid, 'weapon_pistol-34523', 15)
-- OR
exports.core_inventory:removeDurability('stash-'.. Player.getIdentifier():gsub(':',''), 'weapon_pistol-34523', 10)
Parameters :
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:setMetadata(playerid, 1, { ammo = 50, durability = 100, serial = 'ERTDFG')
-- OR
exports.core_inventory:setMetadata('content-' .. Player.PlayerData.citizenid, 55, { ammo = 50, durability = 100, serial = 'ERTDFG')
-- OR
exports.core_inventory:setMetadata('primary-'.. Player.PlayerData.citizenid, 1, { ammo = 10, durability = 50, serial = 'XXXXX')
-- OR
exports.core_inventory:setMetadata('stash-'.. Player.getIdentifier():gsub(':',''), 0, { ammo = 150, durability = 100, serial = 'ERT-345-1')
Parameters :
Name
Type
Description
inventory
number / string
If number : player id
else inventory name where item is located like :
'content-' .. citizenid / identifier:gsub(':','') or
'stash-' .. citizenid / identifier:gsub(':','')
or
'primary-' .. citizenid / identifier:gsub(':','')
exports.core_inventory:updateMetadata(playerid, 'weapon_pistol-34523', { ammo = 50, durability = 100, serial = 'ERTDFG')
-- OR
exports.core_inventory:updateMetadata('content-' .. Player.PlayerData.citizenid, 'weapon_pistol-34523', { ammo = 50, durability = 100, serial = 'ERTDFG')
-- OR
exports.core_inventory:updateMetadata('primary-'.. Player.PlayerData.citizenid, 'weapon_pistol-34523', { ammo = 10, durability = 50, serial = 'XXXXX')
-- OR
exports.core_inventory:updateMetadata('stash-'.. Player.getIdentifier():gsub(':',''), 'weapon_pistol-34523', { ammo = 150, durability = 100, serial = 'ERT-345-1')
Parameters :
Name
Type
Description
inventory
number / string
If number : player id
else 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
confiscatePlayerInventory
Confiscate all the players inventory (save in another inventory). Use returnPlayerInventory to send back all the inventory.
Running this export multiple time without returning the player inventory before will remove the FIRST inventory saved of the player and can't be retrive anymore. Make sure to call it just once or return the player inventory before
true if all inventory have been saved and cleared on player
false if not (in case of error, all items will be set back to the player)
Parameters :
Name
Type
Description
source
number
server id of the player, need to be online
confiscateInventory
Confiscate the inventory pass as parameter. Use returnInventory to send back the inventory.
Running this export multiple time without returning the inventory before will remove the FIRST inventory saved and can't be retrive anymore. Make sure to call it just once or return the player inventory before
exports.core_inventory:confiscateInventory('stash-'.. Player.PlayerData.citizenid, source, 'stash')
-- OR
exports.core_inventory:confiscateInventory('primary-'.. Player.PlayerData.citizenid, nil, 'primary')
-- OR
exports.core_inventory:confiscateInventory('stash-'.. Player:getIdentifier():gsub(':',''), nil, 'stash')
Return :
true if everything is confiscated and cleared
Parameters :
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(':','')
Calling this export will delete ALL items from the inventory. If items are in the player inventory when you did this, they will be removed and can't be retrive anymore. Make sure to call it when player inventory is empty
Calling this export will delete ALL items from the inventory. If items are in the inventory when you did this, they will be removed and can't be retrive anymore. Make sure to call it when inventory is empty
exports.core_inventory:returnInventory('stash-'.. Player.PlayerData.citizenid, 'stash')
-- OR
exports.core_inventory:returnInventory('content-'.. Player.PlayerData.citizenid, 'content')
-- OR
exports.core_inventory:returnInventory('stash-'.. Player:getIdentifier():gsub(':',''), 'stash')
Return :
true if all items return
Parameters :
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(':','')
inventoryType
string
inventory type like 'primary' or 'secondry'
registerDynamicItem
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 etc.
exports.core_inventory:registerDynamicItem('custom-water', {
name = 'custom-water',
description = 'custom water use for custom thing',
category = 'uniqueItem',
x = 2,
y = 2
}, true)
Parameters :
Name
Type
Description
itemName
string
name of the item
itemData
table
item data that will be use to setup the item ( all qbcore shared item data or item database ciolumn can be used). If no category is add to the item, 'misc' is used by default