AI Core

Medical

Revive and heal players and check whether a player is down, through whichever death script the server runs.

Deaths and revives go through ai-core, never through a death script's own exports or state bags (ai-death included). ai-core forwards each call to the first death script running: ai-death, qbx_medical, ars_ambulancejob, qb-ambulancejob, esx_ambulancejob and the others in the compatibility list. With none running, nobody counts as down and nothing can be revived.

"Down" means dead or in last stand, as the death script sees it. Death scripts keep a downed ped alive, so never use the game's IsEntityDead to ask whether a player is down.

To react when a player dies, listen to ai-core's server event ai-core:playerDied (src, killer, weaponHash) instead of checking health. See Events and state.

GetMedicalSystem

The resource name of the death script ai-core forwards to.

Side: Server · Waits: no · Lib: medical.provider()

Signature
GetMedicalSystem(): string | null
Lua
local system = exports['ai-core']:GetMedicalSystem() -- string or nil

Parameters

None.

Returns

string | null: the death script's resource name. null when none runs.

Example

import { addCommand, resourceExport } from "@aicore-fivem/lib/server";

const core = resourceExport("ai-core");

addCommand("deathsystem", { help: "Shows the death script in use", restricted: true }, () => {
  console.log(core.GetMedicalSystem() ?? "none: revive and heal do nothing");
});

RevivePlayer

Gets a downed player back up where they lie.

Side: Server · Waits: no · Lib: medical.revive

Signature
RevivePlayer(source: number): boolean
Lua
local revived = exports['ai-core']:RevivePlayer(source)

Parameters

Prop

Type

Returns

boolean: true when the player was down and the death script revived them. false when the player was not down, is not online, no death script runs or it failed.

Example

import { onClientCallback, coordsOf, isNear, progressFor, resourceExport } from "@aicore-fivem/lib/server";
import { fail, oneArg, readId } from "@aicore-fivem/lib/shared";
import { Locale } from "common";

const core = resourceExport("ai-core");

// A medic revives a downed player next to them with a medkit.
onClientCallback("myscript:revive", { args: oneArg(readId), lock: true }, async (source, target) => {
  if (core.GetDutyJob(source) !== "ambulance") return fail("NOT_EMS");
  if (target === source || !isNear(target, coordsOf(source), 2)) return fail("TOO_FAR");
  if (!core.IsPlayerDead(target)) return fail("NOT_DOWN");
  if (!(await progressFor(source, { label: Locale("REVIVING"), duration: 10000 }))) return fail("CANCELLED");
  if (!core.RemoveItem(source, "medkit")) return fail("NO_MEDKIT");
  core.RevivePlayer(target);
  core.RefillNeeds(target);
  return { ok: true };
});

HealPlayer

Gives a player who is not down full health.

Side: Server · Waits: no · Lib: medical.heal

Signature
HealPlayer(source: number): boolean
Lua
local ok = exports['ai-core']:HealPlayer(source)

Parameters

Prop

Type

Returns

boolean: true when the heal was handed to the death script. false when the player is not online, no death script runs or it failed. A downed player needs RevivePlayer; what a death script does with a heal on a downed player is up to it.

Example

import { onClientCallback, resourceExport, near } from "@aicore-fivem/lib/server";
import { fail } from "@aicore-fivem/lib/shared";

const core = resourceExport("ai-core");
const CHECK_IN = { x: 308.4, y: -595.3, z: 43.3 };

// Hospital check-in: pay and get patched up.
onClientCallback("myscript:checkIn", { guards: [near(CHECK_IN, 2)], lock: true }, (source) => {
  if (core.IsPlayerDead(source)) return fail("IS_DOWN");
  if (!core.RemoveMoney(source, "bank", 250, "hospital")) return fail("NOT_ENOUGH_MONEY");
  core.HealPlayer(source);
  return { ok: true };
});

IsPlayerDead

Whether a player is down (dead or in last stand) in the running death script.

Side: Server · Waits: no · Lib: medical.isDead (server); on the client the lib's medical.isDead() reads the local player's state without a call

Signature
IsPlayerDead(source: number): boolean
Lua
local down = exports['ai-core']:IsPlayerDead(source)

Parameters

Prop

Type

Returns

boolean: true when the player is down. false when they are up, not online, or no death script runs.

Example

import { onClientCallback, resourceExport } from "@aicore-fivem/lib/server";
import { fail } from "@aicore-fivem/lib/shared";

const core = resourceExport("ai-core");

// A downed player cannot open the phone shop menu.
onClientCallback("myscript:openShop", (source) =>
  core.IsPlayerDead(source) ? fail("IS_DOWN") : { ok: true },
);

On this page