Skip to Content
Cobalt

Licenses

cobalt_core exports: licenses.

ExportSideWhat it does
GetLicenseTypesClient, ServerThe licence types from licenses in config/shared.lua, by key.
HasLicenseServerFalse for an unknown type or character.
GetLicenseRecordsServerEvery licence type's record for the character: whether it is held, who granted it and when, when it was revoked, and its points.
GrantLicenseServerGrants a licence, records when and by whom in metadata.licenceGrants, clears its revocation and points, saves an offline character, and fires cobalt_core:server:licenseChanged(citizenid, key, true, source?).
RevokeLicenseServerRevokes a licence and records when in metadata.licenceRevoked, saving an offline character, and fires cobalt_core:server:licenseChanged(citizenid, key, false, source?).
AddLicensePointsServerAdds points to a held licence whose type has a pointsLimit, and revokes it once the total reaches that limit, firing licenseChanged.
CardMetadataServerThe metadata for a new ID or licence card item, from the player's loaded character and dated today.
UseCardServerThe id_card, driver_license and weapon_license items' server export.

GetLicenseTypes

Client

The licence types from licenses in config/shared.lua, by key. The ID card is not one.

exports.cobalt_core:GetLicenseTypes()
ReturnsDescription
table<string, LicenseType>
Example
local licenseTypes = exports.cobalt_core:GetLicenseTypes()

Server

The licence types from licenses in config/shared.lua, by key. The ID card is not one.

exports.cobalt_core:GetLicenseTypes()
ReturnsDescription
table<string, LicenseType>
Example
local licenseTypes = exports.cobalt_core:GetLicenseTypes()

HasLicense

Server

False for an unknown type or character.

exports.cobalt_core:HasLicense(target, key)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
keystringNo
ReturnsDescription
boolean
Example
local ok = exports.cobalt_core:HasLicense(source, 'driver')

GetLicenseRecords

Server

Every licence type's record for the character: whether it is held, who granted it and when, when it was revoked, and its points. Nil when the character doesn't exist.

exports.cobalt_core:GetLicenseRecords(target)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
ReturnsDescription
table<string, LicenseRecord>?
Example
local licenseRecords = exports.cobalt_core:GetLicenseRecords(source)

GrantLicense

Server

Grants a licence, records when and by whom in metadata.licenceGrants, clears its revocation and points, saves an offline character, and fires cobalt_core:server:licenseChanged(citizenid, key, true, source?). False when the type is unknown, the character doesn't exist or already holds it.

exports.cobalt_core:GrantLicense(target, key, issuer)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
keystringNo
issuerstringYesshown on City Hall's card counter, such as LSPD or the DMV
ReturnsDescription
booleanchanged
Example
local changed = exports.cobalt_core:GrantLicense(source, 'driver', 'ABC12345')

RevokeLicense

Server

Revokes a licence and records when in metadata.licenceRevoked, saving an offline character, and fires cobalt_core:server:licenseChanged(citizenid, key, false, source?). False when the type is unknown, the character doesn't exist or doesn't hold it.

exports.cobalt_core:RevokeLicense(target, key)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
keystringNo
ReturnsDescription
booleanchanged
Example
local changed = exports.cobalt_core:RevokeLicense(source, 'driver')

AddLicensePoints

Server

Adds points to a held licence whose type has a pointsLimit, and revokes it once the total reaches that limit, firing licenseChanged. Returns nil and false when the type has no limit, the amount isn't positive, or the character doesn't hold it.

exports.cobalt_core:AddLicensePoints(target, key, amount)
ParameterTypeOptionalDescription
targetinteger | stringNoserver id or citizenid
keystringNo
amountintegerNo
ReturnsDescription
integer?total
booleanrevoked
Example
local total, revoked = exports.cobalt_core:AddLicensePoints(source, 'driver', 100)

CardMetadata

Server

The metadata for a new ID or licence card item, from the player's loaded character and dated today. Nil when the player has no character loaded.

exports.cobalt_core:CardMetadata(source, key)
ParameterTypeOptionalDescription
sourceintegerNo
keystringYesthe licence key for a licence card, such as driver or weapon; omit it for an ID card
ReturnsDescription
CardItemMetadata?
Example
local itemMetadata = exports.cobalt_core:CardMetadata(source, 'driver')

UseCard

Server

The id_card, driver_license and weapon_license items' server export. On usedItem it shows the card to its holder and, when idCard.showNearby is set, to every player within idCard.nearbyDistance meters in the holder's routing bucket.

exports.cobalt_core:UseCard(event, item, inventory, slot)
ParameterTypeOptionalDescription
event'usingItem' | 'usedItem'No
itemtableNo
inventorytableNo
slottableNo
Example
exports.cobalt_core:UseCard(
    'usingItem',
    { name = 'id_card' },
    { id = 'ABC12345', source = source },
    { id = '5f3c9a1e' }
)

On this page