AI Core

Lib: shared and fivem

@aifivem/lib/shared and /fivem: the helpers that work on both sides, what each entry is for, and every topic page.

Two parts of the lib work on the client and on the server alike:

EntryWhat it holdsWhere you can use it
@aifivem/lib/sharedPlain helpers that never call a FiveM native: refusals, input readers, number and text formatting, vector math, zone geometry, panel data readers, a NUI page's lang texts.Client, server, resource/common/, and NUI (React) code.
@aifivem/lib/fivemHelpers that call natives existing on both sides: exports between resources, the scheduler, resource stop handling, the lang file loader.Client, server and resource/common/. Not in NUI code.

The client and server entries re-export everything from /fivem, so in a client or server file you can import those helpers from @aifivem/lib/client or @aifivem/lib/server too. Use /fivem only in resource/common/ files that both sides bundle.

TypeScript
import { fail, readInt, groupDigits } from "@aifivem/lib/shared";
import { resourceExport, every, createLocale } from "@aifivem/lib/fivem";

Lua

Only a few of these helpers have a Lua twin on aiLib (load it with shared_script '@ai-lib/init.lua', see Lib for Lua): every, waitFor, formatText, locale, fail, numbers.round, numbers.groupDigits, numbers.headingTo and stripGameText. Each entry shows the Lua call when there is one, and says so when there is none. Lua has its own tools for the rest: vector math (#(a - b) for a distance), Entity(e).state for state bags, exports['name']:Fn() for exports.

Topics

Shared types (Vec3, Vec4, ActionResult, AccessRule, BlipStyle, ZoneShape, VehicleProps...) are explained field by field on Shared types.

On this page