RedM documentation

Murphy's Doctor

Developers

Server exports


Call them from any server script of another resource:

lua
local isDoctor = exports.murphy_doctor:IsPlayerDoctor(source)

Conventions used on this page:

  • src is a connected player's server id; charid is the character identifier (see Identifiers).
  • Module: the export is only registered when that module is enabled (see Module guards). "always" means the export exists whatever the configuration.
  • Exports marked DB run a synchronous database query: call them from a thread or an event handler, not every tick.

There are 37 server exports.

System Exports
Doctors and availability IsPlayerDoctor, IsPlayerDoctorAsync, CheckDoctorByJob, CheckDoctorByDatabaseSync, CheckDoctorByWhitelist, InvalidateDoctorCache, InvalidateAllDoctorCache, RefreshDoctorStatus, FindAllDoctors, FindNearbyDoctorsAdvanced, IsDutyServiceGateActive, IsDoctorAvailable, FindNearbyAvailableDoctors, IsDoctorOnDuty
Health AdminHealCharacter, GetMedicalCatalog
Coma and revive AuthorizeComaExit
Diseases, infection and immunity TryInfect, RollConsumableInfection, GrantImmunity, IsImmune, GetImmunityExpiry, SyncDiseasesToPlayer, BuildClientDiseasePayload
Addiction GetAddictions, ReduceAddiction
Alcohol OnAlcoholConsumed, GetLiverWear
Billing GetUnpaidInvoices
Incidents GetIncidents
Death certificates GetDeathCertificates
Medical file GetMedicalFile
Transport GetTransportState
Epidemics GetActiveOutbreaks, StartOutbreak, StopOutbreak
Diagnostics RunSelfTest

Doctors and availability

Doctor detection follows Config.Interactions.DoctorDetection ("job", "database", "whitelist", "both" for job plus database, "any" for all three, or a table such as { "job", "whitelist" }). When Config.Interactions.DoctorSpeFromCraft is true and murphy_craft runs, a player who unlocked the root node of the Config.Interactions.DoctorSpeCraftId specialisation also counts as a doctor.

IsPlayerDoctor

lua
exports.murphy_doctor:IsPlayerDoctor(src) --> boolean
Parameter Type Description
src number Player server id

Returns true when the player is a doctor under the configured detection modes. The result is cached 30 seconds per player. No database query: the "database" mode reads an in-memory copy of the members table.

Module: always.

lua
RegisterNetEvent("pharmacy:server:open", function()
local src = source
if not exports.murphy_doctor:IsPlayerDoctor(src) then return end
TriggerClientEvent("pharmacy:client:open", src)
end)

IsPlayerDoctorAsync

lua
exports.murphy_doctor:IsPlayerDoctorAsync(src, callback)
Parameter Type Description
src number Player server id
callback function(isDoctor: boolean) Called with the result

Same check as IsPlayerDoctor, callback form. Every detection path is synchronous, so the callback runs before the export returns. Module: always.

CheckDoctorByJob

lua
exports.murphy_doctor:CheckDoctorByJob(src) --> boolean

Checks only the job: GetCharJob(src) compared (case-insensitive) with Config.DoctorJobs. When Config.Interactions.DoctorJobRequireDuty is true and the adapter exposes GetCharJobDuty (RSG), an off-duty job returns false. Uncached, ignores DoctorDetection. Module: always.

CheckDoctorByDatabaseSync

lua
exports.murphy_doctor:CheckDoctorByDatabaseSync(src) --> boolean

Checks only the dispensary membership (murphy_doctor_members), read from the in-memory set. The set is loaded a few seconds after start and reloaded when a member is added or removed. Uncached, ignores DoctorDetection. Module: always.

CheckDoctorByWhitelist

lua
exports.murphy_doctor:CheckDoctorByWhitelist(src) --> boolean

Checks only Config.DoctorWhitelist. Matches the character identifier or any account identifier of the player (license:, steam:, discord:, fivem:...). Uncached. Module: always.

InvalidateDoctorCache

lua
exports.murphy_doctor:InvalidateDoctorCache(src)

Drops the cached doctor status of one player. Call it after you change a player's job or membership yourself, so the next check is fresh instead of waiting up to 30 seconds. This clears the server cache only; the player's client keeps its own cache (see the client event murphy_doctor:invalidateDoctorCache in Events). Module: always.

InvalidateAllDoctorCache

lua
exports.murphy_doctor:InvalidateAllDoctorCache()

Drops the cached status of every player. Module: always.

RefreshDoctorStatus

lua
exports.murphy_doctor:RefreshDoctorStatus(src) --> boolean
exports.murphy_doctor:RefreshDoctorStatus(src, callback) -- callback(isDoctor)

Invalidates the cache of src, then checks again. Without a callback the new status is returned; with one it is passed to the callback. Module: always.

lua
-- your job script, after a job change
exports.murphy_doctor:RefreshDoctorStatus(src)
TriggerClientEvent("murphy_doctor:invalidateDoctorCache", src)

FindAllDoctors

lua
exports.murphy_doctor:FindAllDoctors() --> { { serverId, name, isOnline }, ... }

Every connected player for whom IsPlayerDoctor is true. name is "first last" from the adapter, isOnline is always true. Module: always.

FindNearbyDoctorsAdvanced

lua
exports.murphy_doctor:FindNearbyDoctorsAdvanced(x, y, z, radius) --> { { serverId, distance, name }, ... }
Parameter Type Description
x, y, z number Search origin
radius number Radius in metres

Connected doctors within radius, closest first. Ignores duty. Module: always.

IsDutyServiceGateActive

lua
exports.murphy_doctor:IsDutyServiceGateActive() --> boolean

true when Config.Duty.Enabled is true and Config.Duty.GateServices is not false. When the gate is active, help calls and the nurse NPC only count doctors who are clocked in. Module: always.

IsDoctorAvailable

lua
exports.murphy_doctor:IsDoctorAvailable(src) --> boolean

true when the player is a doctor and, if the duty gate is active, clocked in. Without the gate (or when the duty module is not loaded) it equals IsPlayerDoctor. Module: always.

FindNearbyAvailableDoctors

lua
exports.murphy_doctor:FindNearbyAvailableDoctors(x, y, z, radius) --> { { serverId, distance, name }, ... }

Same as FindNearbyDoctorsAdvanced, filtered with IsDoctorAvailable. This is the list the help calls use. Module: always.

lua
local coords = GetEntityCoords(GetPlayerPed(src))
local doctors = exports.murphy_doctor:FindNearbyAvailableDoctors(coords.x, coords.y, coords.z, 500.0)
if #doctors == 0 then
-- no doctor on duty nearby: fall back to your own NPC
end

IsDoctorOnDuty

lua
exports.murphy_doctor:IsDoctorOnDuty(src) --> boolean

true when the player's character is clocked in at a dispensary. Module: Config.Duty.


Health

AdminHealCharacter

lua
exports.murphy_doctor:AdminHealCharacter(charid, opts) --> ok: boolean, errKey: string|nil
exports.murphy_doctor:AdminHealCharacter(src, parts) -- legacy form

Heals the online player whose active character is charid.

Form Arguments Effect
New, full heal charid, nil (or { parts = "all" }) Clears every injury and condition, sets temperature to 37, restores health and refills the health core
New, partial heal charid, { parts = { "head", "left-arm" } } Removes only the listed body parts that carry an injury, restores health and the core
Legacy src (server id), "all" or { "head", ... } Same, the first argument being a server id

Returns true on success, otherwise false and one of invalid_args, invalid_parts, target_offline, no_health_data.

Side effects: saves the health row, and sends the client events murphy_doctor:healthRestored then murphy_doctor:applyBandageHeal (full heal) or murphy_doctor:applyTreatmentEffects (partial heal). Diseases, immunities, addictions and liver wear are kept. It does not revive a player in a coma: see Coma and revive.

Module: always.

lua
RegisterCommand("healchar", function(source, args)
local ok, err = exports.murphy_doctor:AdminHealCharacter(args[1]) -- charid
if not ok then print("heal failed: " .. tostring(err)) end
end, true)
-- Heal only the legs of server id 12
exports.murphy_doctor:AdminHealCharacter(12, { "left-leg", "right-leg" })

GetMedicalCatalog

lua
exports.murphy_doctor:GetMedicalCatalog() --> { diseases = {...}, conditions = {...} }

Localized labels for dashboards, logs and admin panels:

lua
{
diseases = {
[diseaseId] = { label = "Cholera", urgency = "haute" }, -- one entry per grimoire id
...
},
conditions = { cold = "...", hot = "...", bleeding = "...", poisoned = "...", fever = "..." },
}

label follows Config.Locale. urgency is the raw urgency key of the grimoire entry (modérée, haute, critique or variable in the shipped config). Module: always.


Coma and revive

There is no "is in coma" server export. Read the replicated state bag murphy_doctor:coma (see State bags) or ask the client (IsInComa).

AuthorizeComaExit

lua
exports.murphy_doctor:AuthorizeComaExit(src)
Parameter Type Description
src number Player server id

Allows the next coma exit of this player for 60 seconds, even if the coma timer is not over. With Config.Coma.ServerExitCheck = true (default) the server refuses an early exit that it did not cause: the player gets up on their screen, but the coma stays in the database and comes back on the next connection. Call this export right before any revive issued by your own resource.

The VORP (vorp_core:Server:OnPlayerRevive) and RSG (rsg-adminmenu:server:playerrevive) admin revives already call it through the server adapters.

Module: always.

lua
RegisterCommand("myrevive", function(source, args)
local target = tonumber(args[1])
if not target then return end
exports.murphy_doctor:AuthorizeComaExit(target)
-- resurrect in place at full health, through murphy_doctor's own client handler
TriggerClientEvent("murphy_doctor:revivePlayer", target, source)
end, true)

Diseases, infection and immunity

TryInfect

lua
exports.murphy_doctor:TryInfect(src, diseaseId, sourceTag) --> boolean
Parameter Type Description
src number Player server id
diseaseId string Grimoire id, for example "cholera"
sourceTag string, optional Free text shown in the Discord log, for example "well_water"

Gives the disease. No probability roll: your code decides. Picks 2 to 4 visible symptoms from the grimoire entry, saves the disease, pushes the disease list to the client and, when Config.Infection.NotifyOnInfection is on and the disease has no incubation, tells the player they feel sick (without naming the disease).

Returns false when Config.Infection.Enabled is false, the player has no loaded health data, is already sick with this disease, or is immune to it.

Module: always (inert without Config.Infection.Enabled).

lua
if math.random() < 0.20 then
exports.murphy_doctor:TryInfect(src, "cholera", "well_water")
end

RollConsumableInfection

lua
exports.murphy_doctor:RollConsumableInfection(src, itemName) --> boolean

Rolls the chances listed for itemName in Config.Infection.Consumable.Items and infects on a hit. A per-item cooldown (Config.Infection.Consumable.RollIntervalSeconds) prevents spam. Already called for every consumable used through murphy_doctor: call it only for items consumed outside the script. Returns true when a disease was applied.

Module: always (inert without Config.Infection.Enabled and Config.Infection.Consumable.Enabled).

GrantImmunity

lua
exports.murphy_doctor:GrantImmunity(src, diseaseId, durationSeconds, opts) --> boolean
Parameter Type Description
src number Player server id
diseaseId string Grimoire id
durationSeconds number Immunity length, greater than 0
opts table, optional { silent = bool, notifyText = string or { k = "locale.key" }, vaccineItem = string }

Saves the immunity right away. Unless silent, the player gets a notification: notifyText, else the notifyText of Config.Infection.Vaccines[vaccineItem], else a built-in message for variole and cholera. Returns false when the arguments are invalid, the player has no loaded health data, or the player is already immune for longer.

Module: always.

lua
exports.murphy_doctor:GrantImmunity(src, "cholera", 30 * 24 * 3600, {
notifyText = "You have been vaccinated against cholera.",
})

IsImmune

lua
exports.murphy_doctor:IsImmune(src, diseaseId) --> boolean

true while the immunity has not expired. Module: always.

GetImmunityExpiry

lua
exports.murphy_doctor:GetImmunityExpiry(src, diseaseId) --> number|nil

Expiry as a Unix timestamp (seconds), or nil when the player never had that immunity. The value may be in the past. Module: always.

SyncDiseasesToPlayer

lua
exports.murphy_doctor:SyncDiseasesToPlayer(src)

Pushes the player's disease list to their client now (it is pushed every 30 seconds anyway), through the client event murphy_doctor:syncDiseases. Module: always.

BuildClientDiseasePayload

lua
exports.murphy_doctor:BuildClientDiseasePayload(diseases) --> table

Pure helper. Copies a { [diseaseId] = state } table and adds symptomatic = true|false to each entry (incubation from Config.Treatment.DiseaseEffects[id].incubationSeconds, measured on the server clock from appliedAt). Never modifies its input. Module: always.


Addiction

Module for both: Config.Addiction.

GetAddictions

lua
exports.murphy_doctor:GetAddictions(src) --> { [substance] = { level, dependent, withdrawal }, ... }

substance is a key of Config.Addiction.Substances (alcohol, tobacco, opiates by default). Only substances with a level above 0 (or dependent) are listed. level goes from 0 to 100 (decayed to now), dependent is level >= dependentAt, withdrawal is true when dependent and the last use is older than withdrawalAfterMinutes. Returns {} when the player has no character. DB on the first call for a character (then cached).

ReduceAddiction

lua
exports.murphy_doctor:ReduceAddiction(src, substance, amount) --> boolean

Lowers the level by amount (a negative amount raises it), clamped to 0 to 100, saves it and pushes the new flags to the client. Returns false for an unknown player or substance.

lua
-- a rehab session
exports.murphy_doctor:ReduceAddiction(src, "opiates", 25)

Alcohol

OnAlcoholConsumed

lua
exports.murphy_doctor:OnAlcoholConsumed(src, units)

Adds liver wear for units alcohol units (units * Config.Alcohol.Wear.GainPerAlcoholUnit, capped at Config.Alcohol.Wear.Max) and saves it. Already called for every alcoholic consumable used through murphy_doctor: call it only for drinks served by your own script. It does not change the player's drunkenness, which is client side (see SetAlcoholLevel in Client exports).

Module: always (no-op without Config.Alcohol.Enabled).

GetLiverWear

lua
exports.murphy_doctor:GetLiverWear(src) --> number

Current liver wear, 0 when healthy, up to Config.Alcohol.Wear.Max. Module: always.


Billing

GetUnpaidInvoices

lua
exports.murphy_doctor:GetUnpaidInvoices(charid) --> { { id, amount, reason, doctor, dispensary, at }, ... }

Unpaid invoices of a character, oldest first. dispensary is the dispensary name from Config.Dispensaries, at a Unix timestamp. DB. Module: Config.Billing.

lua
local charid = MyFramework.GetCharacterId(src) -- your framework's character id (see Identifiers)
local unpaid = exports.murphy_doctor:GetUnpaidInvoices(charid)
if #unpaid > 0 then
-- refuse the train ticket until the doctor is paid
end

Incidents

GetIncidents

lua
exports.murphy_doctor:GetIncidents(filter) --> { { id, victim_name, cause, weapon, attacker_name, attacker_npc, zone, at }, ... }
Filter key Type Description
victim string Victim charid
attacker string Attacker charid
name string Part of the victim or attacker name
limit number 1 to 100, default Config.Incidents.MaxRows

Coma records, newest first. Every filter is optional (nil returns the latest rows). cause is a coma cause key, attacker_npc is 1 when an NPC knocked the victim out, at is a Unix timestamp. DB. Module: Config.Incidents.

lua
-- sheriff office terminal
local rows = exports.murphy_doctor:GetIncidents({ attacker = suspectCharid, limit = 10 })

Death certificates

GetDeathCertificates

lua
exports.murphy_doctor:GetDeathCertificates(filter) --> { {...}, ... }
Filter key Type Description
deceased string charid of the deceased
name string Part of the deceased's name
limit number 1 to 100, default Config.Autopsy.MaxRows

Signed death certificates, newest first. Each row: certificate_id, deceased_id (nil for an NPC), deceased_name, cause, weapon, wound (body part), time_of_death, place, notes, doctor_name, at (Unix timestamp). DB. Module: Config.Autopsy (enabled unless set to false).


Medical file

GetMedicalFile

lua
exports.murphy_doctor:GetMedicalFile(charid) --> table|nil

Everything the doctors know about a character, whether the player is online or not. Returns nil for an empty identifier. Shape:

Field Content
identifier The charid
name, surname From the latest report, if any
bloodType, allergies, conditions, notes Written by doctors in the medical file (strings, empty when unset)
updatedBy, updated Last editor and date of those notes
diseases Array of localized disease names
vaccines Array of { name, expires } (expires as YYYY-MM-DD) for valid immunities
liver Liver wear 0 to 100, or nil
addictions Array of { name, level, dependent } for substances at half the dependence threshold or more
death { id, date, cause, doctor } of the last death certificate, or nil
history Array of { id, kind, date, doctor, summary }, newest first; kind is report, bed or certificate

The export reads every dispensary's reports, whatever Config.Archives.SharedArchives says. DB. Module: Config.Records (enabled unless set to false).


Transport

GetTransportState

lua
local state, bed = exports.murphy_doctor:GetTransportState(src)
--> "carried" | "stretcher" | "bed" | nil, bedKey (only for "bed")

Is the player carried on a shoulder, lying on a stretcher or in a dispensary bed? For a bed, the second value is the key of the bed in the transport config. Module: Config.Transport (enabled unless set to false).

lua
-- jail script: never teleport a patient who lies in a hospital bed
if exports.murphy_doctor:GetTransportState(src) == "bed" then return end

Epidemics

Module for all three: Config.Epidemics.

GetActiveOutbreaks

lua
exports.murphy_doctor:GetActiveOutbreaks() --> { { id, outbreak, diseaseId, zone, zoneLabel, startedAt, endsAt, infected }, ... }

Active outbreaks, sorted by id. outbreak is a key of Config.Epidemics.Outbreaks, zone a key of Config.Epidemics.Zones, startedAt / endsAt Unix timestamps, infected the number of players infected so far.

StartOutbreak

lua
local id, err = exports.murphy_doctor:StartOutbreak(outbreak, zoneId, hours)
--> number | nil, "unknown outbreak" | "unknown zone" | "already active" | "too many active outbreaks"

Starts an outbreak in a zone. hours is optional (defaults to the outbreak's own hours, then 24). Doctors are warned, and so are players inside the zone when Config.Epidemics.AnnounceToZone is on. Fires the server event murphy_doctor:outbreakChanged. Outbreaks survive a restart (resource KVP).

StopOutbreak

lua
exports.murphy_doctor:StopOutbreak(id) --> boolean
exports.murphy_doctor:StopOutbreak("all") --> true

Ends one outbreak (or all). Returns false for an unknown id. Fires murphy_doctor:outbreakChanged.

lua
-- a newspaper script announcing an epidemic in Saint Denis
local id, err = exports.murphy_doctor:StartOutbreak("cholera", "saintdenis", 12)
if not id then print("outbreak not started: " .. err) end

Diagnostics

RunSelfTest

lua
local lines, counts = exports.murphy_doctor:RunSelfTest(serverId)
--> { "[OK] ...", "[WARN] ...", "[FAIL] ...", ..., "Summary: ..." }, { OK = n, WARN = n, FAIL = n }

The same report as the doc_selftest console command: adapter functions, dependencies, tables, item names, known conflicts. With serverId, it adds that player's character, health cache, doctor and staff status. Module: always.


Last updated: November 20, 2026