ai-exitsleeping for developers
Server and client exports, hook events and the sleeper shape of ai-exitsleeping.
ai-exitsleeping has one server export, three client exports and four local hook events (the original script's editable hooks). None are typed in @aicore-fivem/shared: in TypeScript call them with callExport.
Server exports
AddCreateCheck
Adds a check that runs when a player logs out. Return false to leave no sleeping body (an apartment, an event zone, a jail). Use it when your script knows places where a body must not stay.
Side: Server · Waits: no
AddCreateCheck(id: string, check: (source: number, charId: number, coords: { x: number; y: number; z: number; heading: number }) => boolean): voidexports['ai-exitsleeping']:AddCreateCheck(id, function(source, charId, coords) return true end)Parameters
Prop
Type
Returns
Nothing. The check is dropped by itself when your resource stops.
Example
import { callExport } from "@aicore-fivem/lib/server";
// No sleeping bodies inside the event arena (200 m around its centre).
const ARENA = { x: -324.0, y: -1968.0, z: 21.6 };
callExport("ai-exitsleeping", "AddCreateCheck", "arena",
(_source: number, _charId: number, c: { x: number; y: number; z: number }) =>
Math.hypot(c.x - ARENA.x, c.y - ARENA.y) > 200,
);For a fixed place, a Hidden area in the panel does the same without code.
Client exports
PlayerLoaded
Wakes the local player's body and starts showing the bodies around. Call it from a spawn script after its own final spawn, and only when the panel's Wake up on is PlayerLoaded export (spawn script).
Side: Client · Waits: no
PlayerLoaded(): voidexports['ai-exitsleeping']:PlayerLoaded()Returns
Nothing. A second call before the next character switch does nothing.
SetHidden
Hides every sleeping body on this client while any reason holds. Use it while the player is in a place where bodies would look wrong (a shell interior, a cutscene).
Side: Client · Waits: no
SetHidden(reason: string, hidden: boolean): voidexports['ai-exitsleeping']:SetHidden('myshell', true)Parameters
Prop
Type
Returns
Nothing. Your reasons are dropped when your resource stops.
Example
import { callExport } from "@aicore-fivem/lib/client";
export function enterShell(): void {
callExport("ai-exitsleeping", "SetHidden", "shell", true);
}
export function leaveShell(): void {
callExport("ai-exitsleeping", "SetHidden", "shell", false);
}SetCarryBlocked
Hides the carry option on this client while any reason holds (your own rules: a minigame, a jail).
Side: Client · Waits: no
SetCarryBlocked(reason: string, blocked: boolean): voidexports['ai-exitsleeping']:SetCarryBlocked('minigame', true)Returns
Nothing. Same reason rules as SetHidden. Carrying is already blocked in a vehicle, while downed and while cuffed.
Hook events
Local events (not sent over the network) you can listen to.
ai-exitsleeping:created
A sleeping body was created for a character that logged out. Side: Server.
Prop
Type
ai-exitsleeping:removed
A sleeping body is gone (woke up, expired, toggled off). Side: Server. Argument: charId: number.
ai-exitsleeping:positionChanged
A body's position changed (carried, driven, put down). Side: Server. Arguments: charId: number, coords: { x, y, z, heading }.
ai-exitsleeping:client:pedSpawned
A sleeping ped was created on this client. Side: Client. Arguments: ped: number (a local, non-networked ped), view: SleeperView.
// Server: log every body that appears and disappears.
on("ai-exitsleeping:created", (charId: number, view: { x: number; y: number; z: number }) => {
console.log(`character ${charId} fell asleep at ${view.x}, ${view.y}, ${view.z}`);
});
on("ai-exitsleeping:removed", (charId: number) => {
console.log(`character ${charId} woke up`);
});SleeperView
Prop
Type
Internal events
ai-exitsleeping:wake, area, client:area, look, startCarry, stopCarry, putInVehicle, takeOut are between its own client and server; do not call them.