Skip to content

Exports & events

Public API of Cuxial License: client exports to open the panels, item exports, server exports for an MDT and events.

Open the panels from your own targets or items, and read, issue, revoke and restore documents and badges from an MDT or any other resource.

Client exports ​

openGetCard ​

Opens the document store. With an office id it shows the cards of that office, the same as its NPC; without it, every card with Charge money that is not restricted to a job.

lua
exports.cuxial_license:openGetCard(opts)
ParameterTypeDescription
opts.officestringId of an office. Optional. The office must be open and visible to the player's job.
lua
exports.cuxial_license:openGetCard({ office = 'cityhall' })

openAdmin ​

Opens the /license panel. Players without admin.permission get a "no permission" notice.

lua
exports.cuxial_license:openAdmin()

openJobManager ​

Opens the issuing panel. Cards, issued documents and nearby players are only delivered to staff and to the jobs in jobs.authorized and jobs.revoke.

lua
exports.cuxial_license:openJobManager(data)
ParameterTypeDescription
data.headingstringTitle of the panel.
data.subHeadingstringText under the title.
data.logostringImage shown next to the title.
data.jobNamestringJob name shown in the panel.
lua
exports.cuxial_license:openJobManager({
    heading = 'Police Department',
    subHeading = 'Licensing desk',
    logo = 'https://example.com/logo.png',
    jobName = 'police',
})

openIdCheck ​

Opens the ID check panel. Scanning only returns data to staff and to the jobs in jobs.authorized and jobs.idCheck.

lua
exports.cuxial_license:openIdCheck()

openFakeId ​

Opens the fake ID generator. It is the only way to open it. The server checks fakeId.enabled, fakeId.jobs, fakeId.requiredItem and the cooldown before the panel opens.

lua
exports.cuxial_license:openFakeId(data)
ParameterTypeDescription
data.headingstringTitle of the panel. Optional.
data.subHeadingstringText under the title. Optional.
lua
exports.ox_target:addBoxZone({
    coords = vec3(0.0, 0.0, 0.0),
    size = vec3(1.0, 1.0, 2.0),
    options = {
        {
            label = 'Forge a document',
            onSelect = function()
                exports.cuxial_license:openFakeId({ heading = 'Forger' })
            end,
        },
    },
})

Item exports ​

The inventory items point to these exports. You do not call them yourself; you reference them in the item definition, as shown in Installation.

ExportItemsShows
cuxial_license.useLicenseCardid_card, badge items and any item name set in the designerA document or badge issued by the script
cuxial_license.useFakeIdfake_idA card made with the fake ID generator
cuxial_license.useJobBadgejob_badgeA badge built from the item's metadata
cuxial_license.useWorkerIdworker_idA worker ID built from the item's metadata

Badge and worker ID items ​

job_badge and worker_id are drawn from their own metadata, with no record in the database. Give them from your own resource:

ItemMetadata
job_badgefirstname (full name), rank, callsign, division or job, heading and footer (ribbon texts), shape, metal, insignia, logo, playerPhoto, issueDate, expireDate, isRevoked, colors
worker_idname, sex, job, rank, division, citizenId, issueDate, logo, playerPhoto, isRevoked, colors

shape, metal and insignia take the badge values listed in Configuration. colors has body, bodyText, footer and footerText in hex.

lua
exports.ox_inventory:AddItem(source, 'job_badge', 1, {
    firstname = 'John Doe',
    rank = 'Sergeant',
    callsign = '214',
    division = 'Patrol',
    heading = 'POLICE DEPARTMENT',
    shape = 'shield',
    metal = 'silver',
    insignia = 'star1',
})

Server exports ​

GetPlayerLicenses ​

Returns the documents of a character that are not revoked. Expired ones are included.

lua
exports.cuxial_license:GetPlayerLicenses(citizenId)
ParameterTypeDescription
citizenIdstringCharacter identifier.

Returns: table[]. Each entry has id (document id), type (id of the card design), label (title of the card), issueDate, expireDate ('YYYY-MM-DD', empty when it has no expiry) and expired (boolean).

lua
for _, doc in ipairs(exports.cuxial_license:GetPlayerLicenses(citizenId)) do
    print(doc.label, doc.expired)
end

GetAvailableCards ​

Returns every card design on the server.

lua
exports.cuxial_license:GetAvailableCards()

Returns: table[]. Each entry has type (id of the design), label, restrictJob, restrictJobNames, issuedForJobs (jobs that can issue it), itemName, layout ('landscape', 'portrait', 'square' or 'badge') and kind ('id', 'license' or 'badge').

IssueLicense ​

Issues a card to a character, online or offline. It does not check permissions: do it in your resource before calling.

lua
exports.cuxial_license:IssueLicense(issuerSrc, cardId, citizenId, opts)
ParameterTypeDescription
issuerSrcnumber | nilServer id of the player who issues. nil records the issuer as SYSTEM.
cardIdstringId of the card design, the type of GetAvailableCards.
citizenIdstringCharacter who receives it.
opts.expireDatestringExpiry date as 'YYYY-MM-DD'. Omit for no expiry.
opts.metadata.playerPhotostringhttps link used as the photo of the card. Optional.

Returns: { success = true, id = documentId }, with offline = true when the character was offline: then only the record is saved, with no item. On failure, { success = false, reason = '…' } with invalid_args, card_not_found, invalid_item or inventory_full.

If the character already holds that card, the existing record is updated, its revocation lifted and its id returned.

lua
local result = exports.cuxial_license:IssueLicense(source, cardId, citizenId, {
    expireDate = '2027-01-01',
})
if result.success then print('Issued', result.id) end

RevokeLicense / RestoreLicense ​

Revoke or restore a document by id, with no permission check.

lua
exports.cuxial_license:RevokeLicense(licenseId)
exports.cuxial_license:RestoreLicense(licenseId)

Returns: boolean. true when the state changed.

GetCardTemplate ​

Returns the design of a card with its fields empty, for a resource that wants to draw the card and fill it in itself.

lua
exports.cuxial_license:GetCardTemplate(query)
ParameterTypeDescription
query.idstringId of the card design.
query.itemstringAlternative to id: the card that hands out this item.

Returns: table | nil. id, display (what the card shows, with its design or factory preset) and fields: first_name, last_name, citizenid, birthdate, gender, nationality, job, rank, callsign, issue_date, expiry_date. nil when no card matches.

lua
local template = exports.cuxial_license:GetCardTemplate({ item = 'id_card' })

GetCardDesign ​

Returns the layered design of a card, or nil. Cards made with an older version are returned converted, without saving them.

lua
exports.cuxial_license:GetCardDesign(cardId)

GetOffices ​

Returns the enabled offices, with the same fields as data/offices.lua and cards (ids of the designs it sells) in place of items.

lua
exports.cuxial_license:GetOffices()

ReprintDocument ​

Gives the holder a new copy of an issued document, for example after losing the item. src must be staff and the holder must be online.

lua
exports.cuxial_license:ReprintDocument(src, licenseId)

Returns: { success = true }, or { success = false, reason = '…' } with not_allowed, invalid_args, not_found, already_revoked, offline, invalid_item, inventory_full or too_fast.

Documents and badges for an MDT ​

These exports return { success = true, data = … } or { success = false, reason = '…' }. src is the player acting from the MDT: their job must be listed in jobs.authorized (issue) or jobs.revoke (revoke and restore), without looking at the grade. Staff always pass. Each action is limited to 5 every 10 seconds per player.

reasonWhen
invalid_argssrc is not an online player, or an argument is missing or of the wrong type
not_allowedThe job of src is not listed, cannot issue that card, or IssueDocument was asked for a badge
too_fastRate limit reached
card_not_foundThe card does not exist; for a badge, no Badge design uses the faction's item
invalid_item / inventory_fullThe item does not exist, or the holder cannot carry it
offlineThe holder is not online
not_foundThe document does not exist or belongs to another character
already_revoked / not_revokedRevoking something revoked, or restoring something that is not
reason_requiredRevocation reason shorter than documents.reasonMin
invalid_dateexpireDate is not YYYY-MM-DD or is in the past
wrong_jobThe badge holder has no job of that faction
unknown_factionThe faction is not in documents.badges and the holder's job matches none
internalInternal error, or two issues at the same time to the same holder

Document ​

The data of most of these exports is a Document, or a list of them:

FieldDescription
id, cardId, typeDocument id, design id (type is the same as cardId)
label, kind, itemName, layoutTitle, 'id' / 'license' / 'badge', item and layout
holderName, issuedByHolder's name and character id of the issuer, or SYSTEM
issueDate, expireDate'YYYY-MM-DD'; expireDate empty = no expiry
status, expired, revoked'valid', 'expired' or 'revoked' (revoked wins), and both as booleans
photohttps link or empty
job, rank, callsign, factionData printed on the document
restoredBy, restoredAtEmpty if it was never restored
revokedReason, revokedBy, revokedByName, revokedAtOnly when status = 'revoked'

GetCitizenDocuments ​

lua
exports.cuxial_license:GetCitizenDocuments(citizenId, opts)
ParameterTypeDescription
citizenIdstringCharacter identifier.
opts.includeRevokedbooleantrue by default.
opts.kindstring'id', 'license' or 'badge'. Optional filter.

Data: Document[], newest first. It takes no src: decide in your MDT who can read it.

GetIssuableCards ​

lua
exports.cuxial_license:GetIssuableCards(src)

Data: the cards the job of src can issue, badges excluded. Each one has type, cardId, label, kind, itemName, layout, restrictJob, restrictJobNames and issuedForJobs.

IssueDocument ​

lua
exports.cuxial_license:IssueDocument(src, target, cardId, opts)
ParameterTypeDescription
targetnumber | stringServer id or character id of the holder. Must be online.
cardIdstringCard to issue. Not a badge.
opts.expireDatestring'YYYY-MM-DD', today or later. Optional.
opts.photostringhttps photo. Accepted if it starts with a prefix of documents.photoHosts or is already on one of the holder's documents; otherwise the holder's last studio photo is used.
opts.customtableValues of the card's custom fields.
opts.divisionstringDivision printed on the card. Optional.

Data: { id, cardId, citizenId, kind, reissued, updated, photo }. Issuing a card the holder already had reuses the record (reissued = true) and lifts its revocation.

IssueBadge ​

lua
exports.cuxial_license:IssueBadge(src, target, opts)
ParameterTypeDescription
targetnumber | stringServer id or character id of the holder. Must be online.
opts.factionstringFaction of documents.badges. By default, the one whose jobs include the holder's job.
opts.callsignstringBadge number. By default, callsign in the holder's metadata.
opts.rankstringRank printed. By default, the label of the holder's grade.
opts.photo, opts.expireDate, opts.custom, opts.divisionAs in IssueDocument.

Data: as in IssueDocument. If the holder already carries that badge unrevoked, no second item is given: rank, number and photo are updated and updated = true.

lua
local res = exports.cuxial_license:IssueBadge(source, targetId, { callsign = '214' })
if not res.success then print(res.reason) end

RevokeDocument / RestoreDocument ​

lua
exports.cuxial_license:RevokeDocument(src, citizenId, licenseId, reason)
exports.cuxial_license:RestoreDocument(src, citizenId, licenseId)

reason must have between documents.reasonMin and documents.reasonMax characters. Restoring a badge requires the holder to have a job of the faction. Data: the updated Document.

RefreshHolder ​

Rewrites job, rank and badge number on the holder's badges, in the database and in their items if they are online, and revokes the badges of factions they left (with documents.revokeOnJobLoss).

lua
exports.cuxial_license:RefreshHolder(target)

Data: { citizenId, updated, revoked }. The script calls it on its own when an online player changes job or grade. Call it yourself after changing a player's badge number, or after promoting or firing someone who is offline.

GetBadgeFor / GetBadgeFactions ​

Return the badge of a job, or of every faction, without the { success, data } wrapper.

lua
local badge = exports.cuxial_license:GetBadgeFor('police')
local all = exports.cuxial_license:GetBadgeFactions()

Returns: GetBadgeFor gives { faction, item, cardId, shape, metal, logo, preset, ribbon = { top, bottom } }, or nil if the job has no faction. GetBadgeFactions gives { [faction] = … } with the same shape. Values follow the live settings.

Events ​

cuxial_license:client:OpenPanel ​

Opens a panel on a player from the server.

lua
TriggerClientEvent('cuxial_license:client:OpenPanel', source, panel, data)
ParameterTypeDescription
panelstring'admin', 'purchase' (store), 'manager' (issuing), 'idcheck' or 'fakeid'.
datatableSame table as the matching client export. 'purchase' takes { office = id }; 'idcheck' takes { scanId = serverId } to scan that player on open.
lua
TriggerClientEvent('cuxial_license:client:OpenPanel', source, 'idcheck', { scanId = targetId })

Opening a panel gives no extra rights. Every action inside is checked again on the server.

cuxial_license:server:DocumentShown ​

Server-side, local (AddEventHandler). Fires once for each player who sees a document being shown.

lua
AddEventHandler('cuxial_license:server:DocumentShown', function(payload)
    -- payload.viewer, payload.holder, payload.holderCitizenId,
    -- payload.cardId, payload.licenseId, payload.kind, payload.status
end)

kind is 'id', 'license' or 'badge'; status is 'valid', 'expired' or 'revoked'.

cuxial_license:server:DocumentChanged ​

Server-side, local. Fires when a document is issued, revoked, restored or refreshed through the MDT exports or by a job change.

lua
AddEventHandler('cuxial_license:server:DocumentChanged', function(payload)
    if payload.action == 'revoked' and payload.by == 'SYSTEM' then
        print(payload.citizenId, payload.reason)
    end
end)
FieldDescription
action'issued', 'revoked', 'restored' or 'refreshed'
citizenId, licenseId, cardId, kindDocument affected
by, byNameCharacter id and name of who acted, or SYSTEM
reasonOnly for 'revoked'
srcServer id of the player, when it came from an export

© Cuxial