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:
| Entry | What it holds | Where you can use it |
|---|---|---|
@aifivem/lib/shared | Plain 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/fivem | Helpers 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.
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
Exports between resources
registerExport, resourceExport, optionalExport, callExport, provideExport, isResourceStarted.
Scheduling and lifecycle
every, onStop, caller, ByResource, Reasons, sleep, waitFor.
State bags
EntityState, PlayerState, GlobalKey, GlobalGroup and their parsers: reading replicated values from memory.
Actions and client input
ActionResult, fail, isActionOk, replyError, readInt, readText, readId, readVec3, oneArg, asArgs.
Text and numbers
formatText, round, groupDigits, formatWeight, stripGameText, randomInt, pickRandom, rollChance, ServerClock.
Positions
distance, flatDistance, headingTo, nearestOf, gridCell, cellKey.
Vehicles
plateOf, normalizePlate, vehicleTypeOfClass, toVehicleProps, toVehicleSetup.
Panel data
num, int, bool, str, record, vec4, spec, readRecords, RecordObjects, withoutSchemaKey.
Access, blips and place NPCs
readAccess, ACCESS_FIELDS, decideAccess, readBlipStyle, readPlacePed and their panel fields.
Locale
createLocale, loadLocaleTexts, LangTexts: your resource's lang files in game and in the NUI.
Logging
createLogger, logSafe, previewJson.
Zone geometry
ZoneShape, zoneContains, zoneBounds, polyFromCorners, readZoneShape.
Shared types (Vec3, Vec4, ActionResult, AccessRule, BlipStyle, ZoneShape, VehicleProps...) are explained field by field on Shared types.