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.
import { readInt, fail, groupDigits } from "@aicore-fivem/lib/shared";
import { resourceExport, every } from "@aicore-fivem/lib/fivem";Exports between resources (/fivem)
| Helper | What |
|---|---|
registerExport(name, handler): void | Registers 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] | null | The same for a resource that may not run (null while stopped). |
callExport(resource, name, ...args): unknown | An export of a script without types here; parse the result. |
provideExport(resource, name, fn): void | Answers exports["<resource>"].<name> for a name this resource provides. |
isResourceStarted(resource): boolean | Whether a resource runs now. |
Resources, scheduling, state (/fivem)
| Helper | What |
|---|---|
every(ms, fn, { active?, name? }): Job | The resource's one scheduler: 0 = every frame. job.set(active), job.stop(), job.running. |
caller(): string | The resource calling this export (this one when local). |
onStop(fn): void | Runs when this resource stops. |
new ByResource({ onDrop? }): set(key, value, owner = caller()), get, delete, ownerOf, values, entries | Entries per calling resource, dropped when that resource stops. |
new Reasons(): set(reason, on, owner?), has, any(), onChange | A state that holds while any reason is set (HUD hidden, sync paused). |
plateOf(vehicle): string | A 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, stateString | Parsers for the state classes. |
const fuel = new EntityState("fuel", stateNumber);
const job = every(1000, () => {
if (cache.vehicle) updateGauge(fuel.get(cache.vehicle) ?? 100);
});Actions and input (/shared)
| Helper | What |
|---|---|
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)
| Helper | What |
|---|---|
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, snapshot | A 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)
| Helper | What |
|---|---|
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_FIELDS | A 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. |