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
Adding & Removing 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)Querying Items
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')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')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['core_inventory']:openLoot(source, inventoryType, lootTable, minItems, maxItems, inventory)Opens a randomized loot inventory. Items are randomly selected from the loot table.
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
inventoryType | string | Inventory type |
lootTable | table | Table of possible items with chances |
minItems | number | Minimum items to spawn |
maxItems | number | Maximum items to spawn |
inventory | string | Optional fixed inventory name |
Returns:
voidExample
lua
exports['core_inventory']:openLoot(source, 'stash', {
{item = 'bread', amount = 3, chance = 80},
{item = 'lockpick', amount = 1, chance = 20},
}, 1, 3)server
exports['core_inventory']:openLootAdvanced(source, inventoryType, lootTable, addAllSameItem, inventory, shouldRegenerate)Advanced loot with control over item duplication and regeneration.
| Parameter | Type | Description |
|---|---|---|
source | number | Player source |
inventoryType | string | Inventory type |
lootTable | table | Loot items |
addAllSameItem | boolean | Add all items at once |
inventory | string | Optional fixed name |
shouldRegenerate | boolean | Regenerate loot on each open |
Returns:
voidExample
lua
exports['core_inventory']:openLootAdvanced(source, 'stash', lootTable, true, 'dumpster-1', false)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)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)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
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']: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['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')