cobalt_inventory
The grid inventory, its shops, stashes and item hooks.
| Export | Side | What it does |
|---|---|---|
AddItem | Server | Adds items to the player's pockets, or to invName. |
RemoveItem | Server | Removes items from the player's pockets, or from invName. |
HasItem | Server, Client | Checks the player's pockets, or invName. |
CanCarry | Server | Checks weight, the inventory's whitelist and free grid space. |
GetItemCount | Server, Client | Counts an item across the player's pockets, or in invName. |
GetItemByName | Server | The first stack of an item in the player's pockets, or in invName. |
GetPlayerItems | Server | The live item list of the player's inventory. |
FindItems | Server | Every item in an online player's pockets whose metadata key holds needle, ignoring case, such as 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. |
SetItemMetadata | Server | |
SetFullMetadata | Server | Replaces an item's whole metadata table. |
ClearInventory | Server | Empties invName, or a character's pockets. |
GetPlayerInvName | Server | The player's one inventory, player-<citizenid>, or nil when the player is not loaded. |
GetSharedItems | Server, Client | Every item definition from data/items.lua, by name. |
GetItemDef | Server, Client | One item definition, or nil for an unknown name. |
GetCurrentWeapon | Server, Client | The weapon the player holds, or nil when unarmed. |
SetWeaponAmmo | Server | Loads the weapon the player holds with amount rounds. |
OpenPlayerInventory | Server | Opens the target's pockets beside source's own with full access. |
GetShopLocations | Shared | The counter positions of a shop from data/shops.lua. |
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. |
RegisterShop | Server | Adds a shop, or replaces the one with that id and resets its stock. |
OpenShop | Server | Opens a shop's buy screen beside the player's pockets when they pass its groups and licence. |
OpenTrunk | Server | |
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. |
RegisterStash | Server | Adds a stash, or replaces the one with that id and resizes its loaded copies. |
Confiscate | Server | Moves the player's pockets into a new confiscation stash, saved so it survives restarts. |
Restore | Server | Returns a confiscation to the owner's pockets. |
AddItem
ServerAdds 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer? | No | nil when invName is given and no player is involved |
itemName | string | No | |
amount | integer | Yes | default 1 |
metadata | table<string, any> | Yes | |
invName | string | Yes | |
reason | string | Yes | |
ignoreWeight | boolean | Yes | add even past the inventory's weight limit |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:AddItem(
source,
'water',
100,
{ label = 'Evidence bag #12', serial = 'A1B2C3' },
'police_evidence',
'Parking in a red zone',
true
)RemoveItem
ServerRemoves items from the player's pockets, or from invName.
exports.cobalt_inventory:RemoveItem(source, itemName, amount, invName, reason, quiet)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
itemName | string | No | |
amount | integer | Yes | default 1 |
invName | string | Yes | |
reason | string | Yes | |
quiet | boolean | Yes | skip the "Removed" notification |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:RemoveItem(
source,
'water',
100,
'police_evidence',
'Parking in a red zone',
true
)HasItem
ServerChecks the player's pockets, or invName.
exports.cobalt_inventory:HasItem(source, itemName, amount, invName)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
itemName | string | No | |
amount | integer | Yes | default 1 |
invName | string | Yes |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:HasItem(source, 'water', 100, 'police_evidence')Client
Checks the local player's pockets.
exports.cobalt_inventory:HasItem(itemName, amount)| Parameter | Type | Optional | Description |
|---|---|---|---|
itemName | string | No | |
amount | integer | Yes | default 1 |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:HasItem('water', 100)CanCarry
ServerChecks 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
itemName | string | No | |
amount | integer | Yes | default 1 |
invName | string | Yes | defaults to the player's pockets |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:CanCarry(source, 'water', 100, 'police_evidence')GetItemCount
ServerCounts an item across the player's pockets, or in invName.
exports.cobalt_inventory:GetItemCount(source, itemName, invName)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
itemName | string | No | |
invName | string | Yes |
| Returns | Description |
|---|---|
integer |
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)| Parameter | Type | Optional | Description |
|---|---|---|---|
itemName | string | No |
| Returns | Description |
|---|---|
integer |
local itemCount = exports.cobalt_inventory:GetItemCount('water')GetItemByName
ServerThe first stack of an item in the player's pockets, or in invName.
exports.cobalt_inventory:GetItemByName(source, itemName, invName)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
itemName | string | No | |
invName | string | Yes |
| Returns | Description |
|---|---|
InventoryItem? |
local item = exports.cobalt_inventory:GetItemByName(source, 'water', 'police_evidence')GetPlayerItems
ServerThe 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No |
| Returns | Description |
|---|---|
InventoryItem[] |
local items = exports.cobalt_inventory:GetPlayerItems(source)FindItems
ServerEvery 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
key | string | No | |
needle | string | No |
| Returns | Description |
|---|---|
table[] |
local result = exports.cobalt_inventory:FindItems('serial', 'A1B2')SearchPlayer
ServerOpens 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
officer | integer | No | |
target | integer | No | |
opts | InventorySearchOptions | Yes |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:SearchPlayer(
source,
targetId,
{ mode = 'readonly', label = 'Frisk' }
)SetItemMetadata
Serverexports.cobalt_inventory:SetItemMetadata(invName, itemId, key, value)| Parameter | Type | Optional | Description |
|---|---|---|---|
invName | string | No | |
itemId | string | No | |
key | string | No | |
value | any | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:SetItemMetadata(
'police_evidence',
'5f3c9a1e',
'label',
'Evidence bag #12'
)SetFullMetadata
ServerReplaces an item's whole metadata table.
exports.cobalt_inventory:SetFullMetadata(invName, itemId, metadata)| Parameter | Type | Optional | Description |
|---|---|---|---|
invName | string | No | |
itemId | string | No | |
metadata | table<string, any> | Yes |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:SetFullMetadata(
'police_evidence',
'5f3c9a1e',
{ label = 'Evidence bag #12', serial = 'A1B2C3' }
)ClearInventory
ServerEmpties invName, or a character's pockets. A citizenid clears the saved pockets of a character who is offline.
exports.cobalt_inventory:ClearInventory(target, invName)| Parameter | Type | Optional | Description |
|---|---|---|---|
target | integer | string | No | server id or citizenid |
invName | string | Yes |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:ClearInventory(source, 'police_evidence')GetPlayerInvName
ServerThe player's one inventory, player-<citizenid>, or nil when the player is not loaded.
exports.cobalt_inventory:GetPlayerInvName(source)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No |
| Returns | Description |
|---|---|
string? |
local playerInvName = exports.cobalt_inventory:GetPlayerInvName(source)GetSharedItems
ServerEvery item definition from data/items.lua, by name.
exports.cobalt_inventory:GetSharedItems()| Returns | Description |
|---|---|
table<string, InventoryItemDef> |
local sharedItems = exports.cobalt_inventory:GetSharedItems()Client
Every item definition from data/items.lua, by name.
exports.cobalt_inventory:GetSharedItems()| Returns | Description |
|---|---|
table<string, InventoryItemDef> |
local sharedItems = exports.cobalt_inventory:GetSharedItems()GetItemDef
ServerOne item definition, or nil for an unknown name.
exports.cobalt_inventory:GetItemDef(itemName)| Parameter | Type | Optional | Description |
|---|---|---|---|
itemName | string | No |
| Returns | Description |
|---|---|
InventoryItemDef? |
local itemDef = exports.cobalt_inventory:GetItemDef('water')Client
One item definition, or nil for an unknown name.
exports.cobalt_inventory:GetItemDef(itemName)| Parameter | Type | Optional | Description |
|---|---|---|---|
itemName | string | No |
| Returns | Description |
|---|---|
InventoryItemDef? |
local itemDef = exports.cobalt_inventory:GetItemDef('water')GetCurrentWeapon
ServerThe weapon the player holds, or nil when unarmed.
exports.cobalt_inventory:GetCurrentWeapon(source)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No |
| Returns | Description |
|---|---|
InventoryWeapon? |
local weapon = exports.cobalt_inventory:GetCurrentWeapon(source)Client
The weapon the local player holds, or nil when unarmed.
exports.cobalt_inventory:GetCurrentWeapon()| Returns | Description |
|---|---|
InventoryWeapon? |
local weapon = exports.cobalt_inventory:GetCurrentWeapon()SetWeaponAmmo
ServerLoads 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
amount | integer | No |
| Returns | Description |
|---|---|
boolean | ok |
string? | reason |
local ok, reason = exports.cobalt_inventory:SetWeaponAmmo(source, 100)OpenPlayerInventory
ServerOpens the target's pockets beside source's own with full access.
exports.cobalt_inventory:OpenPlayerInventory(source, targetSource)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
targetSource | integer | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:OpenPlayerInventory(source, targetId)GetShopLocations
SharedThe counter positions of a shop from data/shops.lua.
exports.cobalt_inventory:GetShopLocations(shopId)| Parameter | Type | Optional | Description |
|---|---|---|---|
shopId | string | No |
| Returns | Description |
|---|---|
vector4[]? |
local shopLocations = exports.cobalt_inventory:GetShopLocations('247supermarket')GetShopPed
ClientThe 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
shopId | string | No | |
locationIndex | integer | No |
| Returns | Description |
|---|---|
integer? | ped |
local ped = exports.cobalt_inventory:GetShopPed('247supermarket', 1)RegisterShop
ServerAdds 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
shopId | string | No | |
shop | InventoryShop | No |
| Returns | Description |
|---|---|
boolean | registered 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 |
local registered = exports.cobalt_inventory:RegisterShop(
'cobalt_cityhall:fishing',
{ label = 'Fish market', items = { fishingrod = { price = 150 }, fish_bait = { price = 3 } } }
)OpenShop
ServerOpens 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
shopId | string | No | from RegisterShop or data/shops.lua |
coords | vector3 | vector4 | Yes | where the player shops |
| Returns | Description |
|---|---|
boolean | opened |
local opened = exports.cobalt_inventory:OpenShop(
source,
'cobalt_cityhall:fishing',
vector3(215.8, -810.1, 30.7)
)OpenTrunk
Serverexports.cobalt_inventory:OpenTrunk(source, plate, model, vehicleClass)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
plate | string | No | |
model | string | Yes | model name; its class from cobalt_core sets the trunk's weight limit |
vehicleClass | integer | Yes | used in place of the model's class |
| Returns | Description |
|---|---|
boolean | opened false when the class is unknown or has no trunk in config/inventory.lua |
local opened = exports.cobalt_inventory:OpenTrunk(source, 'COBALT01', 'sultan', 6)OpenStash
ServerOpens 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
stashId | string | No | |
owner | string | Yes | citizenid whose copy of an owner = true stash to open |
force | boolean | Yes | skip every check, for server callers that already authorised the player |
| Returns | Description |
|---|---|
boolean | opened |
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 |
local opened, invName = exports.cobalt_inventory:OpenStash(
source,
'police_evidence',
'ABC12345',
true
)RegisterStash
ServerAdds 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
stashId | string | No | |
stash | InventoryStash | No |
| Returns | Description |
|---|---|
boolean | registered false when slots or maxWeight is missing or not a whole number |
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
ServerMoves the player's pockets into a new confiscation stash, saved so it survives restarts.
exports.cobalt_inventory:Confiscate(source, reason)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
reason | string | Yes |
| Returns | Description |
|---|---|
string? | confiscationId |
local confiscationId = exports.cobalt_inventory:Confiscate(source, 'Parking in a red zone')Restore
ServerReturns a confiscation to the owner's pockets.
exports.cobalt_inventory:Restore(citizenid, confiscationId)| Parameter | Type | Optional | Description |
|---|---|---|---|
citizenid | string | No | |
confiscationId | string | No |
| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_inventory:Restore('ABC12345', 'jail_ABC12345_1700000000')