AI Core

Lib: shared and fivem

@aicore-fivem/lib/shared (no natives, usable anywhere) and /fivem (natives on both sides) - every helper with its signature.

/shared never calls a native: use it in NUI code, resource/common/ and both sides. /fivem calls natives that exist on both sides; the client and server entries re-export it.

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

Exports between resources (/fivem)

HelperWhat
registerExport(name, handler): voidRegisters an export, also under its first-letter case twin (GetItems and getItems).
resourceExport(resource): CitizenExports[K]Typed access to another resource's exports; one handle per file.
optionalExport(resource): CitizenExports[K] | nullThe same for a resource that may not run (null while stopped).
callExport(resource, name, ...args): unknownAn export of a script without types here; parse the result.
provideExport(resource, name, fn): voidAnswers exports["<resource>"].<name> for a name this resource provides.
isResourceStarted(resource): booleanWhether a resource runs now.

Resources, scheduling, state (/fivem)

HelperWhat
every(ms, fn, { active?, name? }): JobThe resource's one scheduler: 0 = every frame. job.set(active), job.stop(), job.running.
caller(): stringThe resource calling this export (this one when local).
onStop(fn): voidRuns when this resource stops.
new ByResource({ onDrop? }): set(key, value, owner = caller()), get, delete, ownerOf, values, entriesEntries per calling resource, dropped when that resource stops.
new Reasons(): set(reason, on, owner?), has, any(), onChangeA state that holds while any reason is set (HUD hidden, sync paused).
plateOf(vehicle): stringA vehicle's plate, trimmed upper case.
createLocale(), loadLocaleTexts(resource?)The resource's lang texts (t(key, ...args)), and the whole table for a NUI.
new EntityState(key, parse), new PlayerState(key, parse), new GlobalKey(key, parse), new GlobalGroup(prefix, parse)State bag readers: get, onChange; EntityState.getByNetId, GlobalGroup.ids().
stateNumber, stateBoolean, stateStringParsers for the state classes.
TypeScript
const fuel = new EntityState("fuel", stateNumber);
const job = every(1000, () => {
  if (cache.vehicle) updateGauge(fuel.get(cache.vehicle) ?? 100);
});

Actions and input (/shared)

HelperWhat
fail("LANG_KEY")A refusal { ok: false, error } for an ActionResult.
isActionOk(reply), replyError(reply, fallback)Read a reply by hand.
readInt(value, min, max), readFinite(value), readId(value), readText(value, max)Strict readers for client values; null refuses (NaN, Infinity, fractions).
readVec3(value), readVec4(value)Points from client or export input (objects or Lua vectors); null on a bad value.
oneArg(read)A one-value args parser for callbacks: { args: oneArg(readId) }.
asArgs(value)One parsed value as an args result.
num, int, bool, str, record, vec4 (value, fallback, ...)Panel content readers with a fallback.
isRecord(value)A plain object check.

Numbers, text, positions (/shared)

HelperWhat
round(value, decimals = 0), groupDigits(value, separator = ",")1,234,567.
formatWeight(grams)750 g, 1.5 kg.
normalizePlate(text)A plate as a key or for comparing.
stripGameText(text)HTML and ~r~ codes removed from another script's text.
formatText(template, args){0} placeholders.
new LangTexts(): set, translate, subscribe, snapshotA NUI page's lang texts.
logSafe(text, max), previewJson(value, max)Untrusted text and data made safe for the console.
createLogger(resource)info, warn, error with the resource name in front.
distance(a, b), flatDistance(a, b), headingTo(from, to), nearestOf(items, point, pos, max?)Vector math (Vec3).
randomInt(min, max), pickRandom(list), rollChance(percent)Random helpers.
sleep(ms), waitFor(check, timeoutMs = 10000, intervalMs = 0)Waiting.
new ServerClock(): sync(serverNow), now(), toLocal(serverTime)The server's clock on a client, for countdowns.
gridCell(x, y, size), cellKey(cx, cy)Grid cells for AreaStream.
zoneContains(shape, x, y, z), zoneBounds(shape), polyFromCorners(corners, height)Zone geometry.
vehicleTypeOfClass(vehicleClass)A vehicle class to the CreateVehicleServerSetter type.
toVehicleProps(value), toVehicleSetup(value)Vehicle look from untrusted input, or null.

Panel data (/shared)

HelperWhat
spec.int(min, max, optional?), spec.num(min, max, optional?)Data spec builders for schema.ts.
readAccess(record), ACCESS_FIELDS, accessFields(), isPublic(rule), decideAccess(...)Who may use a place: jobs, gangs, grades, on duty.
readBlipStyle(value, fallback), BLIP_STYLE_FIELDSA panel blip style.
PLACE_PED_SPEC, placePedFields(path?), readPlacePed(value)A place's NPC in the panel.
readRecords(raw, readOne)A records file parsed once.
new RecordObjects(source, file, readOne | records, build): rebuild(key), rebuildAll()Points, blips and peds of a records file; an edited record rebuilds only its own objects.
withoutSchemaKey(value)A data file without its $schema key.

On this page