Skip to content

Exports & events

Public API of Cuxial Medical: exports, hooks, state bags and events to use from other resources.

Read the medical state of a player, revive, heal or injure them, and react to what happens from your own resources. All exports are called as exports.cuxial_medical:Name(...).

Shared values ​

ValueOptions
State'alive', 'laststand', 'dead'
Body zonehead, neck, spine, upper_body, lower_body, left_arm, right_arm, left_leg, right_leg
Wound typeshot, stabbed, beat, burned
Level1 to 4
CPR mode'fast', 'full'

Exports that act in the name of a medic return ok, reason. Possible reasons:

ReasonMeaning
no_ems_dutyThe medic is not EMS on duty.
no_targetThe target does not exist.
not_deadThe target is not downed.
is_downThe target is downed.
too_farMedic and target are too far apart.
cooldownThe medic acted too recently.
rate_limitToo many requests.
no_itemThe medic lacks the required item.
no_injuryThere is nothing to treat.
no_config, no_zoneMissing config block or body zone.

Server exports ​

State ​

ExportReturns
IsPlayerDead(src)false, 'laststand' or 'dead'.
GetPlayerPhase(src)0 when alive, otherwise the phase number.
GetPlayerDeathInjury(src){ injury, location, name } for the hit that downed the player, or nil. name is the weapon label.
GetMedicalState(src){ isDead, phase, deathInjury, injuries }.
GetAllDeadPlayers(){ [src] = state } for every downed player.
GetAllMedicalStates(){ [src] = { state, phase, deathInjury, injuries } } for every downed player.
lua
if exports.cuxial_medical:IsPlayerDead(source) then
    return -- the player is downed
end

KillPlayer ​

Downs a player. On a player who is already downed, moves them to the next phase.

lua
exports.cuxial_medical:KillPlayer(target)

Returns: boolean. false when the player does not exist.

RevivePlayer ​

Revives a player, clears their injuries and resets hunger, thirst and stress. Works on any player, with no item and no distance check.

lua
exports.cuxial_medical:RevivePlayer(target, options)
ParameterTypeDescription
targetnumberServer id of the player.
optionstable | number | nilA table { anim, hp, by }, or the server id of whoever revives.
options.animbooleantrue plays the get-up animation. With a table it is off unless set; with a number or nothing it is on.
options.hpnumberFinal health, up to 200. Full health when omitted.
options.bynumberServer id of whoever revives, for the log.

Returns: boolean.

lua
exports.cuxial_medical:RevivePlayer(target, { anim = true, by = source })

RevivePlayerWithHP ​

Revives a player without animation and with an exact health.

lua
exports.cuxial_medical:RevivePlayerWithHP(target, hp)
ParameterTypeDescription
targetnumberServer id of the player.
hpnumberFinal health, from 1 to 200. The player never gets up below 101.

Returns: boolean.

HealPlayer ​

Heals a player, clears their injuries and resets hunger, thirst and stress. A downed player is revived first, without animation.

lua
exports.cuxial_medical:HealPlayer(target, full, quiet)
ParameterTypeDescription
targetnumberServer id of the player.
fullbooleantrue restores full health. Otherwise adds 25.
quietbooleantrue hides the notification.

Returns: boolean.

lua
exports.cuxial_medical:HealPlayer(source, true, true)

Other treatment exports ​

ExportWhat it doesReturns
HealPlayerBy(target, amount)Adds amount health, up to 200. Does not touch injuries.boolean
SedatePlayer(target)Sedates the player for items.sedate.duration. Fails on a downed player.boolean
ResetPlayerNeeds(src)Sets hunger and thirst to 100 and stress to 0.nothing

Acting as a medic ​

These exports apply the same rules as the medic's own actions: EMS on duty, distance, cooldown and items.

ExportWhat it doesReturns
GetPatientReport(medic, target)Full report of a patient.report, or nil, reason
CanResuscitate(medic, target, mode)Checks whether the medic can revive the patient.ok, reason
ResuscitatePatient(medic, target, mode)Revives the patient and consumes the item of the CPR mode.ok, reason
TreatZone(medic, target, bodyZone)Bandages one zone: removes that injury and restores health. Uses treatment.bandage.ok, reason

The report contains targetId, firstname, lastname, fullName, citizenid, isDead, state, phase, phaseKey, phaseLabel, health, maxHealth, hpPercent, deathInjury, injuries, maxSeverity, totalBleed and timestamp. Each entry of injuries is indexed by body zone and has injury, level, bleed, label and injuryLabel.

lua
local ok, reason = exports.cuxial_medical:ResuscitatePatient(source, target, 'fast')
if not ok then print(reason) end

EMS ​

ExportReturns
GetEMSCount()Number of EMS on duty.
IsEMSOnDuty(src)boolean.

Injuries ​

ExportWhat it doesReturns
InjurePlayer(src, bodyZone, type, level, bleed)Adds or replaces the injury of a zone. bleed goes from 0 to 4.boolean
ClearInjury(src, bodyZone)Removes the injury of a zone.nothing
ClearInjuryType(src, type)Removes every injury of a type.nothing
ClearPlayerInjuries(src)Removes every injury.nothing
GetPlayerInjuries(src){ [zone] = { bodyPart, injury, level, bleed } }
GetInjuryAt(src, bodyZone)The injury of that zone, or nil.
HasInjury(src, bodyZone)Without bodyZone, checks for any injury.boolean
GetMaxSeverity(src)Highest level, 0 with no injuries.
GetTotalBleed(src)Sum of the bleeding of all injuries.
DiagnosePlayer(src){ injuries, maxSeverity, totalBleed, deathInjury }, with translated labels.
GetAllInjuredPlayers(){ [src] = { count, maxSeverity, totalBleed } }
lua
exports.cuxial_medical:InjurePlayer(source, 'left_leg', 'stabbed', 2, 1)

Medical history ​

Stored in cuxial_medical_logs. Writing is skipped with logs.persistence = false.

ExportWhat it doesReturns
LogMedicalEvent(patientSrc, eventType, doctorSrc, payload)Saves an event. eventType is death, revive, treat, diagnose or heal. doctorSrc and payload (table) are optional.nothing
GetMedicalHistory(citizenid, limit)Latest events of a character. limit is 25 by default, 100 at most.Rows with id, event_type, doctor_citizenid, doctor_name, payload, created_at.
GetDoctorMedicalStats(doctorCitizenid, since)Counts the actions of a medic. since is a timestamp in milliseconds.{ revives, treats, diagnoses, heals }
lua
local history = exports.cuxial_medical:GetMedicalHistory(citizenid, 10)

getSetting ​

Returns the live value of a settings section.

lua
local phases = exports.cuxial_medical:getSetting('config.death').phases

Valid identifiers: config.jobs, config.death, config.respawn, config.injury, config.treatment, config.items, config.stretcher, config.finisher, config.extras, config.dispatch, config.logs and data.hospitals. Any other returns nil.

Server hooks ​

Register a function that runs when something happens. Each on… export returns the function, to pass to the matching off… export.

lua
exports.cuxial_medical:onTreatment('revive', function(medic, target, data)
    print(('%s revived %s (%s)'):format(medic, target, data.mode))
end)
ExportEventArguments
onTreatment / offTreatmentrevivemedic, target, { health, injury, mode }. Only revives done by a medic.
healmedic, target
treatStart, treatEndmedic, target, woundType
diagnosemedic, target
onFinisher / offFinisherfinishedattacker, victim
onHospital / offHospitalbedReserved, bedReleasedsrc, hospitalId, bedIndex
chargedsrc, account, cost, hospitalId
onStretcher / offStretcheradd, remove{ netId, owner }
seat{ netId, target, medic, pose }
unseat{ netId, target, reason }
onDispatch / offDispatchrequestAddedsrc, name
requestRemovedsrc

Client exports ​

State ​

ExportReturns
isPlayerDead(serverId)false, 'laststand' or 'dead'. Without serverId, the local player.
getDeathPhase()Phase of the local player, 0 when alive.
getDeathPhaseKey()id of the current phase, or nil.
getMedicalState(){ isDead, phase, phaseKey, injury, location, weapon }
isZoomActive()boolean
pauseDeathAnimation(), resumeDeathAnimation()Stop and resume the downed animation, to play your own on a downed player.
lua
if exports.cuxial_medical:isPlayerDead() then return end

Injuries ​

All of them act on the local player.

ExportReturns
GetPlayerInjuries(){ [zone] = injury }
GetInjuryAt(bodyZone)The injury, or nil.
HasInjury(bodyZone)boolean. Without bodyZone, any injury.
IsInjured(), IsLimping(), IsBleeding()boolean
GetMaxSeverity(), GetTotalBleed()number
AddInjury(bodyZone, type, level, bleed)boolean
ClearInjury(bodyZone), ClearInjuryType(type), ClearAllInjuries()nothing

Hospital ​

ExportWhat it doesReturns
requestCheckIn(hospitalId)Check-in with the rules of the reception: hospital enabled, player standing, within the radius, medics allowing it. Notifies the player when refused.boolean
attemptCheckIn(hospitalId)Starts the check-in without those rules.boolean
layOnBed(hospitalId, bedIndex)Lays the player on a bed.boolean
getUpFromBed()Gets the player up.nothing
resolveBed(hospitalId, bedIndex)Position, heading and animations of a bed.table or nil

hospitalId is optional in both check-in exports: the nearest enabled hospital is used. They wait until the treatment ends.

lua
exports.cuxial_medical:requestCheckIn()

Medic actions ​

For menus and radial wheels. They act on the nearest player, need EMS on duty and follow the item rules.

ExportWhat it doesReturns
reviveTarget(options)CPR on the nearest downed player. options.mode is 'fast' or 'full'.boolean
healTarget()Heals the nearest player, or yourself.boolean
useSedative()Sedates the nearest player.boolean
treatPatient(woundType)Treats one wound type.boolean
diagnosePlayer()Diagnoses the nearest player and shows the result.report or nil
ToggleDuty()Switches the EMS duty.ok, onduty
GetDistressRequests()Open distress calls.{ [src] = name }
PlaceInVehicle()Puts the nearest downed or sedated player in the nearest vehicle.boolean
RemoveFromVehicle()Makes the occupants of the nearest vehicle leave it.boolean
IntoVehicle()Warps the local player into a free seat of the nearest vehicle.boolean
RemoveWeapons()Removes every weapon of the local player.nothing
lua
exports.cuxial_medical:reviveTarget({ mode = 'full' })

CPR animation ​

ExportWhat it doesReturns
ReviveAnimation(target, options)Plays the CPR animation on medic and patient. options: mode, lockCamera, unarmTarget. Does not revive.true when it completes
CancelReviveAnimation(target)Cancels it.boolean
IsReviveInProgress()busy, target, mode
GetReviveAnimDuration(mode)Milliseconds

Stretcher ​

ExportWhat it does
toggleStretcher()Same as /stretcher.
spawnStretcher()Places a stretcher. Returns entity, netId.
pickupStretcher()Picks up the stretcher within 3 metres. Returns boolean.
deleteStretcher()Removes the stretcher within 5 metres.
placeNearestOnStretcher(pose)Places the nearest downed or sedated player on the nearest stretcher.
removeFromStretcher()Takes the patient off the nearest stretcher.
toggleStretcherExtra(name)Toggles an accessory: headrest, backboard, monitor, redbag or bluebag.
isPlayerUsingStretcher()true when the local player lies on a stretcher.

Poses: lie_back (default), lie_left, lie_prone, sit_up, sit_end, sit_left, sit_right, cpr.

lua
exports.cuxial_medical:placeNearestOnStretcher('sit_up')

Finisher and knockout ​

ExportWhat it does
performFinisher(victimPed)Starts the finisher on that ped. Returns boolean.
isFinisherBusy()boolean
manuallyKnockout()Knocks out the local player. Needs extras.knockout.enabled = true.
disableKnockoutLoop(state)true blocks knockouts, false allows them again.

Client hooks ​

Same pattern as the server hooks.

lua
exports.cuxial_medical:onDeath('playerDeath', function(data)
    print(data.state, data.injury, data.bodyPart)
end)
ExportEventArguments
onDamage / offDamagedamaged{ ped, weapon, bone, healthDiff, armourDiff, currentHealth, currentArmour }
died{ ped, weapon, bone, cause, via }
onInjury / offInjuryapplied{ bodyPart, injury, level, bleed, weapon }
cleared{ bodyPart }
allCleared, limpStart, limpStopnone
blackout{ bodyPart, level, duration }
onDeath / offDeathplayerDeath{ state, injury, bodyPart, weapon }
phaseChange, resumephaseIndex, phaseId
playerSpawnnone
onReviveAnim / offReviveAnimstarted, complete, cancelledtarget, mode

State bags ​

Written by the server. Read them, do not write them.

State bagScopeValue
cuxial:statePlayer'alive', 'laststand' or 'dead'
cuxial:phasePlayerPhase number, 0 when alive
cuxial:injuriesPlayer{ [zone] = { bodyPart, injury, level, bleed } }, or nil
isDeadPlayerboolean
qbx_medical:deathStatePlayer1 alive, 2 last stand, 3 dead. With compat.qbxMedicalStateBag = true
cuxialEmsOnlineGlobalEMS on duty
lua
local downed = Player(source).state['cuxial:state'] ~= 'alive'
local medics = GlobalState.cuxialEmsOnline or 0

The player metadata isdead and inlaststand are kept up to date too.

Excluding a player ​

Set the player state bag inDuel or inEvent to any value and Cuxial Medical ignores the damage and the death of that player. Set it back to nil to return to normal.

lua
Player(source).state:set('inEvent', true, true)

Events ​

Distress call ​

Sends a distress call for the player, downed or not. Use it from a phone or a panic button.

lua
TriggerServerEvent('cuxial_medical:server:Dispatch', { street = 'Alta Street' })

street is optional. The position is taken from the player on the server. The cooldown of dispatch.cooldownMs applies.

Compatibility events ​

Resources written for the ambulance job of QBCore keep working with these events:

EventSideWhat it does
hospital:client:ReviveClientAsks for a self revive. Accepted only for staff and for players with inDuel or inEvent.
hospital:client:RevivePlayerClientThe medic revives the nearest player.
hospital:client:TreatWoundsClientThe medic heals the nearest player.
hospital:client:CheckStatusClientThe medic diagnoses the nearest player.
hospital:server:emergencyAlertServerSends a distress call.

With compat.qbxMedicalEvents = true the script also triggers qbx_medical:client:onPlayerDied, qbx_medical:client:onPlayerLaststand and qbx_medical:client:playerRevived on the player.

© Cuxial