AI Core

Client events

Every client-side local event ai-core fires - the local character loaded or unloaded, down state, cached values, HUD visibility, world sync, job definitions, key hints, seat belt - with arguments and listeners.

ai-core's client fires these events with TriggerEvent on the player's own game. Every client resource of that player hears them; other players never do. They describe the local player only.

ai-core:client:playerLoaded

The local player's character stands in the world. Start your per-character client work here (HUD values, job blips, loops).

Side: Client · Constant: CORE.clientPlayerLoadedEvent

Arguments

Prop

Type

Listener

resource/client/index.ts
import { resourceExport } from "@aicore-fivem/lib/client";
import { CORE, type AiPlayerData } from "@aicore-fivem/shared";

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

function start(data: AiPlayerData): void {
  console.log(`hello ${data.character?.firstname}, cash ${data.money.cash ?? 0}`);
}

// Also covers a resource restart while the player is already in the world.
const now = core.GetPlayerData();
if (now) start(now);
on(CORE.clientPlayerLoadedEvent, start);

ai-core:client:playerUnloaded

The local character was let go: the player went back to the character screen. Stop per-character work and clear what you kept for that character. (When the player leaves the server, their game closes; nothing fires.)

Side: Client · Constant: CORE.clientPlayerUnloadedEvent

Arguments

None.

Listener

resource/client/index.ts
import { CORE } from "@aicore-fivem/shared";

on(CORE.clientPlayerUnloadedEvent, () => {
  SendNUIMessage({ action: "reset" });
});

ai-core:client:dead

The local player went down (dead or last stand) or got up, in whichever death script runs. Fires only on a change.

Side: Client · Constant: CORE.clientDeadEvent · Lib: medical.onChange

Arguments

Prop

Type

Listener

resource/client/index.ts
import { medical } from "@aicore-fivem/lib/client";

// Same as on(CORE.clientDeadEvent, ...).
medical.onChange((dead) => {
  if (dead) SendNUIMessage({ action: "close" });
});

ai-core:client:cache

A cached value of the local player changed. One watcher in ai-core reads the ped, vehicle, seat and weapon for every resource and fires this only when a value changes, so no resource has to poll them. The lib's cache and onCache (aiLib.cache and aiLib.cache.onChange in Lua) are built on it; use those.

Side: Client · Constant: CORE.clientCacheEvent

Arguments

Prop

Type

Listener

resource/client/index.ts
import { onCache } from "@aicore-fivem/lib/client";

onCache("vehicle", (vehicle, old) => {
  if (vehicle !== false) console.log(`entered vehicle ${vehicle}`);
  else if (old !== false) console.log("left the vehicle");
});

ai-core:client:hudVisible

HUDs should show or hide: a full-screen UI opened or the last one closed. A HUD resource listens to it.

Side: Client · Constant: CORE.clientHudVisibleEvent · Lib: hud.onChange

Arguments

Prop

Type

Listener

resource/client/hud.ts
import { hud } from "@aicore-fivem/lib/client";

hud.onChange((visible) => SendNUIMessage({ action: "visible", data: visible }));

ai-core:client:worldSync

The weather and time sync was paused or runs again. A weather script listens to it. See Weather and time sync.

Side: Client · Constant: CORE.clientWorldSyncEvent

Arguments

Prop

Type

Listener

resource/client/weather.ts
import { CORE } from "@aicore-fivem/shared";

on(CORE.clientWorldSyncEvent, (paused: boolean) => {
  console.log(paused ? "weather sync paused" : "weather sync running");
});

ai-core:client:definitions

A job or gang was added, changed or deleted in the admin panel. Fires on every client, once per job or gang that changed. Pair it with the GetDefinitions export.

Side: Client · Constant: CORE.clientDefinitionsEvent

Arguments

Prop

Type

Listener

See the example of GetDefinitions.

ai-core:client:characterPortrait

A portrait picture for a character card on the character screen. A clothing script (ai-appearance) fires it; ai-core's character screen listens and shows the picture. Fire it yourself only if you write a clothing script.

Side: Client · Constant: CORE.clientCharacterPortraitEvent · Fired by: the clothing script, heard by ai-core

Arguments

Prop

Type

Listener

resource/client/portraits.ts
import { CORE } from "@aicore-fivem/shared";

// A clothing script hands a portrait to the character screen.
export function sendPortrait(charId: number, txd: string): void {
  emit(CORE.clientCharacterPortraitEvent, charId, `https://nui-img/${txd}/${txd}`);
}

ai-core:client:keyHints

The list of key hints HUDs should show changed. Carries the whole new list. Pair it with the GetKeyHints export.

Side: Client · Constant: KEY_HINTS.changedEvent

Arguments

Prop

Type

Listener

See the example of GetKeyHints.

ai-core:client:seatbelt

The local player's seat belt changed, in whichever seat belt script ai-core reads. Fires from the scripts that tell changes (ai-smallresources, qbx_seatbelt); with a HUD's own belt, read GetSeatbelt when you need it.

Side: Client · Constant: CORE.clientSeatbeltEvent · Lib: seatbelt.onChange

Arguments

Prop

Type

Listener

resource/client/hud.ts
import { seatbelt } from "@aicore-fivem/lib/client";

seatbelt.onChange((worn) => SendNUIMessage({ action: "belt", data: worn === true }));

ai-smallresources:seatbelt

ai-smallresources' own seat belt event. HUDs that only support ai-smallresources listen to it. New code should listen to ai-core:client:seatbelt above, which works with every supported seat belt script.

Side: Client · Constant: SEATBELT_EVENT

Arguments

Prop

Type

Listener

resource/client/hud.ts
import { SEATBELT_EVENT } from "@aicore-fivem/shared";

on(SEATBELT_EVENT, (worn: boolean | null) => console.log(`belt: ${worn}`));

Internal client events

The lib's Keybind talks to ai-core's client with two local events. Do not fire or answer them yourself; use Keybind (TS) or aiLib.Keybind (Lua).

EventConstantDirectionArguments
ai-core:client:keybindKEYBIND.announceEventlib to ai-core(info: KeybindInfo) a keybind waits for its default key.
ai-core:client:keybindKeyKEYBIND.keyEventai-core to lib(resource: string, name: string, key: string) the key to register: the panel's key, else the script's own.

On this page