Players
cobalt_core exports: players.
| Export | Side | What it does |
|---|---|---|
GetCoreObject | Client, Server | The core object, or only the listed keys of it. |
GetShared | Shared | A Cobalt.Shared table, such as GetShared('Jobs'), or one entry of it, such as GetShared('Jobs', 'police'). |
GetCoreVersion | Server | cobalt_core's manifest version. |
GetPlayerData | Client | The local character's player data: citizenid, charinfo, job, gang, money and metadata. |
GetName | Client, Server | The local character's full name. |
IsWearingGloves | Client | Whether the local ped's arms drawable counts as gloves, which keeps fingerprints off evidence. |
GetPlayers | Client, Server | Active player indices. |
GetPlayer | Server | Looks up by server id, or by identifier when given a non-numeric string. |
GetPlayerByCitizenId | Server | Returns the character with this citizenid, online from memory or else loaded from players and cached for a minute. |
GetPlayerByLicense | Server | Returns the character on this Rockstar license, online from memory or else the license's character whose row changed last (players.last_updated, normally the last one played), loaded and cached for a minute. |
GetAccount | Server | Everything cobalt_core holds on a Rockstar license: its state ID, the connected player, every character and every ban. |
GetPlayerByPhone | Server | Returns the character whose npwd number in players.phone_number is number, online from memory or else loaded and cached for a minute. |
GetPlayerByCharInfo | Server | Returns the first online character whose charinfo[property] equals value, such as firstname, or else the first matching row, cached for a minute. |
GetIdentifier | Server | One of the player's identifiers, license by default. |
GetSource | Server | The loaded player holding an identifier, or 0. |
GetMetaData | Server | One metadata key for each character, online ones from memory and the rest from players in one query. |
SetMetaData | Server | Sets one metadata key on a character and writes it to players.metadata straight away. |
SetNeed | Server | Sets hunger or thirst, clamped to 0 to 100, and updates the HUD. |
AddNeed | Server | Adds to hunger or thirst, clamped to 0 to 100, and updates the HUD. |
SetMethod | Server | Adds a method to every player object. |
SetField | Server | Adds a field to the core object. |
AddPlayerMethod | Server | Adds a method to one player, a list of players, or every player with -1. |
AddPlayerField | Server | Adds a field to one player, a list of players, or every player with -1. |
GetCoreObject
ClientThe core object, or only the listed keys of it.
exports.cobalt_core:GetCoreObject(filters)| Parameter | Type | Optional | Description |
|---|---|---|---|
filters | string[] | Yes |
| Returns | Description |
|---|---|
Core |
local core = exports.cobalt_core:GetCoreObject({ 'Functions', 'Shared' })Server
The core object, or only the listed keys of it.
exports.cobalt_core:GetCoreObject(filters)| Parameter | Type | Optional | Description |
|---|---|---|---|
filters | string[] | Yes |
| Returns | Description |
|---|---|
Core |
local core = exports.cobalt_core:GetCoreObject({ 'Functions', 'Shared' })GetShared
SharedA Cobalt.Shared table, such as GetShared('Jobs'), or one entry of it, such as GetShared('Jobs', 'police').
exports.cobalt_core:GetShared(namespace, item)| Parameter | Type | Optional | Description |
|---|---|---|---|
namespace | 'Vehicles' | 'VehicleHashes' | 'Gangs' | 'Jobs' | 'Locations' | No | |
item | string | integer | Yes |
| Returns | Description |
|---|---|
any |
local shared = exports.cobalt_core:GetShared('Vehicles', 'police')GetCoreVersion
Servercobalt_core's manifest version.
exports.cobalt_core:GetCoreVersion()| Returns | Description |
|---|---|
string |
local coreVersion = exports.cobalt_core:GetCoreVersion()GetPlayerData
ClientThe local character's player data: citizenid, charinfo, job, gang, money and metadata.
exports.cobalt_core:GetPlayerData()| Returns | Description |
|---|---|
PlayerData |
local data = exports.cobalt_core:GetPlayerData()Client
The local character's player data: citizenid, charinfo, job, gang, money and metadata.
exports.cobalt_core:GetPlayerData(cb)| Parameter | Type | Optional | Description |
|---|---|---|---|
cb | function | No |
exports.cobalt_core:GetPlayerData(function(data) end)GetName
ClientThe local character's full name.
exports.cobalt_core:GetName()| Returns | Description |
|---|---|
string |
local name = exports.cobalt_core:GetName()Server
A character's full name by server id or citizenid, read from memory when online and from players when not. Nil when no character matches or it has no name.
exports.cobalt_core:GetName(target)| Parameter | Type | Optional | Description |
|---|---|---|---|
target | integer | string | No | server id or citizenid |
| Returns | Description |
|---|---|
string? |
local name = exports.cobalt_core:GetName(source)IsWearingGloves
ClientWhether the local ped's arms drawable counts as gloves, which keeps fingerprints off evidence.
exports.cobalt_core:IsWearingGloves()| Returns | Description |
|---|---|
boolean |
local ok = exports.cobalt_core:IsWearingGloves()GetPlayers
ClientActive player indices.
exports.cobalt_core:GetPlayers()| Returns | Description |
|---|---|
integer[] |
local players = exports.cobalt_core:GetPlayers()Server
Server ids of loaded players.
exports.cobalt_core:GetPlayers()| Returns | Description |
|---|---|
integer[] |
local players = exports.cobalt_core:GetPlayers()GetPlayer
ServerLooks up by server id, or by identifier when given a non-numeric string.
exports.cobalt_core:GetPlayer(source)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | string | Yes |
| Returns | Description |
|---|---|
CorePlayer? |
local player = exports.cobalt_core:GetPlayer(source)GetPlayerByCitizenId
ServerReturns the character with this citizenid, online from memory or else loaded from players and cached for a minute. A player loaded from the database has Offline = true and no PlayerData.source. Pass onlineOnly when you need a loaded character, for example to message it by source. The lookup then never queries the database.
exports.cobalt_core:GetPlayerByCitizenId(citizenid, onlineOnly)| Parameter | Type | Optional | Description |
|---|---|---|---|
citizenid | string | No | |
onlineOnly | boolean | Yes | look at online players only, never the database |
| Returns | Description |
|---|---|
CorePlayer? |
local player = exports.cobalt_core:GetPlayerByCitizenId('ABC12345')
local source = exports.cobalt_core:GetPlayerByCitizenId('ABC12345', true)?.PlayerData.sourceGetPlayerByLicense
ServerReturns the character on this Rockstar license, online from memory or else the license's character whose row changed last (players.last_updated, normally the last one played), loaded and cached for a minute. A player loaded from the database has Offline = true and no PlayerData.source.
exports.cobalt_core:GetPlayerByLicense(license, onlineOnly)| Parameter | Type | Optional | Description |
|---|---|---|---|
license | string | No | |
onlineOnly | boolean | Yes | look at online players only, never the database |
| Returns | Description |
|---|---|
CorePlayer? |
local player = exports.cobalt_core:GetPlayerByLicense('license:0123456789abcdef')GetAccount
ServerEverything cobalt_core holds on a Rockstar license: its state ID, the connected player, every character and every ban. The character being played comes from memory, the rest from players in one query. Nil when the license has no character, ban or state ID and isn't connected.
exports.cobalt_core:GetAccount(license)| Parameter | Type | Optional | Description |
|---|---|---|---|
license | string | No |
| Returns | Description |
|---|---|
CoreAccount? |
local account = exports.cobalt_core:GetAccount('license:0123456789abcdef')
if not account then return end
for _, character in ipairs(account.characters) do
print(character.citizenid, character.name, character.phone_number, character.job?.label)
end
for _, ban in ipairs(account.bans) do
if ban.active then print(ban.reason, ban.by, ban.expires or 'permanent') end
endGetPlayerByPhone
ServerReturns the character whose npwd number in players.phone_number is number, online from memory or else loaded and cached for a minute. A player loaded from the database has Offline = true and no PlayerData.source.
exports.cobalt_core:GetPlayerByPhone(number, onlineOnly)| Parameter | Type | Optional | Description |
|---|---|---|---|
number | string | No | |
onlineOnly | boolean | Yes | look at online players only, never the database |
| Returns | Description |
|---|---|
CorePlayer? |
local player = exports.cobalt_core:GetPlayerByPhone('5551234567')GetPlayerByCharInfo
ServerReturns the first online character whose charinfo[property] equals value, such as firstname, or else the first matching row, cached for a minute. Charinfo values such as names repeat, so the database match is whichever row MariaDB reads first. A player loaded from the database has Offline = true and no PlayerData.source. Errors when the lookup reaches the database and property isn't an identifier.
exports.cobalt_core:GetPlayerByCharInfo(property, value, onlineOnly)| Parameter | Type | Optional | Description |
|---|---|---|---|
property | string | No | charinfo key: letters, digits and underscores, not starting with a digit |
value | string | number | No | |
onlineOnly | boolean | Yes | look at online players only, never the database |
| Returns | Description |
|---|---|
CorePlayer? |
local player = exports.cobalt_core:GetPlayerByCharInfo('firstname', 'John')GetIdentifier
ServerOne of the player's identifiers, license by default.
exports.cobalt_core:GetIdentifier(source, idtype)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
idtype | 'license' | 'license2' | 'discord' | 'steam' | 'fivem' | 'xbl' | 'live' | 'ip' | string | Yes |
| Returns | Description |
|---|---|
string? |
local identifier = exports.cobalt_core:GetIdentifier(source, 'license')GetSource
ServerThe loaded player holding an identifier, or 0.
exports.cobalt_core:GetSource(identifier)| Parameter | Type | Optional | Description |
|---|---|---|---|
identifier | string | No |
| Returns | Description |
|---|---|
integer |
local source = exports.cobalt_core:GetSource('license:0123456789abcdef')GetMetaData
ServerOne metadata key for each character, online ones from memory and the rest from players in one query. Characters that don't exist or lack the key are left out. Errors when key isn't an identifier.
exports.cobalt_core:GetMetaData(citizenids, key)| Parameter | Type | Optional | Description |
|---|---|---|---|
citizenids | string[] | No | |
key | string | No | letters, digits and underscores, not starting with a digit |
| Returns | Description |
|---|---|
table<string, any> | values by citizenid |
local values = exports.cobalt_core:GetMetaData({ 'ABC12345', 'XYZ67890' }, 'driver')SetMetaData
ServerSets one metadata key on a character and writes it to players.metadata straight away. A loaded character also gets it in memory and on its client, and job or gang also replace PlayerData.job or PlayerData.gang. False when no character has that citizenid. Errors when key isn't an identifier.
exports.cobalt_core:SetMetaData(citizenid, key, value)| Parameter | Type | Optional | Description |
|---|---|---|---|
citizenid | string | No | |
key | string | No | letters, digits and underscores, not starting with a digit |
value | any | No | JSON-encodable; nil clears it |
| Returns | Description |
|---|---|
boolean | written |
local written = exports.cobalt_core:SetMetaData('ABC12345', 'driver', 'John')SetNeed
ServerSets hunger or thirst, clamped to 0 to 100, and updates the HUD.
exports.cobalt_core:SetNeed(source, need, value)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
need | 'hunger' | 'thirst' | No | |
value | number | No |
| Returns | Description |
|---|---|
boolean | set false when the need is unknown, the value isn't a number or the player isn't loaded |
local ok = exports.cobalt_core:SetNeed(source, 'hunger', 1.0)AddNeed
ServerAdds to hunger or thirst, clamped to 0 to 100, and updates the HUD.
exports.cobalt_core:AddNeed(source, need, amount)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
need | 'hunger' | 'thirst' | No | |
amount | number | No | negative to lower |
| Returns | Description |
|---|---|
boolean | added false when the need is unknown, the amount isn't a number or the player isn't loaded |
local ok = exports.cobalt_core:AddNeed(source, 'hunger', 100)SetMethod
ServerAdds a method to every player object.
exports.cobalt_core:SetMethod(methodName, handler)| Parameter | Type | Optional | Description |
|---|---|---|---|
methodName | string | No | |
handler | function | No |
| Returns | Description |
|---|---|
boolean | ok |
string | message |
local ok, message = exports.cobalt_core:SetMethod('GetNickname', function(self, ...) end)SetField
ServerAdds a field to the core object.
exports.cobalt_core:SetField(fieldName, data)| Parameter | Type | Optional | Description |
|---|---|---|---|
fieldName | string | No | |
data | any | No |
| Returns | Description |
|---|---|
boolean | ok |
string | message |
local ok, message = exports.cobalt_core:SetField('nickname', 'Johnny')AddPlayerMethod
ServerAdds a method to one player, a list of players, or every player with -1.
exports.cobalt_core:AddPlayerMethod(ids, methodName, handler)| Parameter | Type | Optional | Description |
|---|---|---|---|
ids | integer | integer[] | No | |
methodName | string | No | |
handler | function | No |
exports.cobalt_core:AddPlayerMethod(source, 'GetNickname', function(self, ...) end)AddPlayerField
ServerAdds a field to one player, a list of players, or every player with -1.
exports.cobalt_core:AddPlayerField(ids, fieldName, data)| Parameter | Type | Optional | Description |
|---|---|---|---|
ids | integer | integer[] | No | |
fieldName | string | No | |
data | any | No |
exports.cobalt_core:AddPlayerField(source, 'nickname', 'Johnny')