AI Core

Door locks

Lock, unlock and read doors through whichever door lock script the server runs.

Door calls go through ai-core, never through a door lock script's own exports or events (ai-doorlock included). ai-core forwards each call to the active door lock script: the one the panel's Door lock script setting picks, or the first one running (ai-doorlock, ox_doorlock, tgiann-doorlock and the others in the compatibility list).

A door is named by that script's own door id: the id you see in its door list (ai-doorlock: the door's id in the admin panel; ox_doorlock: its database number).

GetDoorlockSystem

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

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

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

Parameters

None.

Returns

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

Example

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

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

// The door ids in your config belong to one door lock script: warn when another runs.
if (core.GetDoorlockSystem() !== "ai-doorlock")
  console.log("myscript: door ids are written for ai-doorlock");

SetDoorLocked

Locks or unlocks a door.

Side: Server · Waits: no · Lib: doors.setLocked

Signature
SetDoorLocked(id: string, locked: boolean, by?: number): boolean
Lua
local ok = exports['ai-core']:SetDoorLocked('pacific_vault', false, source)

Parameters

Prop

Type

Returns

boolean: true when the door lock script accepted the change. false when no door lock script runs, the door is unknown, the script refused, id is empty or locked is not a boolean.

Example

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

const core = resourceExport("ai-core");
const VAULT = { x: 253.9, y: 225.2, z: 101.9 };

onClientCallback("myscript:hackVault", { guards: [near(VAULT, 2)], lock: true }, async (source) => {
  if (!core.HasItem(source, "laptop")) return fail("NO_LAPTOP");
  if (!(await progressFor(source, { label: Locale("HACKING"), duration: 15000 }))) return fail("CANCELLED");
  return core.SetDoorLocked("pacific_vault", false, source) ? { ok: true } : fail("DOOR_FAILED");
});

IsDoorLocked

Whether a door is locked.

Side: Server · Waits: no · Lib: doors.isLocked

Signature
IsDoorLocked(id: string): boolean | null
Lua
local locked = exports['ai-core']:IsDoorLocked('pacific_vault') -- true, false or nil

Parameters

Prop

Type

Returns

boolean | null: true locked, false unlocked. null when it is unknown: no door lock script runs, the door does not exist, the script cannot tell on the server, or id is empty.

Example

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

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

/** The heist may start only while the vault is still closed. */
export function vaultClosed(): boolean {
  return core.IsDoorLocked("pacific_vault") !== false;
}

Decide what null means for your feature. The example treats "unknown" as closed, so a missing door lock script never opens the heist early.

On this page