AI Core

Lib: client

@aifivem/lib/client and the client side of aiLib: what they are, how to load them in TypeScript and Lua, and every topic page.

The client lib is the set of helpers every ai-* client script uses instead of writing natives by hand: talking to the server, the local player, interaction points, zones, peds and blips, the shared UI (notifications, progress bar, menus, minigames), keybinds, and the layers that reach whatever HUD, death, clothing or emote script the server runs through ai-core.

TypeScript

Import from @aifivem/lib/client in files under resource/client/. Helpers that work on any side (refusals, input readers, math, RecordObjects, ServerClock) come from @aifivem/lib/shared.

resource/client/index.ts
import { Points, notify, progress, cache } from "@aifivem/lib/client";
import { RecordObjects, ServerClock } from "@aifivem/lib/shared";

Every resource made from the ai-core template already depends on the package ("@aifivem/lib": "workspace:*" in package.json); the build bundles it into dist/client.js.

Lua

Lua resources get the same helpers on the global aiLib table from the ai-lib resource. Add two lines to your fxmanifest.lua:

fxmanifest.lua
dependency 'ai-lib'
shared_script '@ai-lib/init.lua'

Then call aiLib.<name> in any client file. Each module loads the first time you use it and runs inside your resource, so the points, keybinds and callbacks you create belong to your resource and go away when it stops. Classes are made with .new() and their methods are called with a colon: local points = aiLib.Points.new(), then points:add(...).

client.lua
local t = aiLib.locale()

RegisterCommand('hello', function()
    aiLib.notify(t('HELLO'), 'success')
end, false)

Lua functions marked Waits (triggerServerCallback, callAction, progress, menu.show, input, skillCheck, lockpick, itemPicker, fadeOut, fadeIn, player.teleport, waitForEntity, the request* loaders, pedHeadshot) pause the code until the answer comes. They only work inside a thread. Command handlers and net event handlers already run in one; anywhere else (a point's onPressed, a keybind, a menu callback), wrap the call in CreateThread(function() ... end).

Not every TypeScript helper has a Lua twin. Each entry says so when it has none. The ones missing in Lua: fromServer, isActionOk, replyError, onCache (Lua has cache.onChange), readPlayerState, readWeapon, player.holdAnim, attachProp, PreviewVehicle, NuiScreen, hud.onChange, controls.isDisabled, medical, fuel, drivenVehicle, entityFromNetId, the vehicle props helpers, ScriptCamera, TickLoop (use aiLib.every(0, fn)), AreaFollower, ServerClock, AdminWorld, RecordObjects, and the membership checks (hasJob, inGang, onDutyIn, allows, onMembershipChange).

Topics

Helpers shared with the server

The client entry also re-exports the /fivem helpers, so you can import them from @aifivem/lib/client too. They are documented once on Lib: shared and fivem:

registerExport, resourceExport, optionalExport, callExport, provideExport, isResourceStarted, createLocale, loadLocaleTexts, LOCALE_CONVAR, ByResource, caller, onStop, plateOf, Reasons, every (with the types EveryOptions and Job), stateBoolean, stateNumber, stateString (type StateParse).

The state bag classes EntityState, PlayerState, GlobalKey and GlobalGroup exported from the client entry are the read-only client versions: get(id) and onChange(handler), no set. The server versions are on State bags.

Exports your script never calls

ZoneEngine (the zone checker behind Zones), ModelScanner and readModelScanDef (the model scan behind Points.addModel) are exported for ai-lib, which runs them for every resource. Use Zones and Points instead.

On this page