AI Core

Net events

The net events a client script may listen to (ai-core's player data channel), and ai-core's own network traffic that other scripts must not trigger.

A net event travels between the server and one player's client. ai-core sends very few of them: a player's own data goes out once when the character loads, then only the values that change, and only to that player. Everything else your script needs is a client event or a state bag.

You rarely need these events directly. The lib's onPlayerData(key, handler) (TypeScript) and aiLib.playerData.onChange(key, handler) (Lua) listen to both of them for you, merge the money and metadata patches, and read the starting values from ai-core.

ai-core:client:playerData

The server sends one value of the player's own data: the whole value of one key. Fires once per key when the character loads, then each time that value changes (a job, duty, a gang...).

Side: Server to the player's own client

Arguments

Listener

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

// The lib listens to ai-core:client:playerData and playerDataPatch for you.
onPlayerData("job", (job) => console.log(`main job: ${job.job} grade ${job.grade}`));

ai-core:client:playerDataPatch

The server sends only the changed entries of a map value: money (one account's new balance) or metadata (one key). Merge the patch into what you have.

Side: Server to the player's own client

Arguments

Prop

Type

Listener

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

// The lib merges patches: the handler gets the whole merged money map.
const show = (money: Record<string, number>): void => SendNUIMessage({ action: "cash", data: money.cash ?? 0 });
show(getPlayerData("money") ?? {});
onPlayerData("money", show);

On a client, listen to net events only through the lib's onServerEvent (TypeScript) or aiLib.onServerEvent (Lua). They check that the event really came from the server; a bare RegisterNetEvent handler also runs when another client resource fires the name locally.

ai-core's own traffic: do not trigger

These net events and callbacks are ai-core's internal traffic between its server and its client (or the lib). They are listed so you recognize them in logs. Never trigger them from another script, and do not build on them: their arguments may change.

NameDirectionWhat
ai-core:client:spawnserver to clientPuts the loaded character into the world.
ai-core:client:chooseSpawnserver to clientSpawn options for the player to pick.
ai-core:client:openCharactersserver to clientShows the character screen again after a switch.
ai-core:client:characterLooksserver to client (latent)The character screen's looks.
ai-core:client:billsserver to clientThe player's open ai-core bills, for the bill list.
ai-core:client:stressserver to clientStress for a HUD that only takes it from its own client.
ai-core:client:vehicleKeys, ai-core:client:garagesserver to clientCalls for key and garage scripts that only have a client API.
ai-core:clientError, ai-core:fuelReportclient to serverError reports of client bundles; fuel levels from client-side fuel scripts.
ai-core:characters, ai-core:createCharacter, ai-core:deleteCharacter, ai-core:selectCharacter, ai-core:spawnChoice, ai-core:payBill, ai-core:vehicleTypecallbacksThe character screen, spawn choice, bills and vehicle spawning.
ai-core:admin:*, <resource>:admin:worldbothThe admin panel and the panel data of every resource.
ai-lib:client:notify, ai-lib:progressFor, ai-lib:minigameFor, ai-lib:client:progressForCancelserver to clientai-lib's notifications, server-run progress bars and minigames (use the lib's notify, progressFor, minigameFor).

On this page