Events and state
The events ai-core and the ai-* scripts fire, with payloads, the state bags they write and the ESX / QB events the bridge fires.
Event names are constants in @aicore-fivem/shared (CORE, KEY_HINTS, MENU_EVENTS, LIB_UI, VEHICLES_EVENTS, SEATBELT_EVENT), so TypeScript code never types the string.
import { CORE, type CharacterInfo } from "@aicore-fivem/shared";
on(CORE.playerLoadedEvent, (src: number, character: CharacterInfo) => {
console.log(`${character.firstname} joined as ${src}`);
});AddEventHandler('ai-core:playerLoaded', function(src, character)
print(('%s joined as %d'):format(character.firstname, src))
end)For a character's whole life (load, unload, already loaded before a restart) use the lib's onCharacter (aiLib.onCharacter in Lua) instead of these two events by hand.
Server local events
Fired with TriggerEvent on the server; other resources and the bridge mirror player state from them.
| Event | Constant | Payload |
|---|---|---|
ai-core:playerLoaded | CORE.playerLoadedEvent | (src, character: CharacterInfo) after a character is loaded and spawned. |
ai-core:playerUnloaded | CORE.playerUnloadedEvent | (src, charId, reason: "dropped" | "switch") before a character's state is dropped. |
ai-core:moneyChanged | CORE.moneyChangedEvent | (src, account: string, balance: number, delta: number, reason: string) |
ai-core:jobsChanged | CORE.jobsChangedEvent | (src, jobs: JobMembership[]) |
ai-core:dutyChanged | CORE.dutyChangedEvent | (src, job: string | null) |
ai-core:gangsChanged | CORE.gangsChangedEvent | (src, gangs: GangMembership[]) |
ai-core:activeGangChanged | CORE.activeGangChangedEvent | (src, gang: string | null) |
ai-core:metaChanged | CORE.metaChangedEvent | (src, key, value | null) a metadata value changed. |
ai-core:definitionsChanged | CORE.definitionsChangedEvent | (file: "jobs" | "gangs", name) a job or gang changed in the panel. |
ai-core:characterScreen | CORE.characterScreenEvent | (src, charIds: number[]) the character screen loads; a clothing script may answer with portraits. |
ai-core:inventoryChanged | CORE.inventoryChangedEvent | (resource: string | null) the inventory behind the inventory layer changed. |
ai-core:itemUsed | CORE.itemUsedEvent | (src, name: string, status: Record<string, number> | null) a player used an item; status = the needs it gives (hunger, thirst, stress). |
ai-core:playerDied | CORE.playerDiedEvent | (src, killer: number | null, weaponHash: number) a player with a loaded character died. |
ai-inventory:usedItem | (source, name, slot, metadata, status) after every use in ai-inventory. Other scripts listen to ai-core:itemUsed. | |
ai-vehicles:owners | VEHICLES_EVENTS.owners | (puts: [plate, ownerType, ownerId][], removes: plate[]) owners of vehicles in memory changed (one batch per tick). |
chatMessage | (source, author, text) before ai-chat delivers a message; CancelEvent() drops it. |
Client local events
| Event | Constant | Payload |
|---|---|---|
ai-core:client:playerLoaded | CORE.clientPlayerLoadedEvent | (data: AiPlayerData) the local character is loaded. |
ai-core:client:playerUnloaded | CORE.clientPlayerUnloadedEvent | () |
ai-core:client:dead | CORE.clientDeadEvent | (dead: boolean) the local player went down or got up, in any death script. |
ai-core:client:cache | CORE.clientCacheEvent | (key, value) a cached value changed: ped, vehicle, seat, weapon. |
ai-core:client:hudVisible | CORE.clientHudVisibleEvent | (visible: boolean) HUDs show or hide. |
ai-core:client:worldSync | CORE.clientWorldSyncEvent | (paused: boolean) the weather and time sync paused or runs again. |
ai-core:client:definitions | CORE.clientDefinitionsEvent | (file: "jobs" | "gangs", name, definition | null) |
ai-core:client:characterPortrait | CORE.clientCharacterPortraitEvent | (charId: number, url: string) a portrait for the character screen. |
ai-core:client:keyHints | KEY_HINTS.changedEvent | (hints: KeyHintView[]) the key hints HUDs show now. |
ai-smallresources:seatbelt | SEATBELT_EVENT | (worn: boolean | null) the seat belt changed. |
ai-lib UI answers
Only needed when you call ai-lib's exports yourself (the lib's menu, input, skillCheck and prompts listen for you).
| Event | Constant | Payload |
|---|---|---|
ai-lib:client:menuResult | MENU_EVENTS.menuResult | (resource, requestId, itemId | null) a pick or a close (menus, item picker, minigames). |
ai-lib:client:menuHover | MENU_EVENTS.menuHover | (resource, requestId, itemId) the item under the pointer. |
ai-lib:client:menuToggle | MENU_EVENTS.menuToggle | (resource, requestId, itemId, checked) a switch row flipped. |
ai-lib:client:inputResult | MENU_EVENTS.inputResult | (resource, requestId, values | null) the input dialog was confirmed or closed. |
ai-lib:client:promptPressed | LIB_UI.promptPressedEvent | (resource, id) the interaction key was pressed on that resource's prompt. |
ai-lib:client:cancelProgress | LIB_UI.cancelProgressEvent | () the cancel key was pressed during a progress bar. |
State bags
Read them with the lib's state classes (GlobalKey, PlayerState, EntityState, GlobalGroup), or GlobalState[...], Player(src).state[...], Entity(e).state[...] in Lua. Only the owning resource writes.
| Key | Where | Value |
|---|---|---|
ai:duty:<job> | GlobalState | How many players are on duty in a job (dutyCountKey(job)). |
ai:inventory | GlobalState | Resource name of the active inventory. |
ai:vehicleKeys | GlobalState | Resource name of the active key system. |
ai:appearance | GlobalState | Resource name of the active clothing script. |
ai:medical | GlobalState | Resource name of the active death script. |
ai:interaction | GlobalState | "prompt" or "target": how lib Points let players interact. |
ai:pvp | GlobalState | Whether players can hurt each other. |
ai:clock, ai:weather | GlobalState | ai-weathersync's clock and weather. |
door:<id> | GlobalState | ai-doorlock: whether a door is locked. |
dead | Player | true while downed (ai-death). |
cuffed | Player | true while handcuffed (ai-police). |
proximity | Player | Voice range { index, distance, mode } (ai-voice). |
radioChannel, callChannel, callSpeaker, muted, submix | Player | ai-voice's radio, call and mute state. |
ai:owned, ai:vid | Vehicle | An owned vehicle and its id in ai-vehicles. |
ai:props, ai:setup | Vehicle | The look ai-core applies on the owner client. |
fuel | Vehicle | 0-100, kept by the fuel script. |
siren:lx, siren:manu, siren:lightbar | Vehicle | ai-sirens' lights, manual tone and light bar. |
Framework events (bridge)
ai-core's bridge fires the ESX and QB events with the same arguments, so scripts written for those frameworks hear them.
| Side | QB / Qbox | ESX |
|---|---|---|
| Server | QBCore:Server:PlayerLoaded, QBCore:Server:OnPlayerUnload, QBCore:Server:OnMoneyChange, QBCore:Server:OnJobUpdate, QBCore:Server:OnGangUpdate | esx:playerLoaded, esx:playerDropped, esx:playerLogout, esx:setJob |
| Client | QBCore:Client:OnPlayerLoaded, QBCore:Client:OnPlayerUnload, QBCore:Player:SetPlayerData, QBCore:Client:OnJobUpdate, QBCore:Client:SetDuty, QBCore:Client:OnGangUpdate, QBCore:Client:OnMoneyChange | esx:playerLoaded, esx:onPlayerLogout, esx:setAccountMoney, esx:setJob |
Events from other scripts that AI Core answers:
| Event | Answered by |
|---|---|
QBCore:GetObject, esx:getSharedObject | The bridge: the core object. |
QBCore:Server:TriggerCallback, esx:triggerServerCallback | The bridge: framework callbacks. |
QBCore:Notify, esx:showNotification, esx:showAdvancedNotification, esx:showHelpNotification | The bridge: AI Core's notification or prompt. |
police:server:policeAlert | ai-core: client (text), server (text, camId, playerSource), sent to the active alert system. |
hospital:client:Revive | ai-death: revives the player. |
qb-weathersync:client:DisableSync / EnableSync, cd_easytime:PauseSync, vSync:toggle | ai-core: counted as pause reasons of the world sync. |