Skip to Content
Cobalt

Players

cobalt_core exports: players.

ExportSideWhat it does
GetCoreObjectClient, ServerThe core object, or only the listed keys of it.
GetSharedSharedA Cobalt.Shared table, such as GetShared('Jobs'), or one entry of it, such as GetShared('Jobs', 'police').
GetCoreVersionServercobalt_core's manifest version.
GetPlayerDataClientThe local character's player data: citizenid, charinfo, job, gang, money and metadata.
GetNameClient, ServerThe local character's full name.
IsWearingGlovesClientWhether the local ped's arms drawable counts as gloves, which keeps fingerprints off evidence.
GetPlayersClient, ServerActive player indices.
GetPlayerServerLooks up by server id, or by identifier when given a non-numeric string.
GetPlayerByCitizenIdServerReturns the character with this citizenid, online from memory or else loaded from players and cached for a minute.
GetPlayerByLicenseServerReturns 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.
GetAccountServerEverything cobalt_core holds on a Rockstar license: its state ID, the connected player, every character and every ban.
GetPlayerByPhoneServerReturns the character whose npwd number in players.phone_number is number, online from memory or else loaded and cached for a minute.
GetPlayerByCharInfoServerReturns the first online character whose charinfo[property] equals value, such as firstname, or else the first matching row, cached for a minute.
GetIdentifierServerOne of the player's identifiers, license by default.
GetSourceServerThe loaded player holding an identifier, or 0.
GetMetaDataServerOne metadata key for each character, online ones from memory and the rest from players in one query.
SetMetaDataServerSets one metadata key on a character and writes it to players.metadata straight away.
SetNeedServerSets hunger or thirst, clamped to 0 to 100, and updates the HUD.
AddNeedServerAdds to hunger or thirst, clamped to 0 to 100, and updates the HUD.
SetMethodServerAdds a method to every player object.
SetFieldServerAdds a field to the core object.
AddPlayerMethodServerAdds a method to one player, a list of players, or every player with -1.
AddPlayerFieldServerAdds a field to one player, a list of players, or every player with -1.

GetCoreObject

Client

The core object, or only the listed keys of it.

exports.cobalt_core:GetCoreObject(filters)
ParameterTypeOptionalDescription
filtersstring[]Yes
ReturnsDescription
Core
Example
local core = exports.cobalt_core:GetCoreObject({ 'Functions', 'Shared' })

Server

The core object, or only the listed keys of it.

exports.cobalt_core:GetCoreObject(filters)
ParameterTypeOptionalDescription
filtersstring[]Yes
ReturnsDescription
Core
Example
local core = exports.cobalt_core:GetCoreObject({ 'Functions', 'Shared' })

GetShared

Shared

A Cobalt.Shared table, such as GetShared('Jobs'), or one entry of it, such as GetShared('Jobs', 'police').

exports.cobalt_core:GetShared(namespace, item)
ParameterTypeOptionalDescription
namespace'Vehicles' | 'VehicleHashes' | 'Gangs' | 'Jobs' | 'Locations'No
itemstring | integerYes
ReturnsDescription
any
Example
local shared = exports.cobalt_core:GetShared('Vehicles', 'police')

GetCoreVersion

Server

cobalt_core's manifest version.

exports.cobalt_core:GetCoreVersion()
ReturnsDescription
string
Example
local coreVersion = exports.cobalt_core:GetCoreVersion()

GetPlayerData

Client

The local character's player data: citizenid, charinfo, job, gang, money and metadata.

exports.cobalt_core:GetPlayerData()
ReturnsDescription
PlayerData
Example
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)
ParameterTypeOptionalDescription
cbfunctionNo
Example
exports.cobalt_core:GetPlayerData(function(data) end)

GetName

Client

The local character's full name.

exports.cobalt_core:GetName()
ReturnsDescription
string
Example
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)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
ReturnsDescription
string?
Example
local name = exports.cobalt_core:GetName(source)

IsWearingGloves

Client

Whether the local ped's arms drawable counts as gloves, which keeps fingerprints off evidence.

exports.cobalt_core:IsWearingGloves()
ReturnsDescription
boolean
Example
local ok = exports.cobalt_core:IsWearingGloves()

GetPlayers

Client

Active player indices.

exports.cobalt_core:GetPlayers()
ReturnsDescription
integer[]
Example
local players = exports.cobalt_core:GetPlayers()

Server

Server ids of loaded players.

exports.cobalt_core:GetPlayers()
ReturnsDescription
integer[]
Example
local players = exports.cobalt_core:GetPlayers()

GetPlayer

Server

Looks up by server id, or by identifier when given a non-numeric string.

exports.cobalt_core:GetPlayer(source)
ParameterTypeOptionalDescription
sourceinteger | stringYes
ReturnsDescription
CorePlayer?
Example
local player = exports.cobalt_core:GetPlayer(source)

GetPlayerByCitizenId

Server

Returns 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)
ParameterTypeOptionalDescription
citizenidstringNo
onlineOnlybooleanYeslook at online players only, never the database
ReturnsDescription
CorePlayer?
Example
local player = exports.cobalt_core:GetPlayerByCitizenId('ABC12345')
local source = exports.cobalt_core:GetPlayerByCitizenId('ABC12345', true)?.PlayerData.source

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. A player loaded from the database has Offline = true and no PlayerData.source.

exports.cobalt_core:GetPlayerByLicense(license, onlineOnly)
ParameterTypeOptionalDescription
licensestringNo
onlineOnlybooleanYeslook at online players only, never the database
ReturnsDescription
CorePlayer?
Example
local player = exports.cobalt_core:GetPlayerByLicense('license:0123456789abcdef')

GetAccount

Server

Everything 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)
ParameterTypeOptionalDescription
licensestringNo
ReturnsDescription
CoreAccount?
Example
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
end

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. A player loaded from the database has Offline = true and no PlayerData.source.

exports.cobalt_core:GetPlayerByPhone(number, onlineOnly)
ParameterTypeOptionalDescription
numberstringNo
onlineOnlybooleanYeslook at online players only, never the database
ReturnsDescription
CorePlayer?
Example
local player = exports.cobalt_core:GetPlayerByPhone('5551234567')

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. 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)
ParameterTypeOptionalDescription
propertystringNocharinfo key: letters, digits and underscores, not starting with a digit
valuestring | numberNo
onlineOnlybooleanYeslook at online players only, never the database
ReturnsDescription
CorePlayer?
Example
local player = exports.cobalt_core:GetPlayerByCharInfo('firstname', 'John')

GetIdentifier

Server

One of the player's identifiers, license by default.

exports.cobalt_core:GetIdentifier(source, idtype)
ParameterTypeOptionalDescription
sourceintegerNo
idtype'license' | 'license2' | 'discord' | 'steam' | 'fivem' | 'xbl' | 'live' | 'ip' | stringYes
ReturnsDescription
string?
Example
local identifier = exports.cobalt_core:GetIdentifier(source, 'license')

GetSource

Server

The loaded player holding an identifier, or 0.

exports.cobalt_core:GetSource(identifier)
ParameterTypeOptionalDescription
identifierstringNo
ReturnsDescription
integer
Example
local source = exports.cobalt_core:GetSource('license:0123456789abcdef')

GetMetaData

Server

One 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)
ParameterTypeOptionalDescription
citizenidsstring[]No
keystringNoletters, digits and underscores, not starting with a digit
ReturnsDescription
table<string, any>values by citizenid
Example
local values = exports.cobalt_core:GetMetaData({ 'ABC12345', 'XYZ67890' }, 'driver')

SetMetaData

Server

Sets 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)
ParameterTypeOptionalDescription
citizenidstringNo
keystringNoletters, digits and underscores, not starting with a digit
valueanyNoJSON-encodable; nil clears it
ReturnsDescription
booleanwritten
Example
local written = exports.cobalt_core:SetMetaData('ABC12345', 'driver', 'John')

SetNeed

Server

Sets hunger or thirst, clamped to 0 to 100, and updates the HUD.

exports.cobalt_core:SetNeed(source, need, value)
ParameterTypeOptionalDescription
sourceintegerNo
need'hunger' | 'thirst'No
valuenumberNo
ReturnsDescription
booleanset false when the need is unknown, the value isn't a number or the player isn't loaded
Example
local ok = exports.cobalt_core:SetNeed(source, 'hunger', 1.0)

AddNeed

Server

Adds to hunger or thirst, clamped to 0 to 100, and updates the HUD.

exports.cobalt_core:AddNeed(source, need, amount)
ParameterTypeOptionalDescription
sourceintegerNo
need'hunger' | 'thirst'No
amountnumberNonegative to lower
ReturnsDescription
booleanadded false when the need is unknown, the amount isn't a number or the player isn't loaded
Example
local ok = exports.cobalt_core:AddNeed(source, 'hunger', 100)

SetMethod

Server

Adds a method to every player object.

exports.cobalt_core:SetMethod(methodName, handler)
ParameterTypeOptionalDescription
methodNamestringNo
handlerfunctionNo
ReturnsDescription
booleanok
stringmessage
Example
local ok, message = exports.cobalt_core:SetMethod('GetNickname', function(self, ...) end)

SetField

Server

Adds a field to the core object.

exports.cobalt_core:SetField(fieldName, data)
ParameterTypeOptionalDescription
fieldNamestringNo
dataanyNo
ReturnsDescription
booleanok
stringmessage
Example
local ok, message = exports.cobalt_core:SetField('nickname', 'Johnny')

AddPlayerMethod

Server

Adds a method to one player, a list of players, or every player with -1.

exports.cobalt_core:AddPlayerMethod(ids, methodName, handler)
ParameterTypeOptionalDescription
idsinteger | integer[]No
methodNamestringNo
handlerfunctionNo
Example
exports.cobalt_core:AddPlayerMethod(source, 'GetNickname', function(self, ...) end)

AddPlayerField

Server

Adds a field to one player, a list of players, or every player with -1.

exports.cobalt_core:AddPlayerField(ids, fieldName, data)
ParameterTypeOptionalDescription
idsinteger | integer[]No
fieldNamestringNo
dataanyNo
Example
exports.cobalt_core:AddPlayerField(source, 'nickname', 'Johnny')

On this page