Skip to Content
Cobalt

cobalt_inventory

The grid inventory, its shops, stashes and item hooks.

ExportSideWhat it does
AddItemServerAdds items to the player's pockets, or to invName.
RemoveItemServerRemoves items from the player's pockets, or from invName.
HasItemServer, ClientChecks the player's pockets, or invName.
CanCarryServerChecks weight, the inventory's whitelist and free grid space.
GetItemCountServer, ClientCounts an item across the player's pockets, or in invName.
GetItemByNameServerThe first stack of an item in the player's pockets, or in invName.
GetPlayerItemsServerThe live item list of the player's inventory.
FindItemsServerEvery item in an online player's pockets whose metadata key holds needle, ignoring case, such as FindItems('serial', 'A1B2').
SearchPlayerServerOpens the target's pockets beside the officer's own: readonly to look, remove to take items, full both ways.
SetItemMetadataServer
SetFullMetadataServerReplaces an item's whole metadata table.
ClearInventoryServerEmpties invName, or a character's pockets.
GetPlayerInvNameServerThe player's one inventory, player-<citizenid>, or nil when the player is not loaded.
GetSharedItemsServer, ClientEvery item definition from data/items.lua, by name.
GetItemDefServer, ClientOne item definition, or nil for an unknown name.
GetCurrentWeaponServer, ClientThe weapon the player holds, or nil when unarmed.
SetWeaponAmmoServerLoads the weapon the player holds with amount rounds.
OpenPlayerInventoryServerOpens the target's pockets beside source's own with full access.
GetShopLocationsSharedThe counter positions of a shop from data/shops.lua.
GetShopPedClientThe shopkeeper at a shop counter, while the player is close enough for it to be spawned; nil for a shop without a ped.
RegisterShopServerAdds a shop, or replaces the one with that id and resets its stock.
OpenShopServerOpens a shop's buy screen beside the player's pockets when they pass its groups and licence.
OpenTrunkServer
OpenStashServerOpens a stash from data/stashes.lua or RegisterStash when the player passes its groups, routing bucket and distance, and notifies a player whose rank falls short.
RegisterStashServerAdds a stash, or replaces the one with that id and resizes its loaded copies.
ConfiscateServerMoves the player's pockets into a new confiscation stash, saved so it survives restarts.
RestoreServerReturns a confiscation to the owner's pockets.

AddItem

Server

Adds items to the player's pockets, or to invName. money added to a player's pockets becomes cobalt_core cash; anywhere else it is an item.

exports.cobalt_inventory:AddItem(source, itemName, amount, metadata, invName, reason, ignoreWeight)
ParameterTypeOptionalDescription
sourceinteger?Nonil when invName is given and no player is involved
itemNamestringNo
amountintegerYesdefault 1
metadatatable<string, any>Yes
invNamestringYes
reasonstringYes
ignoreWeightbooleanYesadd even past the inventory's weight limit
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:AddItem(
    source,
    'water',
    100,
    { label = 'Evidence bag #12', serial = 'A1B2C3' },
    'police_evidence',
    'Parking in a red zone',
    true
)

RemoveItem

Server

Removes items from the player's pockets, or from invName.

exports.cobalt_inventory:RemoveItem(source, itemName, amount, invName, reason, quiet)
ParameterTypeOptionalDescription
sourceintegerNo
itemNamestringNo
amountintegerYesdefault 1
invNamestringYes
reasonstringYes
quietbooleanYesskip the "Removed" notification
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:RemoveItem(
    source,
    'water',
    100,
    'police_evidence',
    'Parking in a red zone',
    true
)

HasItem

Server

Checks the player's pockets, or invName.

exports.cobalt_inventory:HasItem(source, itemName, amount, invName)
ParameterTypeOptionalDescription
sourceintegerNo
itemNamestringNo
amountintegerYesdefault 1
invNamestringYes
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:HasItem(source, 'water', 100, 'police_evidence')

Client

Checks the local player's pockets.

exports.cobalt_inventory:HasItem(itemName, amount)
ParameterTypeOptionalDescription
itemNamestringNo
amountintegerYesdefault 1
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:HasItem('water', 100)

CanCarry

Server

Checks weight, the inventory's whitelist and free grid space. A player's pockets always carry money, which they hold as cash.

exports.cobalt_inventory:CanCarry(source, itemName, amount, invName)
ParameterTypeOptionalDescription
sourceintegerNo
itemNamestringNo
amountintegerYesdefault 1
invNamestringYesdefaults to the player's pockets
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:CanCarry(source, 'water', 100, 'police_evidence')

GetItemCount

Server

Counts an item across the player's pockets, or in invName.

exports.cobalt_inventory:GetItemCount(source, itemName, invName)
ParameterTypeOptionalDescription
sourceintegerNo
itemNamestringNo
invNamestringYes
ReturnsDescription
integer
Example
local itemCount = exports.cobalt_inventory:GetItemCount(source, 'water', 'police_evidence')

Client

Counts an item across the local player's inventories.

exports.cobalt_inventory:GetItemCount(itemName)
ParameterTypeOptionalDescription
itemNamestringNo
ReturnsDescription
integer
Example
local itemCount = exports.cobalt_inventory:GetItemCount('water')

GetItemByName

Server

The first stack of an item in the player's pockets, or in invName.

exports.cobalt_inventory:GetItemByName(source, itemName, invName)
ParameterTypeOptionalDescription
sourceintegerNo
itemNamestringNo
invNamestringYes
ReturnsDescription
InventoryItem?
Example
local item = exports.cobalt_inventory:GetItemByName(source, 'water', 'police_evidence')

GetPlayerItems

Server

The live item list of the player's inventory. Its first five slots (y = 0) are the quick-access row that keys 1 to 5 use.

exports.cobalt_inventory:GetPlayerItems(source)
ParameterTypeOptionalDescription
sourceintegerNo
ReturnsDescription
InventoryItem[]
Example
local items = exports.cobalt_inventory:GetPlayerItems(source)

FindItems

Server

Every item in an online player's pockets whose metadata key holds needle, ignoring case, such as FindItems('serial', 'A1B2').

exports.cobalt_inventory:FindItems(key, needle)
ParameterTypeOptionalDescription
keystringNo
needlestringNo
ReturnsDescription
table[]
Example
local result = exports.cobalt_inventory:FindItems('serial', 'A1B2')

SearchPlayer

Server

Opens the target's pockets beside the officer's own: readonly to look, remove to take items, full both ways. Access ends 10 meters from where it opened.

exports.cobalt_inventory:SearchPlayer(officer, target, opts)
ParameterTypeOptionalDescription
officerintegerNo
targetintegerNo
optsInventorySearchOptionsYes
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:SearchPlayer(
    source,
    targetId,
    { mode = 'readonly', label = 'Frisk' }
)

SetItemMetadata

Server
exports.cobalt_inventory:SetItemMetadata(invName, itemId, key, value)
ParameterTypeOptionalDescription
invNamestringNo
itemIdstringNo
keystringNo
valueanyNo
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:SetItemMetadata(
    'police_evidence',
    '5f3c9a1e',
    'label',
    'Evidence bag #12'
)

SetFullMetadata

Server

Replaces an item's whole metadata table.

exports.cobalt_inventory:SetFullMetadata(invName, itemId, metadata)
ParameterTypeOptionalDescription
invNamestringNo
itemIdstringNo
metadatatable<string, any>Yes
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:SetFullMetadata(
    'police_evidence',
    '5f3c9a1e',
    { label = 'Evidence bag #12', serial = 'A1B2C3' }
)

ClearInventory

Server

Empties invName, or a character's pockets. A citizenid clears the saved pockets of a character who is offline.

exports.cobalt_inventory:ClearInventory(target, invName)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
invNamestringYes
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:ClearInventory(source, 'police_evidence')

GetPlayerInvName

Server

The player's one inventory, player-<citizenid>, or nil when the player is not loaded.

exports.cobalt_inventory:GetPlayerInvName(source)
ParameterTypeOptionalDescription
sourceintegerNo
ReturnsDescription
string?
Example
local playerInvName = exports.cobalt_inventory:GetPlayerInvName(source)

GetSharedItems

Server

Every item definition from data/items.lua, by name.

exports.cobalt_inventory:GetSharedItems()
ReturnsDescription
table<string, InventoryItemDef>
Example
local sharedItems = exports.cobalt_inventory:GetSharedItems()

Client

Every item definition from data/items.lua, by name.

exports.cobalt_inventory:GetSharedItems()
ReturnsDescription
table<string, InventoryItemDef>
Example
local sharedItems = exports.cobalt_inventory:GetSharedItems()

GetItemDef

Server

One item definition, or nil for an unknown name.

exports.cobalt_inventory:GetItemDef(itemName)
ParameterTypeOptionalDescription
itemNamestringNo
ReturnsDescription
InventoryItemDef?
Example
local itemDef = exports.cobalt_inventory:GetItemDef('water')

Client

One item definition, or nil for an unknown name.

exports.cobalt_inventory:GetItemDef(itemName)
ParameterTypeOptionalDescription
itemNamestringNo
ReturnsDescription
InventoryItemDef?
Example
local itemDef = exports.cobalt_inventory:GetItemDef('water')

GetCurrentWeapon

Server

The weapon the player holds, or nil when unarmed.

exports.cobalt_inventory:GetCurrentWeapon(source)
ParameterTypeOptionalDescription
sourceintegerNo
ReturnsDescription
InventoryWeapon?
Example
local weapon = exports.cobalt_inventory:GetCurrentWeapon(source)

Client

The weapon the local player holds, or nil when unarmed.

exports.cobalt_inventory:GetCurrentWeapon()
ReturnsDescription
InventoryWeapon?
Example
local weapon = exports.cobalt_inventory:GetCurrentWeapon()

SetWeaponAmmo

Server

Loads the weapon the player holds with amount rounds. The magazine takes up to its clip size, stored in the weapon's metadata and set on the client; the rest goes into the pockets as the weapon's ammo item, so reloading draws from it. False with a reason when no weapon is drawn, it takes no ammo, or the pockets can't hold the rest.

exports.cobalt_inventory:SetWeaponAmmo(source, amount)
ParameterTypeOptionalDescription
sourceintegerNo
amountintegerNo
ReturnsDescription
booleanok
string?reason
Example
local ok, reason = exports.cobalt_inventory:SetWeaponAmmo(source, 100)

OpenPlayerInventory

Server

Opens the target's pockets beside source's own with full access.

exports.cobalt_inventory:OpenPlayerInventory(source, targetSource)
ParameterTypeOptionalDescription
sourceintegerNo
targetSourceintegerNo
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:OpenPlayerInventory(source, targetId)

GetShopLocations

Shared

The counter positions of a shop from data/shops.lua.

exports.cobalt_inventory:GetShopLocations(shopId)
ParameterTypeOptionalDescription
shopIdstringNo
ReturnsDescription
vector4[]?
Example
local shopLocations = exports.cobalt_inventory:GetShopLocations('247supermarket')

GetShopPed

Client

The shopkeeper at a shop counter, while the player is close enough for it to be spawned; nil for a shop without a ped. Fires cobalt_inventory:client:shopPedSpawned (shopId, locationIndex, ped) each time it spawns.

exports.cobalt_inventory:GetShopPed(shopId, locationIndex)
ParameterTypeOptionalDescription
shopIdstringNo
locationIndexintegerNo
ReturnsDescription
integer?ped
Example
local ped = exports.cobalt_inventory:GetShopPed('247supermarket', 1)

RegisterShop

Server

Adds a shop, or replaces the one with that id and resets its stock. Its id can't be one from data/shops.lua. Registrations last until cobalt_inventory restarts, so register again on its onResourceStart.

exports.cobalt_inventory:RegisterShop(shopId, shop)
ParameterTypeOptionalDescription
shopIdstringNo
shopInventoryShopNo
ReturnsDescription
booleanregistered false, with the reason in the console, when the id is taken by data/shops.lua or the label, an item or a price is invalid
Example
local registered = exports.cobalt_inventory:RegisterShop(
    'cobalt_cityhall:fishing',
    { label = 'Fish market', items = { fishingrod = { price = 150 }, fish_bait = { price = 3 } } }
)

OpenShop

Server

Opens a shop's buy screen beside the player's pockets when they pass its groups and licence. The caller checks the player is where the shop sells; with coords, purchases stop once the player is more than 10 meters from them.

exports.cobalt_inventory:OpenShop(source, shopId, coords)
ParameterTypeOptionalDescription
sourceintegerNo
shopIdstringNofrom RegisterShop or data/shops.lua
coordsvector3 | vector4Yeswhere the player shops
ReturnsDescription
booleanopened
Example
local opened = exports.cobalt_inventory:OpenShop(
    source,
    'cobalt_cityhall:fishing',
    vector3(215.8, -810.1, 30.7)
)

OpenTrunk

Server
exports.cobalt_inventory:OpenTrunk(source, plate, model, vehicleClass)
ParameterTypeOptionalDescription
sourceintegerNo
platestringNo
modelstringYesmodel name; its class from cobalt_core sets the trunk's weight limit
vehicleClassintegerYesused in place of the model's class
ReturnsDescription
booleanopened false when the class is unknown or has no trunk in config/inventory.lua
Example
local opened = exports.cobalt_inventory:OpenTrunk(source, 'COBALT01', 'sultan', 6)

OpenStash

Server

Opens a stash from data/stashes.lua or RegisterStash when the player passes its groups, routing bucket and distance, and notifies a player whose rank falls short. An owner = true stash opens the player's own copy; another character's copy needs force. Opening fires the server event cobalt_inventory:server:openedInventory (source, inventory name); a shared stash's inventory name is its id.

exports.cobalt_inventory:OpenStash(source, stashId, owner, force)
ParameterTypeOptionalDescription
sourceintegerNo
stashIdstringNo
ownerstringYescitizenid whose copy of an owner = true stash to open
forcebooleanYesskip every check, for server callers that already authorised the player
ReturnsDescription
booleanopened
string?invName the inventory name of the copy that opened, which is the stash id for a shared stash and <id>:<owner> for an owned copy
Example
local opened, invName = exports.cobalt_inventory:OpenStash(
    source,
    'police_evidence',
    'ABC12345',
    true
)

RegisterStash

Server

Adds a stash, or replaces the one with that id and resizes its loaded copies. Register it before OpenStash or a client opens it; registrations last until cobalt_inventory restarts. A shared stash's inventory name is its id, so AddItem and the other exports reach it by id while it is loaded; an owned copy is <id>:<owner>.

exports.cobalt_inventory:RegisterStash(stashId, stash)
ParameterTypeOptionalDescription
stashIdstringNo
stashInventoryStashNo
ReturnsDescription
booleanregistered false when slots or maxWeight is missing or not a whole number
Example
local registered = exports.cobalt_inventory:RegisterStash(
    'mrpd_armory',
    { label = 'MRPD armory', slots = 150, maxWeight = 400000, groups = { police = 2 }, coords = vector3(452.1, -980.0, 30.7) }
)

Confiscate

Server

Moves the player's pockets into a new confiscation stash, saved so it survives restarts.

exports.cobalt_inventory:Confiscate(source, reason)
ParameterTypeOptionalDescription
sourceintegerNo
reasonstringYes
ReturnsDescription
string?confiscationId
Example
local confiscationId = exports.cobalt_inventory:Confiscate(source, 'Parking in a red zone')

Restore

Server

Returns a confiscation to the owner's pockets.

exports.cobalt_inventory:Restore(citizenid, confiscationId)
ParameterTypeOptionalDescription
citizenidstringNo
confiscationIdstringNo
ReturnsDescription
boolean
Example
local ok = exports.cobalt_inventory:Restore('ABC12345', 'jail_ABC12345_1700000000')

On this page