Skip to content

NUI contract ​

The contract between the NUI, client Lua and server Lua. The TypeScript package packages/contracts in the resource declares every payload shape; Lua mirrors them by convention (camelCase keys, same field names). This page summarises it. You only need it to change the NUI or build another front end; resources that use the exports never touch it.

The rule: the NUI drafts, the server decides. The NUI holds the editor state and renders previews; every transaction is a server RPC that validates against the session, the template, the catalog and the caller's permissions.

Transport ​

NUI → client: fetch('https://np_manufacturing/<name>', payload) ​

Every callback answers with an RpcResult:

ts
type RpcResult<T> = { ok: true; data: T } | { ok: false; reason: string; params?: Record<string, string | number> }

reason is a stable code; the NUI translates it (reason.<code>) with params. There are two kinds of callbacks:

  • Local callbacks are handled by client Lua (camera, peek, previews, photo mode, anchor gizmo).
  • RPC callbacks are registered generically from one whitelist and forwarded to the server.

Client → server: one RPC event ​

client: TriggerServerEvent('np_manufacturing:rpc', { id, name, payload })
server: TriggerClientEvent('np_manufacturing:rpc:reply', src, { id, ok, data, reason, params })

The client holds the NUI callback until the reply arrives (timeout 15 s → { ok = false, reason = 'timeout' }). Payloads are limited to 8 MB on both sides. On the server each RPC is declared once with its rate bucket, whether it needs a session (payload.sessionId must belong to the caller, else session_invalid) and an optional role (use, approve, admin, mechanic, emergency). Editing RPCs additionally check the workshop's allowedModes (workshop_mode_not_allowed). During a session the 5-second bayProbe carries the sessionId and extends the session while the vehicle is still in the bay.

Server → client pushes ​

TriggerClientEvent('np_manufacturing:push', src, { action, payload })

The client forwards pushes to the NUI unchanged with SendNUIMessage({ action, payload }), and additionally reacts to jobUpdated (the in-world job runtime) and notify (np_hud while the console is closed).

Local callbacks ​

Name Payload Purpose
ready {} NUI loaded; Lua answers with bootstrap
close {} Close the console
captureVehicle { networkId? } Re-capture the bay vehicle and request a session
setCameraPreset { preset: 'off' | 'side' | 'front' | 'rear' | 'top' | 'orbit' } Scripted camera
peek { active } Alt held: hide the console and release focus until Alt is released
previewAttachments { attachments } Spawn preview props on the bay car
clearAttachmentPreview {} Remove them
previewDraft { draft, textureDataUrl? } Draft on the real car (runtime texture when enabled, else runtime_texture_disabled; runtime_livery_not_permitted without the live livery permission)
photoMode { active, preset?: 'studio' | 'night' | 'sunset' } Photo mode
takePhoto {} Screenshot
startAnchorPlacement { slot, boneName, position, rotation } In-world anchor gizmo
stopAnchorPlacement { commit } End it
hudAction { action: 'dismiss_job' } Hide the job HUD
textureRendered { requestId, dataUrl? , ok?, reason? } Answer to renderTexture

RPCs ​

Name Request Response
bayProbe { vehicle, workshopId, sessionId? } BayStatus (with sessionId: keeps the session alive)
requestSession { vehicle, workshopId } SessionPayload
closeSession { sessionId } null
listCatalog { sessionId } { templates, attachments } (admins get every status)
setTemplateStatus / setAttachmentStatus { sessionId, templateId | definitionId, status } Updated lists (admin)
listInspections { sessionId } VehicleInspection[] (admin)
createTemplate { sessionId, template: TemplateDraftInput } VehicleTemplate (admin). The draft may carry textureTargets (≤ 4), liverySlots and projections. Another call for the same model creates the next version
listProjects / createProject / loadProject session, name, visibility, projectId Project[] / Project / { project, draft, versions, logos }
loadDraft { sessionId, draftId } { draft, version }
saveDraft { sessionId, projectId, name?, draft, thumbnail? } { version, versions, project, draft } (draft = the stored, sanitized draft)
saveLogo { sessionId, projectId, name, draft, thumbnail? } LogoAsset[]
uploadAsset / loadAsset { sessionId, projectId, mime, data } / { sessionId, assetId } { assetId } / { assetId, data }. loadAsset has its own asset rate bucket (60 / 10 s)
listAttachmentPresets / saveAttachmentPreset session, name, visibility, attachments VehicleAttachmentPreset[]
validateAttachments { sessionId, attachments } { attachments, weightKg }
quoteBuild { sessionId, draft, attachments } Bill
submitBuild { sessionId, projectId, name, draft, attachments, applicationMode, nativeLiveryIndex, thumbnail?, comment?, texture? } BuildDetail. texture = { dataUrl, width, height, targetId? } is required for, and only allowed with, runtime_texture and runtime_slot (where it is the static fallback)
cloneBuild { sessionId, buildId } BuildDetail
getBuild / listBuilds / listPendingBuilds buildId / filter: 'all' | 'approved' | 'pending' | 'mine' BuildDetail / BuildSummary[]
commentBuild / requestChanges / approveBuild / revokeBuild / restoreBuild { sessionId, buildId, body | comment | reason } BuildDetail
applyBuild { sessionId, buildId } { build, job } (job when production jobs are on)
revertBuild { sessionId, buildId } null
listFleet { sessionId } FleetVehicle[]
createRollout / listRollouts { sessionId, buildId, targets: { vehicleKey, unit? }[] } Rollout / Rollout[]
getBrandKit / saveBrandKit { sessionId, organizationId? } / { sessionId, kit } BrandKit | null / BrandKit
getJob { sessionId?, jobId? } ProductionJob | null
cancelJob { jobId } null
listBakes { sessionId } BakeTemplate[] (admin): templates with approved live builds, suggested indices, baked state
exportBake { sessionId, templateId, buildIds? } BakeExportResult (admin): directory, path, files, builds, skipped. At most 32 builds and 64 MB
setBakedLivery / clearBakedLivery { sessionId, templateId, buildId, system, index } / { sessionId, templateId, buildId } BakeTemplate (admin). Cars with the build get the new manifest at once

Live modes add their own reasons: runtime_slot_disabled, runtime_slot_not_supported, runtime_slot_invalid ({ field }) and runtime_livery_not_permitted ({ mode }), checked on submitBuild, cloneBuild, applyBuild and (the permission) createRollout. A full slot pool doesn't fail an RPC: the car's manifest carries slotReason = 'runtime_slot_pool_full' and it shows the base livery. Baking answers with bake_* reasons.

Lua → NUI messages ​

SendNUIMessage({ action, payload }):

Action Payload When
bootstrap { locale, resourceName, playerName, capabilities } After ready
open / close { workshopId, workshopLabel } / { reason } Console opened / closed
vehicleCaptured { ok, vehicle, reason? } Bay vehicle captured
sessionOpened / sessionClosed SessionPayload / { reason }
bayStatus BayStatus ~1/s before a session, every 5 s during one
camera, peek, photoMode { preset }, { active }, { active }
photoTaken { ok, url?, savedToPhone, phonePending?, reason? } phonePending: a phone save was requested; the server confirms with notify
anchorPlacement { active, slot?, position?, rotation?, committed? } Gizmo updates (10/s)
buildUpdated { build: BuildSummary } Server push
pendingCount { count } Approvers
jobUpdated { job } Server push
rolloutUpdated { rollout } Server push
notify { level, title, message?, icon?, app?, reason?, params? } Toast
renderTexture { requestId, draft, variables, size, projections? } Render a per-vehicle runtime texture; answer within 3 s
hud { visible, job?, prompt?, progress?, tag? } In-world HUD (console closed)

bootstrap.capabilities tells the NUI which features are on: runtimeTexture, runtimeSlot, productionJobs, billing, photoMode, phone, rollouts, brandKits, wear.

Types in brief ​

SessionPayload: everything the console needs after the bay is ready: sessionId, workshop, vehicleKey, the captured vehicle, inspection, the matching template and all templates, approved attachments, presets, projects, build history, pending builds, the appliedBuild (for the diff), permissions (canDesign, canApprove, canAdminister, canMechanic, canUseEmergencyEquipment, canUseRuntimeLivery), organization, brandKit, resolved variables, wear, pricing, the limits (maxLayers, maxAttachmentsPerBuild, maxWeightKg) and expiresAt.

BayStatus: workshopId, workshopLabel, vehicle, checks (each { id, ok, params?, reason? } in the order vehicle_found, in_bay, stationary, empty, identity, ownership, template, lock, permission), ready and lockExpiresIn.

LiveryDraft: { canvasSize, background, layers }. A LiveryLayer has id, kind (text / shape / image / logo / group), name, visible, locked, templateLocked?, view (left / right / top / front / rear / uv), mirrored, normalised x, y, w, h, scale, rotation, opacity, color, and kind-specific fields: text, fontSize, fontWeight, letterSpacing, font; shape (rect / ellipse / stripe / chevron); assetId. Text may contain {unit}, {plate}, {callsign}.

Layer fields are bounded by LAYER_LIMITS, shared by the NUI editors and the server sanitizer so a saved draft never changes shape: x / y -0.5 … 1.5 (layers may bleed over the canvas edge), w / h 0.001 … 2, scale 0.01 … 8, rotation ±360, opacity 0 … 1, fontSize 4 … 1024, letterSpacing -50 … 200; names up to 64 characters, text up to 120, font names up to 48.

BuildSummary / BuildDetail: id, name, version, project, status (draft, pending, changes_requested, approved, in_production, applied, revoked, reverted), template and model, applicationMode, counts, thumbnail, submitter, approval, vehicleCount, total. The detail adds the draft, attachments, nativeLiveryIndex, bill, comments and timeline.

Bill: lines ({ kind: 'wrap' | 'part' | 'labour' | 'materials', label, detail?, amount }), total, currency, payer ('organization:<id>' or 'player') and labourSeconds.

ProductionJob: jobId, build, vehicleKey, plate, workshopId, status (awaiting_materials, in_progress, completed, cancelled), steps ({ stepId, kind, label, attachmentId?, slot?, coords?, durationMs, status }), materials with fulfilled counts, mechanicName and, per recipient, youAreMechanic.

FleetVehicle, Rollout (with targets[]: vehicleKey, plate, unit, status, reason?, appliedAt?), BrandKit (organizationId, name, colors[], logoIds[], fonts[], brandOnly), VehicleTemplate and AttachmentDefinition follow the fields described in Fleet, Administration and Templates & catalog.