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
server
exports['core_inventory']:addItem(inventory, item, amount, metadata, inventoryType)Adds an item to the specified inventory. Handles stacking, metadata, money sync, and inventory creation automatically.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
amount | number | Amount to add |
metadata | table | Optional metadata (e.g., {durability = 100}) |
inventoryType | string | Optional inventory type for auto-creation |
Returns:
booleanExample
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')server
exports['core_inventory']:removeItem(inventory, item, amount, inventoryType)Removes an item from the specified inventory. Removes from the first matching slot found.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
amount | number | Amount to remove |
inventoryType | string | Optional inventory type |
Returns:
booleanExample
lua
exports['core_inventory']:removeItem(source, 'bread', 2)server
exports['core_inventory']:removeItemExact(inventory, item, amount)Removes an item from a specific slot index rather than searching by name.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | number | Slot index to remove from |
amount | number | Amount to remove |
Returns:
booleanExample
lua
exports['core_inventory']:removeItemExact(source, 3, 1) -- Remove 1 from slot 3server
exports['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.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
amount | number | Target amount |
metadata | table | Optional metadata |
Returns:
voidExample
lua
-- Ensure player has exactly 10 water
exports['core_inventory']:setItem(source, 'water', 10)Server Exports — Querying
server
exports['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.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
items | string|table | Item name or table of item names |
amount | number | Required amount (default 1) |
Returns:
booleanExample
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
endserver
exports['core_inventory']:getItem(inventory, item)Returns the first matching item data found in the inventory.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
Returns:
table|nilExample
lua
local item = exports['core_inventory']:getItem(source, 'weapon_pistol')
if item then
print('Durability:', item.metadata.durability)
print('Ammo:', item.metadata.ammo)
endserver
exports['core_inventory']:getItems(inventory, item)Returns all matching items of the given name across all slots.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
Returns:
tableExample
lua
local allBread = exports['core_inventory']:getItems(source, 'bread')
for _, slot in pairs(allBread) do
print('Slot has', slot.amount, 'bread')
endserver
exports['core_inventory']:getItemCount(inventory, items)Returns the total count of an item across all slots. Accepts a single item or table of items.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
items | string|table | Item name or table of item names |
Returns:
numberExample
lua
local count = exports['core_inventory']:getItemCount(source, 'bread')
print('Player has', count, 'bread total')server
exports['core_inventory']:getItemBySlot(inventory, slot)Returns the item data at a specific slot index.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
slot | number | Slot index |
Returns:
table|nilExample
lua
local item = exports['core_inventory']:getItemBySlot(source, 1)server
exports['core_inventory']:getSlotsByItem(inventory, item)Returns all slot indices containing the specified item.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
Returns:
tableExample
lua
local slots = exports['core_inventory']:getSlotsByItem(source, 'bread')server
exports['core_inventory']:getFirstSlotByItem(inventory, item)Returns the first slot index containing the specified item.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
Returns:
number|nilExample
lua
local slot = exports['core_inventory']:getFirstSlotByItem(source, 'phone')server
exports['core_inventory']:getItemsList()Returns the full registered items table (all item definitions).
Returns:
tableExample
lua
local allItems = exports['core_inventory']:getItemsList()server
exports['core_inventory']:canCarry(inventory, item, amount, metadata)Checks if the inventory has enough space to hold the specified item and amount.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
item | string | Item name |
amount | number | Amount to check |
metadata | table | Optional metadata |
Returns:
booleanExample
lua
if exports['core_inventory']:canCarry(source, 'bread', 10) then
exports['core_inventory']:addItem(source, 'bread', 10)
endserver
exports['core_inventory']:search(inventory, search, items, metadata)Advanced search across an inventory. Supports searching by item names and metadata filters.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
search | string | Search type |
items | string|table | Item name(s) to search for |
metadata | table | Optional metadata filter |
Returns:
tableExample
lua
local results = exports['core_inventory']:search(source, 'count', 'bread')Server Exports — Inventory Management
server
exports['core_inventory']:getInventory(inventory)Returns the full inventory data including all slots and content.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
Returns:
table|nilExample
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
endserver
exports['core_inventory']:clearInventory(inventory, source)Clears all items from the inventory. Respects SoulboundItems — those items are kept.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Inventory name |
source | number | Optional player source for notification |
Returns:
voidExample
lua
exports['core_inventory']:clearInventory(source)server
exports['core_inventory']:clearAllInventory(source)Clears ALL player inventories — pockets, weapon holders, and clothing slots.
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
Returns:
voidExample
lua
exports['core_inventory']:clearAllInventory(source)server
exports['core_inventory']:confiscatePlayerInventory(source)Confiscates all items from a player's inventory (stores them for later return).
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
Returns:
voidExample
lua
exports['core_inventory']:confiscatePlayerInventory(source)server
exports['core_inventory']:returnPlayerInventory(source)Returns previously confiscated items back to the player.
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
Returns:
voidExample
lua
exports['core_inventory']:returnPlayerInventory(source)server
exports['core_inventory']:confiscateInventory(inventory)Confiscates all items from a named inventory.
| Parameter | Type | Description |
|---|---|---|
inventory | string | Inventory name |
Returns:
voidExample
lua
exports['core_inventory']:confiscateInventory('stash-evidence1')server
exports['core_inventory']:returnInventory(inventory)Returns previously confiscated items to a named inventory.
| Parameter | Type | Description |
|---|---|---|
inventory | string | Inventory name |
Returns:
voidExample
lua
exports['core_inventory']:returnInventory('stash-evidence1')Server Exports — Opening Inventories
server
exports['core_inventory']:openInventory(source, inventory, inventoryType, label, restrictedTo, openForSource)Opens or creates an inventory and optionally displays it to a player.
| Parameter | Type | Description |
|---|---|---|
source | number|nil | Player source (nil to just create) |
inventory | string | Unique inventory name |
inventoryType | string | Inventory type from Config.Inventories |
label | string | Optional display label override |
restrictedTo | table | Optional category restrictions |
openForSource | boolean | Whether to open UI for the player |
Returns:
voidExample
lua
-- Open a stash for a player
exports['core_inventory']:openInventory(source, 'mystash-1', 'stash', 'My Stash', nil, true)server
exports['core_inventory']:openOtherPlayerInventory(source, target)Opens another player's inventory for searching/transfer.
| Parameter | Type | Description |
|---|---|---|
source | number | Player who is searching |
target | number | Player being searched |
Returns:
voidExample
lua
exports['core_inventory']:openOtherPlayerInventory(copSource, suspectSource)server
exports['core_inventory']:openHolder(source, inventory, inventoryType)Opens a holder-type inventory (single item slot).
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
inventory | string | Holder inventory name |
inventoryType | string | Holder type |
Returns:
voidExample
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
minandmax - If
min/maxoptions 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
addItemcall with amount 50, not 50 separate calls - In animated mode, each item type appears with a
Config.LootAppearTimedelay 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'}},
}| Key | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Item name |
chance | number | Yes | Chance out of 100 to appear |
min | number | No (default: 1) | Minimum quantity if rolled |
max | number | No (default: min) | Maximum quantity if rolled |
metadata | table | No | Metadata to attach to the item |
Options
The fourth parameter is an optional settings table:
| Key | Type | Default | Description |
|---|---|---|---|
inventory | string | auto-generated | Custom inventory name for persistence |
regenerate | boolean | false | Clear and re-roll loot if inventory already exists |
animated | boolean | true | Items appear one by one with delay |
min | number | all | Minimum number of distinct item types to add |
max | number | all | Maximum 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
server
exports['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.
| Parameter | Type | Description |
|---|---|---|
source | number | Player server ID |
inventoryType | string | Inventory type from config (stash, trunk, etc.) |
lootTable | table | Array of loot entries |
options | table | Optional settings table |
Returns:
string, tableExample
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)
endServer 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
server
exports['core_inventory']:updateMetadata(inventory, slot, metadata)Replaces the metadata of an item at a specific slot.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
slot | number | Slot index |
metadata | table | New metadata table |
Returns:
voidExample
lua
exports['core_inventory']:updateMetadata(source, 1, { durability = 50, uses = 3 })server
exports['core_inventory']:setMetadata(inventory, slotid, metadata)Sets metadata on an item by slot ID.
| Parameter | Type | Description |
|---|---|---|
inventory | number|string | Player source or inventory name |
slotid | number | Slot index |
metadata | table | Metadata to set |
Returns:
voidExample
lua
exports['core_inventory']:setMetadata(source, 5, { quality = 'legendary' })server
exports['core_inventory']:setDurability(inventory, slot, value)Sets the durability of an item at a specific slot (0-100).
| Parameter | Type | Description |
|---|---|---|
inventory | string | Inventory name |
slot | number | Slot index |
value | number | Durability value (0-100) |
Returns:
voidExample
lua
exports['core_inventory']:setDurability('content-ABC123', 3, 100)server
exports['core_inventory']:removeDurability(inventory, slot, amount)Reduces the durability of an item by the specified amount.
| Parameter | Type | Description |
|---|---|---|
inventory | string | Inventory name |
slot | number | Slot index |
amount | number | Amount to reduce |
Returns:
voidExample
lua
exports['core_inventory']:removeDurability('content-ABC123', 3, 10)Server Exports — Saving & Loading
server
exports['core_inventory']:savePlayerInventory(source)Saves all player inventories to the database.
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
Returns:
voidExample
lua
exports['core_inventory']:savePlayerInventory(source)server
exports['core_inventory']:saveInventory(inventory)Saves a specific inventory to the database.
| Parameter | Type | Description |
|---|---|---|
inventory | string | Inventory name |
Returns:
voidExample
lua
exports['core_inventory']:saveInventory('stash-police1')server
exports['core_inventory']:loadPlayerInventory(source)Loads a player's inventories from the database.
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
Returns:
voidExample
lua
exports['core_inventory']:loadPlayerInventory(source)server
exports['core_inventory']:updateInventorySize(inventory, slots, rows)Dynamically updates the slot count and row layout of an inventory.
| Parameter | Type | Description |
|---|---|---|
inventory | string | Inventory name |
slots | number | New slot count |
rows | number | New row count |
Returns:
voidExample
lua
exports['core_inventory']:updateInventorySize('stash-vip', 200, 10)Server Exports — Dynamic Items
server
exports['core_inventory']:registerDynamicItem(itemname, itemData, force)Registers a new item at runtime without requiring a restart.
| Parameter | Type | Description |
|---|---|---|
itemname | string | Item name to register |
itemData | table | Item definition table |
force | boolean | Overwrite if exists |
Returns:
booleanExample
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
client
exports['core_inventory']:openInventory()Opens the player's inventory UI.
Returns:
voidExample
lua
exports['core_inventory']:openInventory()client
exports['core_inventory']:closeInventory()Closes the inventory UI.
Returns:
voidExample
lua
exports['core_inventory']:closeInventory()client
exports['core_inventory']:isInventoryOpen()Returns whether the inventory UI is currently open.
Returns:
booleanExample
lua
if exports['core_inventory']:isInventoryOpen() then
-- Inventory is open
endclient
exports['core_inventory']:openShop(shopId)Opens a shop UI by its config key.
| Parameter | Type | Description |
|---|---|---|
shopId | string | Shop ID from Config.Shops |
Returns:
voidExample
lua
exports['core_inventory']:openShop('247')Client Exports — Querying
client
exports['core_inventory']:getInventory()Returns the local player's inventory data. Also available as getPlayerItems().
Returns:
tableExample
lua
local items = exports['core_inventory']:getInventory()
-- or
local items = exports['core_inventory']:getPlayerItems()client
exports['core_inventory']:getItemsList()Returns all registered item definitions.
Returns:
tableExample
lua
local allItems = exports['core_inventory']:getItemsList()client
exports['core_inventory']:getItemCount(item)Returns the total count of an item in the local player's inventory.
| Parameter | Type | Description |
|---|---|---|
item | string | Item name |
Returns:
numberExample
lua
local count = exports['core_inventory']:getItemCount('bread')client
exports['core_inventory']:hasItem(items, count)Checks if the local player has the specified item(s). Accepts a single item or table of items.
| Parameter | Type | Description |
|---|---|---|
items | string|table | Item name or table of item names |
count | number | Required amount (default 1) |
Returns:
booleanExample
lua
if exports['core_inventory']:hasItem('lockpick') then
-- Player has a lockpick
endclient
exports['core_inventory']:search(search, item, metadata)Searches the local player's inventory. Also available as searchInventory().
| Parameter | Type | Description |
|---|---|---|
search | string | Search type |
item | string|table | Item name(s) |
metadata | table | Optional metadata filter |
Returns:
table|booleanExample
lua
local results = exports['core_inventory']:search('count', 'bread')
-- or
local results = exports['core_inventory']:searchInventory('count', 'bread')Client Exports — Weapons
client
exports['core_inventory']:weaponWheel(enable)Enables or disables the GTA weapon wheel.
| Parameter | Type | Description |
|---|---|---|
enable | boolean | true to enable, false to disable |
Returns:
voidExample
lua
exports['core_inventory']:weaponWheel(false) -- Disable weapon wheelclient
exports['core_inventory']:getWeaponEquiped()Returns data about the currently equipped weapon.
Returns:
table|nilExample
lua
local weapon = exports['core_inventory']:getWeaponEquiped()
if weapon then
print('Equipped:', weapon.name)
endclient
exports['core_inventory']:getWeaponData()Returns the full data table of the current weapon.
Returns:
table|nilExample
lua
local data = exports['core_inventory']:getWeaponData()client
exports['core_inventory']:getWeaponAmmo()Returns the current ammo count and max capacity of the equipped weapon.
Returns:
number, numberExample
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.
client
exports['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.
| Parameter | Type | Description |
|---|---|---|
ped | number | Ped handle (nil for local player) |
notIncludeDefaultSkin | boolean | If true, only returns clothing that differs from the default skin |
Returns:
tableExample
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)client
exports['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.
| Parameter | Type | Description |
|---|---|---|
ped | number | Ped handle (nil for local player) |
addAlreadyOwnCloth | boolean | Add even if player already owns this clothing piece |
notIncludeDefaultSkin | boolean | Skip default skin components |
notCheckSpace | boolean | Skip inventory space check |
Returns:
voidExample
lua
-- Save current outfit to player's inventory
exports['core_inventory']:addClothingItemFromPedSkinInInventory(nil, false, true, false)client
exports['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).
| Parameter | Type | Description |
|---|---|---|
ped | number | Ped handle (nil for local player) |
addAlreadyOwnCloth | boolean | Add even if player already owns this clothing piece |
notIncludeDefaultSkin | boolean | Skip default skin components |
notCheckSpace | boolean | Skip inventory space check |
Returns:
voidExample
lua
-- Save current outfit to clothing holder (wardrobe)
exports['core_inventory']:addClothingItemFromPedSkinInClothHolder(nil, false, true, false)Client Exports — State Management
client
exports['core_inventory']:lockInventory()Locks the inventory, preventing the player from opening it. Sets invBusy state to true.
Returns:
voidExample
lua
-- Lock during a minigame or animation
exports['core_inventory']:lockInventory()client
exports['core_inventory']:unlockInventory()Unlocks the inventory, allowing the player to open it again.
Returns:
voidExample
lua
exports['core_inventory']:unlockInventory()client
exports['core_inventory']:lockCloth()Locks the clothing system, preventing the player from changing clothes.
Returns:
voidExample
lua
exports['core_inventory']:lockCloth()client
exports['core_inventory']:unlockCloth()Unlocks the clothing system, allowing the player to change clothes again.
Returns:
voidExample
lua
exports['core_inventory']:unlockCloth()