Jobs and services
Police alerts, prison, MDT records, medics, revive and heal, stress, hunger and thirst, job and gang definitions, prime time.
import { dispatch, prison, mdt, ems, medical, stress, needs, definitions, isPrimeTime } from "@aicore-fivem/lib/server";Each object here goes through one of ai-core's layers: the script the server runs for that job (an alert system, a prison, an MDT, a death script, a HUD) answers. Your script keeps working when the owner swaps it. While no such script runs, calls fail quietly (false, 0, null).
dispatch
dispatch.alert
Sends a police (or other job) alert. The alert system shows it to the on-duty members of jobs, default the police jobs.
Side: Server · Waits: no
dispatch.alert(alert: DispatchAlert): booleanlocal ok = aiLib.dispatch.alert(alert)DispatchAlert
Prop
Type
The type is DispatchAlert.
Returns
boolean: true when sent. false when no alert system runs or the alert is invalid.
Example
import { dispatch, coordsOf, createLocale } from "@aicore-fivem/lib/server";
const Locale = createLocale();
function storeRobbed(source: number, store: string) {
dispatch.alert({
code: "10-90",
title: Locale("ALERT_STORE_ROBBERY"),
message: store,
coords: coordsOf(source),
source,
icon: "store",
priority: "high",
});
}prison
Jail sentences through ai-core, whatever prison script runs.
prison.jail
Sends a loaded player to prison.
Side: Server · Waits: no
prison.jail(source: number, minutes: number, by?: number): booleanlocal ok = aiLib.prison.jail(source, minutes, by)Prop
Type
Returns true when jailed, false while no prison runs.
if (!prison.jail(target, 15, officer)) return fail("NO_PRISON");prison.release
Lets a jailed player out.
Side: Server · Waits: no
prison.release(source: number): booleanlocal ok = aiLib.prison.release(source)Returns true when released, false when not jailed or no prison runs.
prison.release(target);prison.timeLeft
Side: Server · Waits: no
prison.timeLeft(source: number): numberlocal minutes = aiLib.prison.timeLeft(source)Returns the minutes of sentence left, 0 when free.
if (prison.timeLeft(source) > 0) return fail("IN_PRISON");mdt
Police MDT records (fines, warrants, arrests, jail) through ai-core's MDT layer. Nothing is written while no MDT runs.
mdt.record
Writes a record into the police MDT.
Side: Server · Waits: no
mdt.record(record: MdtRecord): booleanlocal ok = aiLib.mdt.record(record)MdtRecord
Prop
Type
The type is MdtRecord.
Returns true when written, false when no MDT runs or it takes no such record.
if (prison.jail(target, 20, officer)) mdt.record({ kind: "jail", target, by: officer, title: "Armed robbery", minutes: 20 });mdt.provider
Side: Server · Waits: no
mdt.provider(): string | nulllocal name = aiLib.mdt.provider()Returns the MDT that records go to, or null.
if (!mdt.provider()) console.log("no MDT: records are skipped");ems
Medics through ai-core's EMS layer: an EMS script's own count and distress calls, else ai-core's duty counts and alerts.
ems.available
How many medics are free to take a call.
Side: Server · Waits: no
ems.available(jobs: string[]): numberlocal count = aiLib.ems.available(jobs)Prop
Type
Returns the number of medics on duty in jobs, leaving out busy ones when a dispatch script knows them.
// Let players respawn at the hospital only when no medic can come.
const canRespawn = ems.available(["ambulance"]) === 0;ems.distress
Sends a distress call for a player to the medics of call.jobs.
Side: Server · Waits: no
ems.distress(source: number, call: DistressCall): booleanlocal ok = aiLib.ems.distress(source, call)Prop
Type
The type is DistressCall.
Returns true when something took the call, false otherwise.
if (!ems.distress(source, { jobs: ["ambulance"], message: "Unconscious" })) return fail("NO_MEDICS");ems.provider
Side: Server · Waits: no
ems.provider(): string | nulllocal name = aiLib.ems.provider()Returns the EMS source the layer uses, "ai-core" for its own duty counts.
console.log(`medics through ${ems.provider()}`);medical
Revive, heal and the down state through ai-core's medical layer, whatever death or ambulance script runs. No Lua twin: call ai-core's exports RevivePlayer, HealPlayer, IsPlayerDead.
medical.revive
Gets a downed player up where they lie.
Side: Server · Waits: no
medical.revive(source: number): booleanReturns true when revived, false when not down or no death script runs.
if (!medical.revive(target)) return fail("NOT_DOWN");medical.heal
Gives full health to a player who is not down.
Side: Server · Waits: no
medical.heal(source: number): booleanReturns true when healed, false when no death script runs.
medical.heal(source);medical.isDead
Whether the player is down.
Side: Server · Waits: no
medical.isDead(source: number): booleanReturns true when down; false without a death script. Use it instead of reading the ped's health.
if (medical.isDead(source)) return fail("YOU_ARE_DOWN");medical.provider
Side: Server · Waits: no
medical.provider(): string | nullReturns the death script that answers (ai-death...), or null when none runs.
console.log(`deaths through ${medical.provider() ?? "nothing"}`);stress
Players' stress (0 to 100) through ai-core's stress layer, whatever HUD keeps it.
stress.gain
Adds stress points.
Side: Server · Waits: no
stress.gain(source: number, amount: number): booleanlocal ok = aiLib.stress.gain(source, amount)Prop
Type
Returns true when added, false when no HUD with stress runs.
stress.gain(source, 5); // after a shootoutstress.relieve
Takes stress points away.
Side: Server · Waits: no
stress.relieve(source: number, amount: number): booleanlocal ok = aiLib.stress.relieve(source, amount)Returns true when taken, false when no HUD with stress runs or amount is 0 or less.
inventory.registerUsableItem("cigarette", (source) => {
stress.relieve(source, 10);
});stress.provider
Side: Server · Waits: no
stress.provider(): string | nulllocal name = aiLib.stress.provider()Returns the HUD that keeps stress, or null.
if (!stress.provider()) console.log("no HUD keeps stress");needs
needs.refill
Fills hunger and thirst to full (admin revive, hospital), through the HUD that keeps them, or ai-core's character metadata without one.
Side: Server · Waits: no
needs.refill(source: number): booleanNo Lua twin: call ai-core's export RefillNeeds(source).
Returns true when refilled, false when the player has no character.
if (medical.revive(target)) needs.refill(target);Job and gang definitions
definitions.job
A job's definition as set in ai-core's panel. Each one is read once from ai-core and kept until the panel changes it, so a read is a memory lookup.
Side: Server · Waits: no
definitions.job(name: string): JobDefinition | nullNo Lua twin: call ai-core's export GetJobDefinition(name).
Returns JobDefinition (label, type, defaultDuty, listed?, grades), or null when no such job exists.
const label = definitions.job("police")?.label ?? "police";definitions.gang
Side: Server · Waits: no
definitions.gang(name: string): GangDefinition | nullNo Lua twin: call ai-core's export GetGangDefinition(name).
Returns GangDefinition (label, grades), or null.
const gang = definitions.gang("ballas");
if (!gang) return fail("UNKNOWN_GANG");Prime time
isPrimeTime
Whether it is prime time for a job, from ai-core's prime time setting. The hours come from tgiann-policealert while it runs, else from the hours set in ai-core's panel.
Side: Server · Waits: no
isPrimeTime(job?: string): booleanNo Lua twin: call ai-core's export IsPrimeTime(job).
Prop
Type
Returns true during prime time.
if (!isPrimeTime("police")) return fail("BANK_CLOSED_FOR_HEISTS");