Lib: server
@aicore8/lib/server and the server side of aiLib: what they are, how to load them in TypeScript and Lua, and every topic page.
The server lib is the set of helpers every ai-* server script uses instead of writing the same code again: answering clients safely, commands, players, items, vehicles, money, logs and the admin panel. Most helpers that touch another system (inventory, keys, phone, prison...) go through ai-core, so your script keeps working when the server owner swaps the inventory or the phone script.
TypeScript
Import from @aicore8/lib/server in files under resource/server/. Helpers that work on any side (refusals, input readers, math) come from @aicore8/lib/shared.
import { onClientCallback, inventory, notify } from "@aicore8/lib/server";
import { fail, oneArg, readId } from "@aicore8/lib/shared";Every resource made from the ai-core template already depends on the package ("@aicore8/lib": "workspace:*" in package.json); the build bundles it into dist/server.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:
dependency 'ai-lib'
shared_script '@ai-lib/init.lua'Then call aiLib.<name> in any server file. Each module loads the first time you use it and runs inside your resource, so commands and callbacks you register belong to your resource and go away when it stops.
aiLib.addCommand('hello', { help = 'Says hello' }, function(source)
aiLib.notify(source, 'Hello!', 'success')
end)Lua functions marked Waits (progressFor, minigameFor, spawnVehicle, triggerClientCallback, billing.unpaid, appearance.get) pause the code until the answer comes. They only work inside a thread. Handlers of aiLib.onClientCallback and aiLib.onClientEvent already run in one; anywhere else, 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: PendingActions, PlayerMap, Cooldowns, KeyedCooldowns, SourceLock, KeyWatchers, the position helpers, AreaStream, the state bag classes, AdminPanel, DataFile and the database helpers (Lua resources use ai-mysql's oxmysql API for SQL).
Topics
Client input
onClientCallback, onClientEvent, guards, triggerClientCallback, progressFor, minigameFor, PendingActions.
Commands
addCommand: parsed arguments, permissions, chat suggestions.
Players and characters
online, onCharacter, notify, nearby players, positions, PlayerMap, cooldowns, locks, rate limits.
Characters, loaded or not
characters: find, read and change any character through ai-core - money, jobs, gangs, metadata, name, play time.
Items
inventory: give, take, count, stashes, shops, usable items.
Vehicles
spawnVehicle, vehicleType, vehicleKeys, fuel, garages, entities from net ids.
Money and banking
money: balances, add and remove, job and gang accounts, transfer, the ledger; banking and billing.
Jobs and services
jobs and gangs of a player, dispatch, prison, mdt, ems, medical, stress, needs, definitions, isPrimeTime.
World
Time and weather, routing buckets, doors, stored characters.
Phone and appearance
phone numbers, mails, texts; stored character looks.
State bags
EntityState, PlayerState, GlobalKey, GlobalGroup: writing replicated values.
Logs
aiLog, aiLogChannels: logs through ai-core to Discord, Fivemanage and more.
Area streaming
AreaStream: world objects sent only to the players near them.
Admin panel
AdminPanel and DataFile: your script's settings in ai-core's panel.
Database
createDatabaseTables, WriteQueue.
Helpers shared with the client
The server entry also re-exports the /fivem helpers, so you can import them from @aicore8/lib/server 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 server entry are the server versions: they add set. See State bags.
Two helpers only ai-core uses
sendPlayerData(source, key, value) and patchPlayerData(source, key, patch) push one value of a player's data (AiPlayerData) to that player's client. ai-core calls them; your script never needs them. Read player data on the client with getPlayerData (Lib: client).