AI Core

Lib: client

@aicore-fivem/lib/client - every client helper with its signature, and the Lua aiLib twin where one exists.

TypeScript
import { Points, notify, progress, cache } from "@aicore-fivem/lib/client";

The client entry also re-exports the /fivem helpers (every, ByResource, Reasons, caller, onStop, plateOf, exports and locale helpers, state bag classes): see Lib: shared and fivem. The last column names the Lua twin on aiLib (Lib for Lua).

Talking to the server

HelperWhatLua
triggerServerCallback(name, args = [], timeoutMs?): Promise<unknown>Asks the server (onClientCallback there); parse the answer.triggerServerCallback
onServerCallback(name, handler: (...args) => unknown): voidAnswers the server's triggerClientCallback.onServerCallback
onServerEvent(name, handler) / onServerEvent(name, { args }, handler)A net event from the server; emits that did not come from the server are dropped. args parses the payload.onServerEvent
fromServer(): booleanWhether the event being handled came from the server.
callAction(name, args = [], { fallback, timeout?, silent? })Runs a server action, shows the translated refusal itself, resolves the ok reply or null.callAction
isActionOk(reply), replyError(reply, fallback)Read an ActionResult by hand.
TypeScript
const reply = await callAction("buy", [itemId], { fallback: "BUY_FAILED" });
if (reply) notify(t("BOUGHT"), "success");

The local player

HelperWhatLua
cacheped, playerId, serverId, vehicle, seat, weapon (false = none), kept by ai-core's one watcher.cache
onCache(key, handler: (value, old) => void): voidRuns when a cached value changes.cache.onChange
readPlayerState(ped), readWeapon(ped)A ped's vehicle, seat and weapon right now.
player.coords(), player.heading(), player.distanceTo(point), player.ped()Position reads (from the cache).player
player.freeze(state: boolean)Freezes the ped.player.freeze
player.teleport(to: { x, y, z? }, { heading?, ground?, fade?, keepVehicle? }): Promise<void>Teleport behind a fade with collision loading; no z lands on the ground.player.teleport
player.playAnim(dict, clip, options?): Promise<void>, player.stopAnim()Plays or stops an animation.player.playAnim, player.stopAnim
player.holdAnim(dict, clip, { ...options, while? })Keeps an animation playing until stop() or while() is false.
fadeOut(ms = 300), fadeIn(ms = 400)Screen fades; each resolves when done.fadeOut, fadeIn
getPlayerData(key), onPlayerData(key, handler): () => void, seedPlayerData(data)ai-core's player data (character, money, jobs, duty, job, gangs, activeGang, metadata).playerData.get, playerData.onChange
hasJob(jobs, minGrade = 0), inGang(gangs, minGrade = 0), onDutyIn(jobs)Membership checks (an empty list = everyone).
onMembershipChange(fn)Jobs, duty or gangs changed.
allows(rule: AccessRule): booleanWhether the player may use a place (the server's online.allows decides the same).
playerPed(serverId): numberA player's ped by server id, 0 out of scope.playerPed
nearestPlayer(metres, { from?, filter? }): number | nullThe closest other player's server id.nearestPlayer

Places and the world

HelperWhatLua
new Points()Every place a player uses: prompt or target (the owner's choice), NPC, blip.Points.new()
points.add(id, { coords, label, icon?, radius?, height?, canShow?, onPressed, onEnter?, onExit?, ped?, blip?, world?, promptOnly?, preferTarget? })Adds a point; label may be a function.points:add
points.addModel(id, { models, label, icon?, radius?, canShow?(entity), onPressed(entity), vehicles?, inVehicle? })A point on every object of some models (ATMs, chairs).points:addModel
points.addVehicle(id, { label, icon?, radius?, canShow?(vehicle), onPressed(vehicle) })A point on every networked vehicle.points:addVehicle
points.remove(id), clear(), refresh(id?), isInside(id)Manage points; refresh reads canShow again.
new Zones(): add(id, options), remove, clear, isInside, sizeAreas without an interaction.Zones.new()
new LocalPed({ model, coords, ... }): entity, removeA ped only this client sees, created near the player.LocalPed.new()
new Blips(): add(id, options), get, remove, clear; createBlip(options)Named blips.Blips.new(), Blips.create()
showPrompt(id, text, at?), hidePrompt(id), onPromptPressed(handler)ai-lib's prompt by hand (Points uses it).showPrompt, hidePrompt, onPromptPressed
new AdminWorld(files): get, onChange, view, recordsThe client copy of a script's sync: "all" panel files.
TypeScript
const points = new Points();
points.add("shop", {
  coords: { x: 25.7, y: -1347.3, z: 29.5 },
  label: t("OPEN_SHOP"),
  icon: "basket-shopping",
  blip: { sprite: 52, color: 2, scale: 0.8, label: t("SHOP") },
  onPressed: () => openShop(),
});

UI

HelperWhatLua
notify(text, kind = "info", duration?)A notification card.notify
progress({ label, duration, anim?, scenario?, face?, allowVehicle?, canCancel?, whileDead?, freeze?, disable? }): Promise<boolean>A timed action with ai-lib's bar; false when cancelled.progress
cancelProgress(), isProgressRunning()Stop or check this resource's bar.progress.cancel(), progress.isRunning()
menu(request, onHover? | { onHover, onToggle }): Promise<string | null>ai-lib's menu; resolves with the picked id.menu.show
input(request): Promise<Record<string, string | number> | null>ai-lib's input dialog.input
itemPicker({ title, target? }): Promise<PickedItem[] | null>Admin tools: ai-core's item grid.itemPicker
skillCheck(difficulty | difficulty[], keys = ["e"]): Promise<boolean>Skill check ("easy" | "medium" | "hard" or { areaSize, speedMultiplier }).skillCheck
lockpick({ difficulty?, pins?, picks? }): Promise<"opened" | "broken" | "cancelled">Lockpick minigame.lockpick
new NuiScreen(name, { cursor?, onClose?, closeCallback? }): open, close, send, on, isOpenA full-screen NUI: focus, hidden HUDs, close message, callbacks.
hud.hide(reason), hud.show(reason), hud.visible(), hud.onChange(fn)Hide HUDs around a full-screen UI.hud
keyHints.show(id, { label, keybind?, key?, icon? }), keyHints.hide(id)A key help line on the HUD.keyHints
radial.add(item), radial.remove(id), radial.refresh()Items on whichever radial menu runs.radial
controls.disable(reason, controls, group?), controls.enable(reason), controls.disableAll(reason, except?)Disabled controls, one per-frame job.controls
new Keybind({ name, description, defaultKey, defaultMapper, hint?, icon?, hintLabel?, onPressed, onReleased })A rebindable key; the panel can set its default. isPressed(), currentKey(), disable(state).Keybind.new()
TypeScript
const done = await progress({
  label: t("REPAIRING"),
  duration: 8000,
  anim: { dict: "mini@repair", clip: "fixing_a_player" },
  canCancel: true,
});

Through AI Core

HelperWhatLua
inventory.openInventory(), inventory.hasItem(item, count = 1), inventory.currentWeapon()The active inventory.inventory
medical.isDead(), medical.onChange(fn)The local player is down, in any death script.
gestures.isHandsUp(), isPointing(), provider()Hands up and pointing of any emote script.gestures
appearance.apply(ped, look), appearance.read(ped)Looks through the active clothing script.appearance
world.pauseSync(reason), world.resumeSync(reason)Pause the weather and time sync.world

Vehicles and entities

HelperWhatLua
nearestVehicle(metres, { networked?, notOwn?, filter? }): numberThe closest vehicle.nearestVehicle
drivenVehicle(): number | falseThe vehicle the player drives.
waitForEntity(netId, timeoutMs = 5000): Promise<number>The entity once it exists here, 0 after the timeout.waitForEntity
entityFromNetId(netId, type?): numberThe entity now or 0 (type 1 ped, 2 vehicle, 3 object).
getVehicleProps(vehicle), setVehicleProps(vehicle, props), setVehicleSetup(vehicle, setup)Read and apply a vehicle's look.
new PreviewVehicle(): show(model, at, setup?), clear()A local showroom vehicle.
vehicleLabel(model | hash | vehicle): stringDisplay name of a vehicle.vehicleLabel

Probes, streaming, timing

HelperWhatLua
raycast(from, to, { flags?, ignore?, options? }): RayHit | nullA line probe: { coords, normal, entity }.raycast
groundZ(x, y, z = 1000): number | nullGround height, null while collision is not loaded.groundZ
locationName(coords?): { street, crossing?, zone }Street and zone names.locationName
waypoint(): { x, y } | nullThe map waypoint.waypoint
pedHeadshot(ped, transparent = false, timeoutMs = 5000)A ped's headshot handle and texture name.pedHeadshot
onShot(handler: (weapon) => void): () => voidThe frame the local ped fires.onShot
requestModel, requestAnimDict, requestAnimSet, requestPtfxAsset, requestTextureDict, requestWeaponAsset (name, timeoutMs = 10000)Load a game asset.same names
attachProp(model, { ped?, bone, offset?, rotation?, collision?, rotationOrder? }): Promise<number>A local prop held at a ped bone.
new TickLoop(onFrame, name?): set(active), runningA per-frame job switched on only while needed.
new AreaFollower(event, cellSize = 64): start, stopReports the player's grid cell to a server AreaStream.
new ScriptCamera(type?): start, move, glideTo, attach, pointAt, setFov, shake, blur, stopA scripted camera, given back to the game camera on stop.

On this page