Skip to content

Exports & events

Public API of Cuxial Police: exports and events to send alerts, read duty, jail players and more.

Send dispatch alerts, read who is on duty, jail players or open the tablet from your own resources. Everything not listed here is internal and can change without notice.

All exports are called as exports.cuxial_police:Name(...).

Dispatch (server) ​

SendDispatchAlert ​

Sends an alert to the on-duty members of the chosen factions or jobs.

lua
local id = exports.cuxial_police:SendDispatchAlert(data)
FieldTypeDescription
titlestringTitle of the alert. Required.
messagestringBody text.
typestringKind of alert. Also decides the faction when factions is not given (see below).
severitystringFree label such as 'low', 'normal', 'high', 'critical'.
coordsvector3 | tablePosition, as vec3 or { x, y, z }.
streetstringStreet name.
codestring | numberAlert code. A sequential number when left out.
reporterstringWho reports.
suspect, suspects, vehicle, weaponstableStructured data shown on the alert card.
imagesstring[]Image URLs.
triage, vitalstableMedical data for EMS alerts.
metadatatableFree data.
centralbooleantrue also adds the alert to the Central board.
factionsstring[]Receivers: 'police', 'ems', 'fib'.
jobsstring[]Job names. When given, it replaces factions.

Returns: string with the alert id, or nil when the data is invalid.

When neither jobs nor factions is given, the faction comes from type:

typeGoes to
robbery, shots, vehicle, drugs, assault, chase, domestic, firePolice, and the federal agency when the addon is enabled
medical, crash, crashfire, cardiac, overdoseEMS
Anything elseEvery faction
lua
exports.cuxial_police:SendDispatchAlert({
    type = 'robbery',
    title = 'ROBBERY IN PROGRESS',
    message = 'Convenience store, armed suspect',
    severity = 'high',
    coords = GetEntityCoords(GetPlayerPed(source)),
    central = true,
    factions = { 'police' },
})

SendAlert ​

Shorter form of the same alert.

lua
exports.cuxial_police:SendAlert(data)

It accepts title, message, code, street, distance, coords, metadata, annotation, central, jobs, factions and type. Without title, a generic one is used.

AddCentralAlert ​

Adds an entry to the Central board without sending it to the sidebars.

lua
exports.cuxial_police:AddCentralAlert(alert)
FieldTypeDescription
titlestringTitle.
messagestringBody text.
codestring | numberCode. Random when left out.
streetstringStreet name.
coordstablePosition.
metadatatableFree data.
factionsstring[]Factions that see the entry.

ClearCentralAlerts ​

Empties the Central board.

lua
exports.cuxial_police:ClearCentralAlerts()

Dispatch (client) ​

SendDispatchAlert ​

Sends an alert from the player who reports it. It takes the same fields as the server export, except code.

lua
local sent = exports.cuxial_police:SendDispatchAlert(data)

coords and street are filled in from the player's position when left out. Each player is limited by dispatch.sendAlertCooldown. When the sender is not a faction member, central and critical are ignored.

Returns: boolean. false when data is not a table.

lua
exports.cuxial_police:SendDispatchAlert({
    type = 'medical',
    title = 'MEDICAL EMERGENCY',
    message = 'Unconscious person',
    factions = { 'ems' },
})

Gunshot alerts ​

Cuxial Police does not detect shots by itself. Trigger this client event from your weapons resource, on the client of the player who fired:

lua
TriggerEvent('cuxial:gunshot', weaponName, weaponLabel)
ParameterTypeDescription
weaponNamestringWeapon name, checked against the ignored list (data.gunshotwhitelist).
weaponLabelstringName shown in the alert. Optional.

No alert is sent when the shooter is on duty in a faction, when the job is in dispatch.ignoredJobs, when the weapon is ignored or silenced, or with dispatch.enabled = false.

With ox_inventory ​

ox_inventory already knows when the player fires. Open ox_inventory/client.lua, find the block that handles a fired shot and add the event as its first line:

ox_inventory/client.lua
lua
elseif weaponAmmo then
    if IsPedShooting(playerPed) then
        TriggerEvent('cuxial:gunshot', currentWeapon.name, Items[currentWeapon.name] and Items[currentWeapon.name].label or currentWeapon.name)

        local currentAmmo
        -- ...

Restart ox_inventory and then cuxial_police. The weapon name sent is the item name (WEAPON_PISTOL), the same one you write in data.gunshotwhitelist.

Updating ox_inventory replaces client.lua. Add the line again after each update.

Duty (server) ​

ExportReturnsDescription
GetCopsOnDuty()numberMembers on duty, all factions together.
IsCopOnDuty(src)booleanWhether that player is on duty in a faction.
GetOnDutySources()number[]Server ids on duty.
GetOnDutySourcesByFaction(faction)number[]Server ids on duty in 'police', 'ems' or 'fib'.
GetFactionOfSource(src)string | nilFaction of an on-duty player.
GetCopData()tableCopy of the roster, keyed by server id.
SetCopReference(src, sprite, color, colorId)booleanChanges the map blip of an on-duty member. A nil parameter is left as it is.
lua
for _, src in ipairs(exports.cuxial_police:GetOnDutySourcesByFaction('police')) do
    TriggerClientEvent('myresource:notify', src, 'Bank alarm')
end
lua
if exports.cuxial_police:GetCopsOnDuty() < 3 then
    return -- not enough units for this robbery
end

Citizens (server) ​

GetCitizenFlags ​

lua
local flags = exports.cuxial_police:GetCitizenFlags(citizenid)

Returns: { wanted = boolean, dangerous = boolean }. Both are false for an empty identifier.

GetAnkleByCitizen ​

lua
local ankle = exports.cuxial_police:GetAnkleByCitizen(citizenid)

Returns: the active ankle monitor of that citizen, or nil.

Home panel (server) ​

The police home tab shows a list of recent robberies that your resources feed.

ExportDescription
AddRobbery({ name, location, status })Adds an entry. status is 'pending' by default. The last 100 are kept.
GetRobberies()Returns the list.
ClearRobberies()Empties the list.
lua
exports.cuxial_police:AddRobbery({ name = 'Jewellery store', location = 'Vinewood' })

Prison (server) ​

These exports act on the built-in prison. Months are converted to real time with prison.monthSeconds and capped at limits.maxSentenceMonths.

ExportReturnsDescription
Jail(src, months, reason, officerSrc)booleanJails an online player. reason and officerSrc are optional.
JailOffline(citizenid, months, reason)booleanJails a citizen who is offline.
Unjail(src)booleanReleases an online player.
UnjailOffline(citizenid)booleanReleases a citizen by identifier.
IsJailed(src)booleanWhether that player is serving a sentence.
GetPrisonerData(src)table | nil{ jail_time, remaining_sec, months }. jail_time is the months left.
GetActiveSentences()tableOnline inmates keyed by citizen id: { name, months, remaining_sec }.
lua
exports.cuxial_police:Jail(target, 12, 'Armed robbery', source)

Medical appointments ​

Server ​

ExportReturnsDescription
CreateAppointment(data, opts)row | nil, reasonBooks an appointment.
GetPatientAppointments(citizenid, opts)table[]Appointments of a patient. opts: kind, openOnly, limit.
GetAgenda(opts)table[]Appointments in a time range. opts: from, to (Unix time), doctorCitizenid, kind.
CancelAppointment(id, reason)boolean, reasonCancels an appointment. The patient is notified when lb-phone is running.
CheckInAppointment(id, citizenid)boolean, reasonMarks the patient as arrived.

Fields of data for CreateAppointment:

FieldTypeDescription
citizenidstringPatient. Required.
scheduledAtnumberUnix time of the appointment. Required; it must be in the future.
kindstring'consulta' (default), 'control', 'cura', 'analisis', 'vacuna', 'obstetricia', 'psicologia' or 'cronico'.
durationMinnumberLength in minutes, 5 to 240.
pricenumberPrice. Taken from appointments.prices when left out.
doctorCitizenidstringAssigned doctor.

opts.doctorName is the name shown as author when no doctor is given.

lua
local appointment, reason = exports.cuxial_police:CreateAppointment({
    citizenid = citizenid,
    kind = 'consulta',
    scheduledAt = os.time() + 3600,
}, { doctorName = 'Reception' })

Client ​

For a phone app or any interface of the patient.

ExportDescription
GetMyAppointments()Returns the player's appointments.
ConfirmMyAppointment(id)Confirms attendance.
CancelMyAppointment(id)Cancels the appointment.
CheckInMyAppointment(id)Checks in. The player must be at a reception point.

InvalidateConditionCache ​

Call it after writing to the table cuxial_ems_conditions from another resource, so the medicine checks reload that patient.

lua
exports.cuxial_police:InvalidateConditionCache(citizenid)

Settings (server) ​

getSetting ​

Returns the live value of a settings section.

lua
local value = exports.cuxial_police:getSetting(id)
ParameterTypeDescription
idstringSection id, such as 'config.jobs' or 'data.permissions'.

Returns: the section as a plain table (vectors become { x, y, z }), or nil for an unknown id.

lua
local jobs = exports.cuxial_police:getSetting('config.jobs')
if jobs.policeJobs[jobName] then
    -- the job belongs to the police faction
end

Federal addon (server) ​

These exports exist only when the addon is enabled.

ExportReturnsDescription
FibGetCase(id)table | nilA case file.
FibAddTimeline(id, kind, actor, text, data)booleanAdds an entry to the timeline of a case. false when the case does not exist.
FibGetOrgHeat(gangId)numberHeat of an organisation; 0 when unknown.
FibCitizenFlags(citizenid)table | nil{ watchlist, threat, org, warrant }, or nil when the agency has nothing on the citizen.
FibActiveArrestWarrant(citizenid)table | nil{ id, number, expires_at, case_id } of the active arrest warrant.
FibDevicesNear(coords, radius)table[]Active devices around a point: { id, kind, dist }. radius is 30.0 by default.
FibRecordIntel(evt)table | nilRecords an intelligence event. evt.kind is required; it accepts origin, gangId, gangLabel, citizenid, plate, actor, text, coords, weight, heat and data. With intel.auto = false only the agency's own events count. Returns the stored event.
lua
local warrant = exports.cuxial_police:FibActiveArrestWarrant(citizenid)
if warrant then
    print(('Arrest warrant %s'):format(warrant.number))
end

sd-computers documents (server) ​

sd-computers uses these exports to work with reports from the department computers, and any other resource can use them too. They only answer police or federal agency members; the agency also sees police reports. Each one is rate limited per player.

ExportReturnsDescription
SdReports(src, filters)table[] | nilReports visible to the player: { id, title, author, date, tags }. filters: text, tag, citizenid, plate, limit (50 by default, 100 max).
SdReport(src, id)table | nilA full report, with implicated people, victims, officers, vehicles, evidence and linked documents.
SdSearch(src, text)table | nil{ citizens, vehicles } matching the text (at least 2 characters, 20 of each).
SdDossier(src, query)table | nilFile of a citizen ({ citizenid }) or a vehicle ({ plate }): profile, reports it appears in and notes.
SdLinkDocument(src, reportId, doc)boolean, errorLinks a department document (doc.id) to a report. Needs the reports.edit permission. Up to 20 documents per report.
SdUnlinkDocument(src, reportId, docId)boolean, errorUnlinks a document. Needs the reports.edit permission.

Possible errors are sd_no_access, sd_report_missing, sd_already_linked and sd_link_limit.

lua
local ok, err = exports.cuxial_police:SdLinkDocument(source, reportId, { id = docId })
if not ok then print(err) end

Forensics (server) ​

Exports for an evidence system that integrates with the tablet. See section config.evidence in Configuration.

ExportReturnsDescription
HasMdtPermission(src, cat, action)booleanWhether the player is on duty and their grade reaches the cat.action permission of data.permissions, for example ('evidence', 'destroy').
UploadPhoto(src, image, prefix){ ok, url?, reason? }Uploads a base64 image with the same service as mugshots. prefix is optional and tags the file ('evidence' by default).
lua
if exports.cuxial_police:HasMdtPermission(source, 'evidence', 'collect') then
    -- the officer can collect evidence
end

Client exports ​

cuxial_mdt ​

Opens the tablet. It is also the handler of the cuxial_mdt item.

lua
exports.cuxial_police:cuxial_mdt()

OpenCitizen ​

Opens the tablet on a citizen's profile. It only works for a player with a police job.

lua
exports.cuxial_police:OpenCitizen(citizenid)

The exports prescription, death_certificate, fib_camera, fib_mic and fib_gps are item handlers for the inventory and are not meant to be called by hand.

Client events ​

Local events to drive the interface from another client resource, such as a radial menu.

EventParametersWhat it does
cuxial:tablet:opennoneOpens the tablet.
cuxial:tablet:closenoneCloses the tablet.
cuxial:tablet:togglenoneOpens or closes the tablet.
cuxial:quickmenu:opennoneOpens the quick menu.
cuxial:quickmenu:closenoneCloses the quick menu.
cuxial:quickmenu:togglenoneOpens or closes the quick menu.
cuxial:duty:togglenoneGoes on or off duty.
cuxial:duty:setstateSets duty to true or false.
cuxial:duty:getcbCalls cb(onDuty).
lua
TriggerEvent('cuxial:tablet:open')

Events you can listen to:

EventParametersWhen
cuxial_police:client:SetDutystateThe player's duty state changed.
cuxial_police:client:NewAlertalertThe player received a dispatch alert.
cuxial_police:client:JobChangeCleanupnoneThe player left the faction or changed job.
lua
RegisterNetEvent('cuxial_police:client:SetDuty', function(state)
    print(state and 'On duty' or 'Off duty')
end)

Server events ​

EventParametersWhen
cuxial_police:internal:JobChangedsrc, oldJob, newJobA player's job changed.
cuxial_police:internal:PrisonReleasedcitizenid, causeAn inmate of the built-in prison was released. cause is 'served' or 'police'.
cuxial_police:settingsAppliedidA settings section was applied. Also triggered on the client.
lua
AddEventHandler('cuxial_police:internal:PrisonReleased', function(citizenid, cause)
    print(('%s released (%s)'):format(citizenid, cause))
end)

State bags ​

State bagOnValue
cuffedPlayertrue while the player is cuffed.
escortedPlayertrue while the player is being escorted.
escortedByPlayerServer id of the escorting officer.
lua
if Player(source).state.cuffed then return end

© Cuxial