Skip to Content
Cobalt

Jobs and gangs

cobalt_core exports: jobs and gangs.

ExportSideWhat it does
GetPlayersByJobServerOnline players whose cobalt_management job (PlayerData.job) has this name or type, and their count.
SetTempJobServerGives the player a runtime-only job beside their real one, replacing any temp job they hold.
ClearTempJobServerEnds the player's temporary job.
GetTempJobServerThe player's temp job, or nil when they have none.
AddJobServerAdds a job at runtime and sends it to every client.
AddJobsServerAdds several jobs at runtime.
RemoveJobServerRemoves a job at runtime.
UpdateJobServerReplaces a job's definition at runtime.
AddGangServerAdds a gang at runtime and sends it to every client.
AddGangsServerAdds several gangs at runtime.
RemoveGangServerRemoves a gang at runtime.
UpdateGangServerReplaces a gang's definition at runtime.

GetPlayersByJob

Server

Online players whose cobalt_management job (PlayerData.job) has this name or type, and their count.

exports.cobalt_core:GetPlayersByJob(job, checkOnDuty)
ParameterTypeOptionalDescription
jobstringNojob name or type
checkOnDutybooleanYesonly players on duty
ReturnsDescription
integer[]players
integercount
Example
local players, count = exports.cobalt_core:GetPlayersByJob('police', true)

SetTempJob

Server

Gives the player a runtime-only job beside their real one, replacing any temp job they hold. Never saved; cleared on logout and when the calling resource stops. Mirrored to the cobalt:tempjob and cobalt:tempjob:label state bags.

exports.cobalt_core:SetTempJob(src, name, data)
ParameterTypeOptionalDescription
srcintegerNo
namestringNo
datatable | tableYes
ReturnsDescription
boolean
Example
local ok = exports.cobalt_core:SetTempJob(source, 'taxi', { label = 'Downtown Cab Co.' })

ClearTempJob

Server

Ends the player's temporary job.

exports.cobalt_core:ClearTempJob(src)
ParameterTypeOptionalDescription
srcintegerNo
ReturnsDescription
booleancleared false when the player held no temp job
Example
local cleared = exports.cobalt_core:ClearTempJob(source)

GetTempJob

Server

The player's temp job, or nil when they have none.

exports.cobalt_core:GetTempJob(src)
ParameterTypeOptionalDescription
srcintegerNo
ReturnsDescription
TempJob?
Example
local job = exports.cobalt_core:GetTempJob(source)

AddJob

Server

Adds a job at runtime and sends it to every client.

exports.cobalt_core:AddJob(jobName, job)
ParameterTypeOptionalDescription
jobNamestringNo
jobCoreJobDefinitionNo
ReturnsDescription
booleanok
OrgResultmessage
Example
local ok, message = exports.cobalt_core:AddJob(
    'police',
    { label = 'Los Santos Police', type = 'leo', defaultDuty = false, offDutyPay = false, grades = { ['0'] = { name = 'Cadet', payment = 50 }, ['1'] = { name = 'Officer', payment = 75 } } }
)

AddJobs

Server

Adds several jobs at runtime.

exports.cobalt_core:AddJobs(jobs)
ParameterTypeOptionalDescription
jobstable<string, CoreJobDefinition>No
ReturnsDescription
booleanok
stringmessage
Example
local ok, message = exports.cobalt_core:AddJobs(
    { taxi = { label = 'Downtown Cab Co.', defaultDuty = true, offDutyPay = false, grades = { ['0'] = { name = 'Driver', payment = 40 } } } }
)

RemoveJob

Server

Removes a job at runtime.

exports.cobalt_core:RemoveJob(jobName)
ParameterTypeOptionalDescription
jobNamestringNo
ReturnsDescription
booleanok
OrgResultmessage
Example
local ok, message = exports.cobalt_core:RemoveJob('police')

UpdateJob

Server

Replaces a job's definition at runtime.

exports.cobalt_core:UpdateJob(jobName, job)
ParameterTypeOptionalDescription
jobNamestringNo
jobCoreJobDefinitionNo
ReturnsDescription
booleanok
OrgResultmessage
Example
local ok, message = exports.cobalt_core:UpdateJob(
    'police',
    { label = 'Los Santos Police', type = 'leo', defaultDuty = false, offDutyPay = false, grades = { ['0'] = { name = 'Cadet', payment = 50 }, ['1'] = { name = 'Officer', payment = 75 } } }
)

AddGang

Server

Adds a gang at runtime and sends it to every client.

exports.cobalt_core:AddGang(gangName, gang)
ParameterTypeOptionalDescription
gangNamestringNo
gangGangDefinitionNo
ReturnsDescription
booleanok
OrgResultmessage
Example
local ok, message = exports.cobalt_core:AddGang(
    'ballas',
    { label = 'Ballas', grades = { ['0'] = { name = 'Recruit' }, ['1'] = { name = 'Shot caller', isboss = true } } }
)

AddGangs

Server

Adds several gangs at runtime.

exports.cobalt_core:AddGangs(gangs)
ParameterTypeOptionalDescription
gangstable<string, GangDefinition>No
ReturnsDescription
booleanok
stringmessage
Example
local ok, message = exports.cobalt_core:AddGangs(
    { vagos = { label = 'Vagos', grades = { ['0'] = { name = 'Recruit' }, ['1'] = { name = 'Jefe', isboss = true } } } }
)

RemoveGang

Server

Removes a gang at runtime.

exports.cobalt_core:RemoveGang(gangName)
ParameterTypeOptionalDescription
gangNamestringNo
ReturnsDescription
booleanok
OrgResultmessage
Example
local ok, message = exports.cobalt_core:RemoveGang('ballas')

UpdateGang

Server

Replaces a gang's definition at runtime.

exports.cobalt_core:UpdateGang(gangName, gang)
ParameterTypeOptionalDescription
gangNamestringNo
gangGangDefinitionNo
ReturnsDescription
booleanok
OrgResultmessage
Example
local ok, message = exports.cobalt_core:UpdateGang(
    'ballas',
    { label = 'Ballas', grades = { ['0'] = { name = 'Recruit' }, ['1'] = { name = 'Shot caller', isboss = true } } }
)

On this page