Skip to content

Exports & API

Core Inventory exposes a comprehensive set of exports for integration with other scripts. All server exports accept either a player source ID or an inventory name string.

TIP

When you pass a player source ID (number), the script automatically resolves it to content-{citizenid}. You can also pass inventory names directly like stash-police1 or big_trunk-ABC123.

Server Exports — Items

serverexports['core_inventory']:addItem(inventory, item, amount, metadata, inventoryType)

Adds an item to the specified inventory. Handles stacking, metadata, money sync, and inventory creation automatically.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
amountnumberAmount to add
metadatatableOptional metadata (e.g., {durability = 100})
inventoryTypestringOptional inventory type for auto-creation
Returns: boolean
Example
lua
-- Add 5 bread to a player
exports['core_inventory']:addItem(source, 'bread', 5)

-- Add a weapon with metadata
exports['core_inventory']:addItem(source, 'weapon_pistol', 1, {
    ammo = 12,
    durability = 100.0
})

-- Add to a named inventory
exports['core_inventory']:addItem('stash-police1', 'bandage', 10, {}, 'stash')
serverexports['core_inventory']:removeItem(inventory, item, amount, inventoryType)

Removes an item from the specified inventory. Removes from the first matching slot found.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
amountnumberAmount to remove
inventoryTypestringOptional inventory type
Returns: boolean
Example
lua
exports['core_inventory']:removeItem(source, 'bread', 2)
serverexports['core_inventory']:removeItemExact(inventory, item, amount)

Removes an item from a specific slot index rather than searching by name.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemnumberSlot index to remove from
amountnumberAmount to remove
Returns: boolean
Example
lua
exports['core_inventory']:removeItemExact(source, 3, 1) -- Remove 1 from slot 3
serverexports['core_inventory']:setItem(inventory, item, amount, metadata)

Sets an item to an exact amount. If amount is higher, adds the difference. If lower, removes the difference.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
amountnumberTarget amount
metadatatableOptional metadata
Returns: void
Example
lua
-- Ensure player has exactly 10 water
exports['core_inventory']:setItem(source, 'water', 10)

Server Exports — Querying

serverexports['core_inventory']:hasItem(inventory, items, amount)

Checks if the inventory contains the specified item(s) in the required amount. Accepts a single item string or a table of items.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemsstring|tableItem name or table of item names
amountnumberRequired amount (default 1)
Returns: boolean
Example
lua
if exports['core_inventory']:hasItem(source, 'lockpick', 1) then
    -- Player has at least 1 lockpick
end

-- Check multiple items
if exports['core_inventory']:hasItem(source, {'bread', 'water'}, 1) then
    -- Player has at least 1 of each
end
serverexports['core_inventory']:getItem(inventory, item)

Returns the first matching item data found in the inventory.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
Returns: table|nil
Example
lua
local item = exports['core_inventory']:getItem(source, 'weapon_pistol')
if item then
    print('Durability:', item.metadata.durability)
    print('Ammo:', item.metadata.ammo)
end
serverexports['core_inventory']:getItems(inventory, item)

Returns all matching items of the given name across all slots.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
Returns: table
Example
lua
local allBread = exports['core_inventory']:getItems(source, 'bread')
for _, slot in pairs(allBread) do
    print('Slot has', slot.amount, 'bread')
end
serverexports['core_inventory']:getItemCount(inventory, items)

Returns the total count of an item across all slots. Accepts a single item or table of items.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemsstring|tableItem name or table of item names
Returns: number
Example
lua
local count = exports['core_inventory']:getItemCount(source, 'bread')
print('Player has', count, 'bread total')
serverexports['core_inventory']:getItemBySlot(inventory, slot)

Returns the item data at a specific slot index.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
slotnumberSlot index
Returns: table|nil
Example
lua
local item = exports['core_inventory']:getItemBySlot(source, 1)
serverexports['core_inventory']:getSlotsByItem(inventory, item)

Returns all slot indices containing the specified item.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
Returns: table
Example
lua
local slots = exports['core_inventory']:getSlotsByItem(source, 'bread')
serverexports['core_inventory']:getFirstSlotByItem(inventory, item)

Returns the first slot index containing the specified item.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
Returns: number|nil
Example
lua
local slot = exports['core_inventory']:getFirstSlotByItem(source, 'phone')
serverexports['core_inventory']:getItemsList()

Returns the full registered items table (all item definitions).

Returns: table
Example
lua
local allItems = exports['core_inventory']:getItemsList()
serverexports['core_inventory']:canCarry(inventory, item, amount, metadata)

Checks if the inventory has enough space to hold the specified item and amount.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
itemstringItem name
amountnumberAmount to check
metadatatableOptional metadata
Returns: boolean
Example
lua
if exports['core_inventory']:canCarry(source, 'bread', 10) then
    exports['core_inventory']:addItem(source, 'bread', 10)
end
serverexports['core_inventory']:search(inventory, search, items, metadata)

Advanced search across an inventory. Supports searching by item names and metadata filters.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
searchstringSearch type
itemsstring|tableItem name(s) to search for
metadatatableOptional metadata filter
Returns: table
Example
lua
local results = exports['core_inventory']:search(source, 'count', 'bread')

Server Exports — Inventory Management

serverexports['core_inventory']:getInventory(inventory)

Returns the full inventory data including all slots and content.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
Returns: table|nil
Example
lua
local inv = exports['core_inventory']:getInventory(source)
if inv then
    for slot, item in pairs(inv.content) do
        print(slot, item.name, item.amount)
    end
end
serverexports['core_inventory']:clearInventory(inventory, source)

Clears all items from the inventory. Respects SoulboundItems — those items are kept.

ParameterTypeDescription
inventorynumber|stringInventory name
sourcenumberOptional player source for notification
Returns: void
Example
lua
exports['core_inventory']:clearInventory(source)
serverexports['core_inventory']:clearAllInventory(source)

Clears ALL player inventories — pockets, weapon holders, and clothing slots.

ParameterTypeDescription
sourcenumberPlayer source
Returns: void
Example
lua
exports['core_inventory']:clearAllInventory(source)
serverexports['core_inventory']:confiscatePlayerInventory(source)

Confiscates all items from a player's inventory (stores them for later return).

ParameterTypeDescription
sourcenumberPlayer source
Returns: void
Example
lua
exports['core_inventory']:confiscatePlayerInventory(source)
serverexports['core_inventory']:returnPlayerInventory(source)

Returns previously confiscated items back to the player.

ParameterTypeDescription
sourcenumberPlayer source
Returns: void
Example
lua
exports['core_inventory']:returnPlayerInventory(source)
serverexports['core_inventory']:confiscateInventory(inventory)

Confiscates all items from a named inventory.

ParameterTypeDescription
inventorystringInventory name
Returns: void
Example
lua
exports['core_inventory']:confiscateInventory('stash-evidence1')
serverexports['core_inventory']:returnInventory(inventory)

Returns previously confiscated items to a named inventory.

ParameterTypeDescription
inventorystringInventory name
Returns: void
Example
lua
exports['core_inventory']:returnInventory('stash-evidence1')

Server Exports — Opening Inventories

serverexports['core_inventory']:openInventory(source, inventory, inventoryType, label, restrictedTo, openForSource)

Opens or creates an inventory and optionally displays it to a player.

ParameterTypeDescription
sourcenumber|nilPlayer source (nil to just create)
inventorystringUnique inventory name
inventoryTypestringInventory type from Config.Inventories
labelstringOptional display label override
restrictedTotableOptional category restrictions
openForSourcebooleanWhether to open UI for the player
Returns: void
Example
lua
-- Open a stash for a player
exports['core_inventory']:openInventory(source, 'mystash-1', 'stash', 'My Stash', nil, true)
serverexports['core_inventory']:openOtherPlayerInventory(source, target)

Opens another player's inventory for searching/transfer.

ParameterTypeDescription
sourcenumberPlayer who is searching
targetnumberPlayer being searched
Returns: void
Example
lua
exports['core_inventory']:openOtherPlayerInventory(copSource, suspectSource)
serverexports['core_inventory']:openHolder(source, inventory, inventoryType)

Opens a holder-type inventory (single item slot).

ParameterTypeDescription
sourcenumberPlayer source
inventorystringHolder inventory name
inventoryTypestringHolder type
Returns: void
Example
lua
exports['core_inventory']:openHolder(source, 'primary-' .. citizenid, 'primary')

Server Exports — Looting

Core Inventory has a built-in loot system that lets you create randomized containers — dumpsters, crates, safes, bodies, or anything else. One unified function handles everything: random rolls, quantity ranges, animated reveals, persistence, and regeneration.

How It Works

  • Each loot table entry is rolled independently against its chance (1-100)
  • Entries that pass get a random quantity between min and max
  • If min/max options are set, limits how many distinct item types are added (randomly picks from those that passed)
  • Quantities are always added in bulk — 50 ammo = one addItem call with amount 50, not 50 separate calls
  • In animated mode, each item type appears with a Config.LootAppearTime delay but its full quantity is added at once
  • In non-animated mode, everything is added instantly

Loot Table Format

Each entry defines an item, its chance to appear, and an optional quantity range:

lua
{
    {name = 'bread',       chance = 80, min = 1, max = 3},
    {name = 'pistol_ammo', chance = 60, min = 10, max = 50},
    {name = 'lockpick',    chance = 15, min = 1, max = 1, metadata = {quality = 'new'}},
}
KeyTypeRequiredDescription
namestringYesItem name
chancenumberYesChance out of 100 to appear
minnumberNo (default: 1)Minimum quantity if rolled
maxnumberNo (default: min)Maximum quantity if rolled
metadatatableNoMetadata to attach to the item

Options

The fourth parameter is an optional settings table:

KeyTypeDefaultDescription
inventorystringauto-generatedCustom inventory name for persistence
regeneratebooleanfalseClear and re-roll loot if inventory already exists
animatedbooleantrueItems appear one by one with delay
minnumberallMinimum number of distinct item types to add
maxnumberallMaximum number of distinct item types to add

Returns

inventoryName (string) and generatedLoot (table) — each entry in the generated loot contains item, quantity, and metadata fields.

openLoot

serverexports['core_inventory']:openLoot(source, inventoryType, lootTable, options)

Unified loot system. Rolls each entry independently against its chance, generates random quantities, and opens the inventory for the player. Supports animated item reveals, persistent inventories, and regeneration.

ParameterTypeDescription
sourcenumberPlayer server ID
inventoryTypestringInventory type from config (stash, trunk, etc.)
lootTabletableArray of loot entries
optionstableOptional settings table
Returns: string, table
Example
lua
-- Simple dumpster loot: 1-3 random item types, animated
exports['core_inventory']:openLoot(source, 'stash', {
    {name = 'bread',        chance = 80, min = 1, max = 3},
    {name = 'water_bottle', chance = 70, min = 1, max = 2},
    {name = 'lockpick',     chance = 15, min = 1, max = 1},
    {name = 'bandage',      chance = 50, min = 1, max = 2},
}, {
    min = 1,
    max = 3,
})

-- Ammo crate: all items added instantly in bulk
exports['core_inventory']:openLoot(source, 'stash', {
    {name = 'pistol_ammo',  chance = 80, min = 20, max = 60},
    {name = 'rifle_ammo',   chance = 60, min = 30, max = 100},
    {name = 'smg_ammo',     chance = 50, min = 15, max = 40},
}, {
    animated = false,
})

-- Persistent stash: loot generated once, keeps contents until taken
exports['core_inventory']:openLoot(source, 'stash', {
    {name = 'goldbar',      chance = 10, min = 1, max = 1},
    {name = 'diamond_ring', chance = 25, min = 1, max = 1},
    {name = 'markedbills',  chance = 50, min = 1, max = 3},
}, {
    inventory = 'vault-heist-01',
})

-- Respawning loot: clears and re-rolls every time it's opened
exports['core_inventory']:openLoot(source, 'stash', {
    {name = 'bread',        chance = 90, min = 1, max = 5},
    {name = 'water_bottle', chance = 80, min = 1, max = 3},
}, {
    inventory = 'dumpster-grove-01',
    regenerate = true,
    animated = true,
})

-- Capture what was generated
local invName, loot = exports['core_inventory']:openLoot(source, 'stash', {
    {name = 'lockpick',    chance = 50, min = 1, max = 2},
    {name = 'pistol_ammo', chance = 70, min = 10, max = 30},
}, {
    animated = false,
})
print('Inventory: ' .. invName)
for _, v in ipairs(loot) do
    print(v.item .. ' x' .. v.quantity)
end

Server Event

You can also trigger loot from the client side:

lua
TriggerServerEvent('core_inventory:server:openLoot', {
    inventoryType = 'stash',
    lootTable = {
        {name = 'bread', chance = 80, min = 1, max = 3},
    },
    options = {
        animated = true,
    }
})

Backwards Compatibility

The old formats still work — both the legacy openLoot(src, type, lootTable, min, max, inv) and openLootAdvanced(src, type, lootTable, addAllSameItem, inv, regen) signatures are detected automatically and handled. No need to update existing scripts.

Server Exports — Metadata & Durability

serverexports['core_inventory']:updateMetadata(inventory, slot, metadata)

Replaces the metadata of an item at a specific slot.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
slotnumberSlot index
metadatatableNew metadata table
Returns: void
Example
lua
exports['core_inventory']:updateMetadata(source, 1, { durability = 50, uses = 3 })
serverexports['core_inventory']:setMetadata(inventory, slotid, metadata)

Sets metadata on an item by slot ID.

ParameterTypeDescription
inventorynumber|stringPlayer source or inventory name
slotidnumberSlot index
metadatatableMetadata to set
Returns: void
Example
lua
exports['core_inventory']:setMetadata(source, 5, { quality = 'legendary' })
serverexports['core_inventory']:setDurability(inventory, slot, value)

Sets the durability of an item at a specific slot (0-100).

ParameterTypeDescription
inventorystringInventory name
slotnumberSlot index
valuenumberDurability value (0-100)
Returns: void
Example
lua
exports['core_inventory']:setDurability('content-ABC123', 3, 100)
serverexports['core_inventory']:removeDurability(inventory, slot, amount)

Reduces the durability of an item by the specified amount.

ParameterTypeDescription
inventorystringInventory name
slotnumberSlot index
amountnumberAmount to reduce
Returns: void
Example
lua
exports['core_inventory']:removeDurability('content-ABC123', 3, 10)

Server Exports — Saving & Loading

serverexports['core_inventory']:savePlayerInventory(source)

Saves all player inventories to the database.

ParameterTypeDescription
sourcenumberPlayer source
Returns: void
Example
lua
exports['core_inventory']:savePlayerInventory(source)
serverexports['core_inventory']:saveInventory(inventory)

Saves a specific inventory to the database.

ParameterTypeDescription
inventorystringInventory name
Returns: void
Example
lua
exports['core_inventory']:saveInventory('stash-police1')
serverexports['core_inventory']:loadPlayerInventory(source)

Loads a player's inventories from the database.

ParameterTypeDescription
sourcenumberPlayer source
Returns: void
Example
lua
exports['core_inventory']:loadPlayerInventory(source)
serverexports['core_inventory']:updateInventorySize(inventory, slots, rows)

Dynamically updates the slot count and row layout of an inventory.

ParameterTypeDescription
inventorystringInventory name
slotsnumberNew slot count
rowsnumberNew row count
Returns: void
Example
lua
exports['core_inventory']:updateInventorySize('stash-vip', 200, 10)

Server Exports — Dynamic Items

serverexports['core_inventory']:registerDynamicItem(itemname, itemData, force)

Registers a new item at runtime without requiring a restart.

ParameterTypeDescription
itemnamestringItem name to register
itemDatatableItem definition table
forcebooleanOverwrite if exists
Returns: boolean
Example
lua
exports['core_inventory']:registerDynamicItem('custom_item', {
    name = 'custom_item',
    label = 'Custom Item',
    weight = 100,
    type = 'item',
    image = 'custom_item.png',
    unique = false,
    useable = true,
    shouldClose = false,
    description = 'A custom item'
}, false)

Client Exports — Inventory UI

clientexports['core_inventory']:openInventory()

Opens the player's inventory UI.

Returns: void
Example
lua
exports['core_inventory']:openInventory()
clientexports['core_inventory']:closeInventory()

Closes the inventory UI.

Returns: void
Example
lua
exports['core_inventory']:closeInventory()
clientexports['core_inventory']:isInventoryOpen()

Returns whether the inventory UI is currently open.

Returns: boolean
Example
lua
if exports['core_inventory']:isInventoryOpen() then
    -- Inventory is open
end
clientexports['core_inventory']:openShop(shopId)

Opens a shop UI by its config key.

ParameterTypeDescription
shopIdstringShop ID from Config.Shops
Returns: void
Example
lua
exports['core_inventory']:openShop('247')

Client Exports — Querying

clientexports['core_inventory']:getInventory()

Returns the local player's inventory data. Also available as getPlayerItems().

Returns: table
Example
lua
local items = exports['core_inventory']:getInventory()
-- or
local items = exports['core_inventory']:getPlayerItems()
clientexports['core_inventory']:getItemsList()

Returns all registered item definitions.

Returns: table
Example
lua
local allItems = exports['core_inventory']:getItemsList()
clientexports['core_inventory']:getItemCount(item)

Returns the total count of an item in the local player's inventory.

ParameterTypeDescription
itemstringItem name
Returns: number
Example
lua
local count = exports['core_inventory']:getItemCount('bread')
clientexports['core_inventory']:hasItem(items, count)

Checks if the local player has the specified item(s). Accepts a single item or table of items.

ParameterTypeDescription
itemsstring|tableItem name or table of item names
countnumberRequired amount (default 1)
Returns: boolean
Example
lua
if exports['core_inventory']:hasItem('lockpick') then
    -- Player has a lockpick
end
clientexports['core_inventory']:search(search, item, metadata)

Searches the local player's inventory. Also available as searchInventory().

ParameterTypeDescription
searchstringSearch type
itemstring|tableItem name(s)
metadatatableOptional metadata filter
Returns: table|boolean
Example
lua
local results = exports['core_inventory']:search('count', 'bread')
-- or
local results = exports['core_inventory']:searchInventory('count', 'bread')

Client Exports — Weapons

clientexports['core_inventory']:weaponWheel(enable)

Enables or disables the GTA weapon wheel.

ParameterTypeDescription
enablebooleantrue to enable, false to disable
Returns: void
Example
lua
exports['core_inventory']:weaponWheel(false) -- Disable weapon wheel
clientexports['core_inventory']:getWeaponEquiped()

Returns data about the currently equipped weapon.

Returns: table|nil
Example
lua
local weapon = exports['core_inventory']:getWeaponEquiped()
if weapon then
    print('Equipped:', weapon.name)
end
clientexports['core_inventory']:getWeaponData()

Returns the full data table of the current weapon.

Returns: table|nil
Example
lua
local data = exports['core_inventory']:getWeaponData()
clientexports['core_inventory']:getWeaponAmmo()

Returns the current ammo count and max capacity of the equipped weapon.

Returns: number, number
Example
lua
local ammo, capacity = exports['core_inventory']:getWeaponAmmo()
print('Ammo:', ammo, '/', capacity)

Client Exports — Clothing

These exports interact with Core Inventory's clothing system, allowing scripts to read and save what a player is wearing.

clientexports['core_inventory']:getClothingItemFromPedSkin(ped, notIncludeDefaultSkin)

Extracts clothing data from a ped's current appearance. Returns a table of clothing components (torso, legs, shoes, hats, etc.) with their drawable/texture values. Supports both male and female models.

ParameterTypeDescription
pednumberPed handle (nil for local player)
notIncludeDefaultSkinbooleanIf true, only returns clothing that differs from the default skin
Returns: table
Example
lua
-- Get all clothing the player is currently wearing
local clothes = exports['core_inventory']:getClothingItemFromPedSkin()

-- Get only non-default clothing (what the player actually changed)
local clothes = exports['core_inventory']:getClothingItemFromPedSkin(nil, true)
clientexports['core_inventory']:addClothingItemFromPedSkinInInventory(ped, addAlreadyOwnCloth, notIncludeDefaultSkin, notCheckSpace)

Reads the ped's current clothing and adds it as items to the player's main inventory. Useful for saving an outfit as inventory items.

ParameterTypeDescription
pednumberPed handle (nil for local player)
addAlreadyOwnClothbooleanAdd even if player already owns this clothing piece
notIncludeDefaultSkinbooleanSkip default skin components
notCheckSpacebooleanSkip inventory space check
Returns: void
Example
lua
-- Save current outfit to player's inventory
exports['core_inventory']:addClothingItemFromPedSkinInInventory(nil, false, true, false)
clientexports['core_inventory']:addClothingItemFromPedSkinInClothHolder(ped, addAlreadyOwnCloth, notIncludeDefaultSkin, notCheckSpace)

Reads the ped's current clothing and adds it to the player's clothing holder inventory (the dedicated wardrobe slots, not main inventory).

ParameterTypeDescription
pednumberPed handle (nil for local player)
addAlreadyOwnClothbooleanAdd even if player already owns this clothing piece
notIncludeDefaultSkinbooleanSkip default skin components
notCheckSpacebooleanSkip inventory space check
Returns: void
Example
lua
-- Save current outfit to clothing holder (wardrobe)
exports['core_inventory']:addClothingItemFromPedSkinInClothHolder(nil, false, true, false)

Client Exports — State Management

clientexports['core_inventory']:lockInventory()

Locks the inventory, preventing the player from opening it. Sets invBusy state to true.

Returns: void
Example
lua
-- Lock during a minigame or animation
exports['core_inventory']:lockInventory()
clientexports['core_inventory']:unlockInventory()

Unlocks the inventory, allowing the player to open it again.

Returns: void
Example
lua
exports['core_inventory']:unlockInventory()
clientexports['core_inventory']:lockCloth()

Locks the clothing system, preventing the player from changing clothes.

Returns: void
Example
lua
exports['core_inventory']:lockCloth()
clientexports['core_inventory']:unlockCloth()

Unlocks the clothing system, allowing the player to change clothes again.

Returns: void
Example
lua
exports['core_inventory']:unlockCloth()