📂Server

getItem

Return all item information group in only one item

Usage :

exports.core_inventory:getItem(inventory, itemName)

Example :

exports.core_inventory:getItem(playerid, 'water')
-- OR
exports.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 exist
nil

Parameters :


getItems

Return all items stack in a table or item with its specific informations (metadata, amount etc.)

Usage :

exports.core_inventory:getItems(inventory, itemName)

Example :

exports.core_inventory:getItems(playerid, 'water')
-- OR
exports.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 :


getItemBySlot

Return the item at this slot

Usage :

exports.core_inventory:getItemBySlot(inventory, slot)

Example :

exports.core_inventory:getItemBySlot(playerid, 0)
-- OR
exports.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 :


getItemCount

Return count of specify item or items

Usage :

local count = exports.core_inventory:getItemCount(inventory, items)

Example :

exports.core_inventory:getItemCount(playerid, 'water')
-- OR
exports.core_inventory:getItemCount('stash-'.. Player.PlayerData.citizenid, { 'water', 'juice' })
-- OR 
exports.core_inventory:getItemCount('stash-'.. Player.getIdentifier():gsub(':',''), 'juice')

Return :

// if water is in the targeted inventory (amount = 2):
2
// if water is not in the targeted inventory :
0

Parameters :


getSlotByItem

Return all slot for the item and a total count of items

Usage :

local slots, totalCount = exports.core_inventory:getSlotsByItem(inventory, item)

Example :

exports.core_inventory:getSlotsByItem(playerid, 'water')
-- OR
exports.core_inventory:getSlotsByItem('stash-'.. Player.PlayerData.citizenid, 'water')
-- OR 
exports.core_inventory:getSlotsByItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water')

Return :

// if water is in the targeted inventory at slot 7 and 33:
[ 7, 33 ]
// if water is not in the targeted inventory :
[]

Parameters :


getFirstSlotByItem

Return the first slot for the item

Usage :

exports.core_inventory:getFirstSlotByItem(inventory, item)

Example :

exports.core_inventory:getFirstSlotByItem(playerid, 'water')
-- OR
exports.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 :


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)
-- OR
exports.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 :


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)

Example :

exports.core_inventory:addItem(playerid, 'water', 1)
-- OR
exports.core_inventory:addItem('stash-'.. Player.PlayerData.citizenid, 'water', 1 , { uses = 5 }, 'stash')
-- OR 
exports.core_inventory:addItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water', 5 , { uses = 10, time = os.time() }, 'stash')

Return :

// 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 :


removeItem

Remove item in the inventory

Usage :

local removed = exports.core_inventory:removeItem(inventory, item, amount, inventoryType)

Example :

exports.core_inventory:removeItem(playerid, 'water', 1)
-- OR
exports.core_inventory:removeItem('stash-'.. Player.PlayerData.citizenid, 'water', 1, 'stash')
-- OR 
exports.core_inventory:removeItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water', 1, 'stash')

Return :

true or false if item is removed or not

Parameters :


removeItemExact

Remove item in the inventory by item id

Usage :

exports.core_inventory:removeItemExact(inventory, itemId, amount)

Example :

exports.core_inventory:removeItemExact(playerid, 'water-23453', 1)
-- OR
exports.core_inventory:removeItemExact('stash-'.. Player.PlayerData.citizenid, 'water-45938', 1)
-- OR 
exports.core_inventory:removeItemExact('stash-'.. Player.getIdentifier():gsub(':',''), 'water-23093', 1)

Parameters :


setItem

Set the item in the inventory (add / remove depend of the amount already present in the inventory)

Usage :

local removed = exports.core_inventory:setItem(inventory, item, amount, metadata)

Example :

exports.core_inventory:setItem(playerid, 'water', 1)
-- OR
exports.core_inventory:setItem('stash-'.. Player.PlayerData.citizenid, 'water', 1, { use = 5 })
-- OR 
exports.core_inventory:setItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water', 1

Return :

true or false if item is set or not

Parameters :


loadPlayerInventory

Load all the player inventories (Content / holder weapon / cloth hodler if enable) in memory and return the content ivnentory when done

Usage :

exports.core_inventory:loadPlayerInventory(identifier)

Example :

exports.core_inventory:loadPlayerInventory(playerid)
-- OR
exports.core_inventory:loadPlayerInventory(Player.PlayerData.citizenid)
-- OR
exports.core_inventory:loadPlayerInventory(Player.getIdentifier():gsub(':',''))

openInventory

Open an inventory on the source screen OR load the inventory if open = false

Usage :

exports.core_inventory:openInventory(source, inventory, inventoryType, x, y, open, content, discoverItem)

Example :

-- Open inventory on player screen :
exports.core_inventory:openInventory(playerid, 'stash-'.. Player.PlayerData.citizenid, 'stash', nil, nil, true, nil, false)
-- OR
exports.core_inventory:openInventory(playerid, 'stash-'.. Player.getIdentifier():gsub(':','', 'stash', nil, nil, true, nil, false)

-- Load the inventory content for futur use (it's like RegisterStash)
exports.core_inventory:openInventory(nil, 'stash-police-storage', 'stash', nil, nil, false, nil, false)

Parameters :


openHolder

Open an holder like weapon holder (primary / secondry holder) or clothing holder. Can be just load if open = false

Usage :

exports.core_inventory:openHolder(source, inventory, inventoryType, x, y, open, content, discoverItem)

Example :

-- Open inventory on player screen :
exports.core_inventory:openHolder(playerid, 'primary-'.. Player.PlayerData.citizenid, 'primary', nil, nil, true, nil)
-- OR
exports.core_inventory:openHolder(playerid, 'primary-'.. Player.getIdentifier():gsub(':','', 'primary', nil, nil, true, nil)

-- Load the inventory content for futur use (it's like RegisterStash)
exports.core_inventory:openHolder(nil, 'torso-' .. Player.PlayerData.citizenid, 'torso', nil, nil, false, nil)

Parameters :


canCarry

Return true or false if the inventory can carry the item or not (metadata check)

Usage :

exports.core_inventory:canCarry(inventory, item, amount, metadata)

Example :

exports.core_inventory:canCarry(playerid, 'water', 1)
-- OR
exports.core_inventory:canCarry('stash-'.. Player.PlayerData.citizenid, 'water', 10)
-- OR 
exports.core_inventory:canCarry('stash-'.. Player.getIdentifier():gsub(':',''), 'water', 5, { uses = 5 })

Return :

true or false if the item can be add on the inventory or not 

Parameters :


hasItem

Return true or false if the inventory has the item with the amount required

Usage :

exports.core_inventory:hasItem(inventory, item, amount)

Example :

exports.core_inventory:hasItem(playerid, 'water', 1)
-- OR
exports.core_inventory:hasItem('stash-'.. Player.PlayerData.citizenid, { 'water', 'juice' }, 40)
-- OR 
exports.core_inventory:hasItem('stash-'.. Player.getIdentifier():gsub(':',''), 'water', 5)

Return :

true or false if the item or items are present in the inventory with the requried amount

Parameters :

clearInventory

Clear the inventory content

Usage :

exports.core_inventory:clearInventory(inventory, source)

Example :

exports.core_inventory:clearInventory(playerid, playerid)
-- OR
exports.core_inventory:clearInventory('primary-'.. Player.PlayerData.citizenid)
-- OR 
exports.core_inventory:clearInventory('stash-'.. Player.getIdentifier():gsub(':',''), source)

Parameters :


clearAllInventory

Clear all the player inventory content (Content / weapon holder / cloth holder)

Usage :

exports.core_inventory:clearAllInventory(identifier, source)

Example :

exports.core_inventory:clearAllInventory(Player.PlayerData.citizenid, Player.source)
-- OR 
exports.core_inventory:clearAllInventory(Player.getIdentifier():gsub(':',''), source)

Parameters :


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

Usage :

exports.core_inventory:openLoot(source, inventoryType, lootTable, minItems, maxItems)

Example :

exports.core_inventory:openLoot(playerid, 'stash', {{"water_bottle", 30},{"weapon_assaultrifle", 5},{"iron", 50}}, 5, 20)

Parameters :


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 :

exports.core_inventory:openLootAdvanced(source, inventoryType, lootTable, addAllSameItem, inventory, shouldRegenerate)

Example :

exports.core_inventory:openLootAdvanced(playerid, 'stash', 
{
        { name = "water_bottle", chance = 30, min = 3, max = 10},
        { name = "weapon_assaultrifle", chance = 5, max = 1},
        {name = "iron", chance = 50, min = 10, max = 20 }
}, false, nil, true)
```

Parameters :


setDurability

Set the durabiltiy of an item if durability is set on hte metadata item

Usage :

exports.core_inventory:setDurability(inventory, itemid, amount)

Example :

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 :


removeDurability

Remove the durability amount on the item.

Usage :

exports.core_inventory:removeDurability(inventory, itemid, amount)

Example :

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 :


setMetadata

Update the metadata of the item by slot

Usage :

exports.core_inventory:setMetadata(inventory, slot, metadata)

Example :

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 :


updateMetadata

Update the metadata of the item

Usage :

exports.core_inventory:updateMetadata(inventory, itemid, metadata)

Example :

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 :


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

Usage :

exports.core_inventory:confiscatePlayerInventory(source)

Return :

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 :


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

Usage :

exports.core_inventory:confiscateInventory(inventory, source, inventoryType)

Example :

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 :


returnPlayerInventory

Return all inventory of the player that have been confiscated before with confiscatePlayerInventory

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

Usage :

exports.core_inventory:returnPlayerInventory(source)

Return :

true if all items return to the player inventories

Parameters :


returnInventory

Return all item of the confiscated inventory with confiscateInventory

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

Usage :

exports.core_inventory:returnInventory(inventory, inventoryType)

Example :

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 :


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.

Usage :

exports.core_inventory:registerDynamicItem(itemname, itemData, force)

Example :

exports.core_inventory:registerDynamicItem('custom-water', { 
    name = 'custom-water',
    description = 'custom water use for custom thing',
    category = 'uniqueItem',
    x = 2,
    y = 2
}, true)

Parameters :

Last updated