AI Core

Prison

Jail players, release them and read the time left, through whichever prison script the server runs.

Jail calls go through ai-core, never through a prison script's own exports or events (ai-prison included). ai-core forwards each call to the first prison script running: ai-prison, qb-prison, rcore_prison, xt-prison, then tgiann-policejob. While none runs, every call answers false or 0.

JailPlayer

Sends a player to prison for a number of minutes.

Side: Server · Waits: no · Lib: prison.jail

Signature
JailPlayer(source: number, minutes: number, by?: number): boolean
Lua
local jailed = exports['ai-core']:JailPlayer(target, 20, source)

Parameters

Prop

Type

Returns

boolean: true when the prison script took the player. false when minutes is not above 0, source is not a number, no prison script runs or it refused.

Example

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

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

addCommand("jail", {
  help: "Jails a player",
  params: [{ name: "id", type: "playerId" }, { name: "minutes", type: "number" }],
  restricted: "ai.job.police",
}, (source, args) => {
  if (core.GetDutyJob(source) !== "police") return;
  core.JailPlayer(args.id, args.minutes, source);
});

Write the matching MDT record with AddMdtRecord (kind: "jail") when the server runs an MDT.

ReleasePlayer

Lets a player out of prison.

Side: Server · Waits: no · Lib: prison.release

Signature
ReleasePlayer(source: number): boolean
Lua
local released = exports['ai-core']:ReleasePlayer(target)

Parameters

Prop

Type

Returns

boolean: true when the prison script released the player. false when the prison script did not release them (for example, they were not in prison), source is not a number or no prison script runs.

Example

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

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

addCommand("unjail", { help: "Releases a player", params: [{ name: "id", type: "playerId" }], restricted: true }, (_source, args) => {
  console.log(core.ReleasePlayer(args.id) ? "released" : "not in prison");
});

GetJailTime

How long a player still has to serve.

Side: Server · Waits: no · Lib: prison.timeLeft

Signature
GetJailTime(source: number): number
Lua
local minutes = exports['ai-core']:GetJailTime(source)

Parameters

Prop

Type

Returns

number: minutes left. 0 when the player is not in prison, source is not a number or no prison script runs.

Example

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

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

// Prisoners cannot use the phone booth.
onClientCallback("myscript:phoneBooth", (source) =>
  core.GetJailTime(source) > 0 ? fail("IN_PRISON") : { ok: true },
);

On this page