NUI contract (Lua ⇄ web) ​
The message contract between the Lua client, the web UI and the server. The source of truth is
docs/ARCHITECTURE.md in the resource
(§3 data shapes, §5 NUI protocol, §6 events, §12 web); this page summarises it. You only need it to change the web UI.
Resources that use the exports never touch it.
The rule: the server decides. The client sends an id, a slot, a count, a plot slot. Growth, quality, prices, counts, durations, tool checks, outcomes and metadata are computed on the server from its own stores, and positions come from the server's own ped. The client never says which tools it has, except the standalone weapon report.
Lua → web: SendNUIMessage({ action, data }) ​
Through NpFarming.sendNui(action, data) (queued until the NUI called ui.ready); from the server
NpFarming.nui(src, action, data).
| action | data |
|---|---|
init |
{ locale, strings, crops, tools, items, quality: { stars, priceMult }, player: { identifier, name, job, grade, farmer, admin }, config: { keys, inventory, metadata, imagePath, hud, weaponReport, toolWeapons }, sync, modules } |
sync |
{ key, value }: one per-player state value changed (farmer, world, plots, contracts, coop, tractor, animals) |
open / close |
{ screen, data } / { screen? }: a focus screen |
theme |
The np_admin theme |
hud:notify, hud:progress, hud:progressCancel, hud:prompt, hud:promptHide |
Toasts, the progress bar and prompts (only without np_hud) |
hud:labels |
{ labels: WorldLabel[] }: the world labels over the plants on screen right now |
hud:card / hud:cardHide |
The PlantCard of the focused plant (no focus) / {} |
hud:hotbar / hud:hotbarHide |
{ slots: HotbarSlot[] } while on a plot / {} |
planting:ghost |
{ cells: GhostCell[], selected? }: the projected placement grid |
station:update / market:update |
StationView / MarketView while that screen is open |
Screens ​
| id | Kind | Opened by |
|---|---|---|
field-hud |
HUD piece | Always mounted: world labels, prompts, card, hotbar |
plant-card |
Focus | The inspect key (H) |
planting |
Focus, keeps game input | Using a seed: the seed pouch and the placement grid |
tools |
Focus | /farmtools, using a tool item, np_menu's radial item, the phone almanac |
station |
Focus | A processing station |
market |
Focus | A buyer |
contracts |
Focus | The contract board, the phone |
coop |
Focus | /farmcoop |
animal |
Focus | A pen |
hive |
Focus | A beehive |
openScreen takes NUI focus and claims the HUD zones; opening another screen closes the first. The client closes the
screen when the player dies, gets cuffed or unloads; ESC calls ui.close. The Harvest app is a separate page
(web/phone.html, an np_phone iframe) fed by the app RPCs overview, almanac, me and world.
Web → Lua: one callback ​
fetch('https://np_farming/rpc', { method: 'POST', body: JSON.stringify({ method, params }) })
// → { ok: true, data } | { ok: false, error: 'code' }
Client-local methods are answered by the client (ui.ready, ui.close, action.run, planting.select,
planting.cancel, card.action, waypoint); everything else goes to the server dispatcher.
Server check order: known method → token bucket (Config.RateLimit) → ready → a sane params table (depth ≤ 5, ≤ 256
keys) → loaded character → job / admin → alive → one call per player and method in flight → schema → cooldown →
handler. Errors are codes (unknown_method, rate_limited, invalid_params, forbidden, too_far, missing_tool,
level_too_low, no_money, vetoed, … plus each module's own); every code has a locale string.
Server RPC methods ​
| Module | Methods |
|---|---|
| core | action.start, action.finish, action.cancel, tools.list, tools.check, levels.me, world.now |
| plots | plots.list, plots.get, plots.rent, plots.release, plots.placement |
| crops | crops.seeds, crops.inspect, crops.area; timed crops.plant, crops.water, crops.fertilize, crops.clear, crops.refill |
| harvest | harvest.preview; timed harvest.do |
| processing | processing.stations, processing.open, processing.start, processing.queue, processing.cancel, processing.collect |
| market | market.buyers, market.prices, market.sell, market.history |
| contracts | contracts.list, contracts.accept, contracts.deliver, contracts.post, contracts.cancel |
| phone | phone.overview, phone.almanac |
| animals | animals.pens, animals.open, animals.collect, animals.buy, animals.walk, animals.walkEnd; timed animals.feed, animals.water, animals.dig |
| bees | bees.hives, bees.open, bees.place, bees.remove; timed bees.smoke, bees.harvest |
| threats | threats.status, threats.place, threats.call; timed threats.spray, threats.extinguish |
| coop | coop.get, coop.create, coop.invite, coop.answer, coop.leave, coop.kick, coop.role, coop.split |
| tractors | tractors.status, tractors.attach, tractors.start, tractors.stop; timed tractors.refuel |
Timed actions ​
Anything that takes time is a timed action: action.start { name, params } → { token, duration, label, icon?, anim?, prop?, canCancel, radius, speed? }, the client plays the bar, then action.finish { token } → { name, result }. The
server sets the duration, checks the elapsed time and the distance, and re-validates everything in the finish step (the
plant is still ripe, the tool is still there). Work actions run at speed: a tool in the hand shortens the bar
(ToolCheck.speedMult).
Shared shapes ​
ToolCheck = { ok: boolean; tool: string; label: string; source?: 'hand' | 'loadout' | 'item'; name?: string; toolLabel?: string;
durability?: number; speedMult?: number; options: { kind: 'item' | 'weapon'; name: string; label: string }[]; text?: string }
ToolsView = { held: HeldTool[]; types: ToolType[]; inHandBonus: number; itemWear: number; weaponWear: number }
PlantState = { id; plot; slot; crop; stage; stageIndex; stages; state: 'growing' | 'thirsty' | 'ripe' | 'rotting' | 'dead';
water; nutrients; health; progress; coords; mine: boolean; ripeAt?; rotAt?; minutesLeft? }
WorldView = { season; seasonDay; seasonDays; weather; raining; snowing; temperature; frost; hour; minute; night; source }
FarmerView = { level; xp; current; next; progress; max: boolean; perks: { level, id, label, unlocked }[]; stats }
Keys are camelCase, Stars = 1 | 2 | 3, Coords = { x, y, z }, icons are Font Awesome solid names without fa-, tints
are the Nimbus tints. The wire types of every screen are in web/src/screens/<id>/types.ts, the shared ones in
web/src/lib/types.ts; web/scripts/check-contract.mjs checks the web's RPC names, NUI actions, screens and error codes
against the architecture file and the Lua registrations.
Net events ​
Client → server: np_farming:rpc (reqId, method, params), np_farming:ready, np_farming:weapons (hashes[])
(standalone only). Server → client: np_farming:rpcResult, np_farming:init, np_farming:sync, np_farming:nui,
np_farming:notify, and the module events np_farming:<module>:<name> (plants, pens, hives, threats, the farm camera,
co-op invites, the phone waypoint, staff tool output). A np_farming:server:* name is never a net event.
Web development ​
React 18 + TypeScript + Vite, the Nimbus CSS unchanged in web/design/, Quicksand and Font Awesome bundled offline.
The stage is 1920×1080, scaled to the window.
cd web
npm run dev # browser mock: ?screen=<id> renders any screen with mock data; ?locale=de
npm test # strings, contract check, vitest
npm run build # FiveM guard, tsc, vite build → web/dist
scripts/screenshots.sh [filter] # every screen to web/screenshots/<id>.png (LOCALE=de for German)
Lua tests: tests/run.sh (Lua 5.4 / 5.5, with fakes of every framework, inventory and sibling).