AI Core

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.

TypeScript
import { CORE, type CharacterInfo } from "@aicore-fivem/shared";

on(CORE.playerLoadedEvent, (src: number, character: CharacterInfo) => {
  console.log(`${character.firstname} joined as ${src}`);
});
Lua
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.

EventConstantPayload
ai-core:playerLoadedCORE.playerLoadedEvent(src, character: CharacterInfo) after a character is loaded and spawned.
ai-core:playerUnloadedCORE.playerUnloadedEvent(src, charId, reason: "dropped" | "switch") before a character's state is dropped.
ai-core:moneyChangedCORE.moneyChangedEvent(src, account: string, balance: number, delta: number, reason: string)
ai-core:jobsChangedCORE.jobsChangedEvent(src, jobs: JobMembership[])
ai-core:dutyChangedCORE.dutyChangedEvent(src, job: string | null)
ai-core:gangsChangedCORE.gangsChangedEvent(src, gangs: GangMembership[])
ai-core:activeGangChangedCORE.activeGangChangedEvent(src, gang: string | null)
ai-core:metaChangedCORE.metaChangedEvent(src, key, value | null) a metadata value changed.
ai-core:definitionsChangedCORE.definitionsChangedEvent(file: "jobs" | "gangs", name) a job or gang changed in the panel.
ai-core:characterScreenCORE.characterScreenEvent(src, charIds: number[]) the character screen loads; a clothing script may answer with portraits.
ai-core:inventoryChangedCORE.inventoryChangedEvent(resource: string | null) the inventory behind the inventory layer changed.
ai-core:itemUsedCORE.itemUsedEvent(src, name: string, status: Record<string, number> | null) a player used an item; status = the needs it gives (hunger, thirst, stress).
ai-core:playerDiedCORE.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:ownersVEHICLES_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

EventConstantPayload
ai-core:client:playerLoadedCORE.clientPlayerLoadedEvent(data: AiPlayerData) the local character is loaded.
ai-core:client:playerUnloadedCORE.clientPlayerUnloadedEvent()
ai-core:client:deadCORE.clientDeadEvent(dead: boolean) the local player went down or got up, in any death script.
ai-core:client:cacheCORE.clientCacheEvent(key, value) a cached value changed: ped, vehicle, seat, weapon.
ai-core:client:hudVisibleCORE.clientHudVisibleEvent(visible: boolean) HUDs show or hide.
ai-core:client:worldSyncCORE.clientWorldSyncEvent(paused: boolean) the weather and time sync paused or runs again.
ai-core:client:definitionsCORE.clientDefinitionsEvent(file: "jobs" | "gangs", name, definition | null)
ai-core:client:characterPortraitCORE.clientCharacterPortraitEvent(charId: number, url: string) a portrait for the character screen.
ai-core:client:keyHintsKEY_HINTS.changedEvent(hints: KeyHintView[]) the key hints HUDs show now.
ai-smallresources:seatbeltSEATBELT_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).

EventConstantPayload
ai-lib:client:menuResultMENU_EVENTS.menuResult(resource, requestId, itemId | null) a pick or a close (menus, item picker, minigames).
ai-lib:client:menuHoverMENU_EVENTS.menuHover(resource, requestId, itemId) the item under the pointer.
ai-lib:client:menuToggleMENU_EVENTS.menuToggle(resource, requestId, itemId, checked) a switch row flipped.
ai-lib:client:inputResultMENU_EVENTS.inputResult(resource, requestId, values | null) the input dialog was confirmed or closed.
ai-lib:client:promptPressedLIB_UI.promptPressedEvent(resource, id) the interaction key was pressed on that resource's prompt.
ai-lib:client:cancelProgressLIB_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.

KeyWhereValue
ai:duty:<job>GlobalStateHow many players are on duty in a job (dutyCountKey(job)).
ai:inventoryGlobalStateResource name of the active inventory.
ai:vehicleKeysGlobalStateResource name of the active key system.
ai:appearanceGlobalStateResource name of the active clothing script.
ai:medicalGlobalStateResource name of the active death script.
ai:interactionGlobalState"prompt" or "target": how lib Points let players interact.
ai:pvpGlobalStateWhether players can hurt each other.
ai:clock, ai:weatherGlobalStateai-weathersync's clock and weather.
door:<id>GlobalStateai-doorlock: whether a door is locked.
deadPlayertrue while downed (ai-death).
cuffedPlayertrue while handcuffed (ai-police).
proximityPlayerVoice range { index, distance, mode } (ai-voice).
radioChannel, callChannel, callSpeaker, muted, submixPlayerai-voice's radio, call and mute state.
ai:owned, ai:vidVehicleAn owned vehicle and its id in ai-vehicles.
ai:props, ai:setupVehicleThe look ai-core applies on the owner client.
fuelVehicle0-100, kept by the fuel script.
siren:lx, siren:manu, siren:lightbarVehicleai-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.

SideQB / QboxESX
ServerQBCore:Server:PlayerLoaded, QBCore:Server:OnPlayerUnload, QBCore:Server:OnMoneyChange, QBCore:Server:OnJobUpdate, QBCore:Server:OnGangUpdateesx:playerLoaded, esx:playerDropped, esx:playerLogout, esx:setJob
ClientQBCore:Client:OnPlayerLoaded, QBCore:Client:OnPlayerUnload, QBCore:Player:SetPlayerData, QBCore:Client:OnJobUpdate, QBCore:Client:SetDuty, QBCore:Client:OnGangUpdate, QBCore:Client:OnMoneyChangeesx:playerLoaded, esx:onPlayerLogout, esx:setAccountMoney, esx:setJob

Events from other scripts that AI Core answers:

EventAnswered by
QBCore:GetObject, esx:getSharedObjectThe bridge: the core object.
QBCore:Server:TriggerCallback, esx:triggerServerCallbackThe bridge: framework callbacks.
QBCore:Notify, esx:showNotification, esx:showAdvancedNotification, esx:showHelpNotificationThe bridge: AI Core's notification or prompt.
police:server:policeAlertai-core: client (text), server (text, camId, playerSource), sent to the active alert system.
hospital:client:Reviveai-death: revives the player.
qb-weathersync:client:DisableSync / EnableSync, cd_easytime:PauseSync, vSync:toggleai-core: counted as pause reasons of the world sync.

On this page