ai-doorlock for developers
Server exports, the ox_doorlock API, GlobalState keys and the event of ai-doorlock.
To lock or unlock doors from your own script, use the lib's doors.setLocked(id, locked, by?) and doors.isLocked(id) (server). They go through ai-core's door lock layer and work with whichever door lock script the server runs. The exports below are what the layer calls while ai-doorlock is active.
A door is named by its panel id: the record key in data/doors.json (shown in the panel's door list). Typed as AiDoorlockServerExports in @aicore-fivem/shared.
import { resourceExport } from "@aicore-fivem/lib/server";
const doorlock = resourceExport("ai-doorlock");Server exports
SetDoorState
Locks or unlocks a door for everyone, without any access or distance check.
Side: Server · Waits: no
SetDoorState(id: string, locked: boolean): voidexports['ai-doorlock']:SetDoorState(id, locked)Parameters
Prop
Type
Returns
Nothing. An id that is not a panel door does nothing.
Example
import { resourceExport } from "@aicore-fivem/lib/server";
const doorlock = resourceExport("ai-doorlock");
// A lockdown: lock every listed door of the station.
const STATION_DOORS = ["mrpd_front", "mrpd_back", "mrpd_back_gate"]; // default panel ids
export function lockdown(): void {
for (const id of STATION_DOORS) doorlock.SetDoorState(id, true);
}IsLocked
Whether a door is locked now.
Side: Server · Waits: no
IsLocked(id: string): booleanlocal locked = exports['ai-doorlock']:IsLocked(id)Returns
true when locked. false when unlocked or the id is not a panel door.
ox_doorlock API
ai-doorlock provides ox_doorlock and answers two of its server exports:
| Export | What it does |
|---|---|
setDoorState(id, state) | Same as SetDoorState: true or 1 locks, anything else unlocks. |
getDoor(id) | { id, name, state } (state 1 locked, 0 unlocked; name is the panel name), or nil for an unknown id. |
Other ox_doorlock exports are not answered.
GlobalState
The lock state of each door is the GlobalState key door:<id> (true = locked), readable on the server and on every client. It is removed when the door is deleted.
local locked = GlobalState['door:mrpd_front'] == trueEvents
| Name | Kind | What it does |
|---|---|---|
ai-doorlock:toggle | client callback | (id) -> { ok, locked }: a player flips a door after the server checks distance and access. Internal; limited to 2 per second per player, and 500 ms per door. |