Script Config (React)
This page covers the React/NUI side of the script config system. For the Lua side (registration, watchers, DB persistence), see dirk_lib → scriptConfig.
New resource? You do not build an admin panel any more.
Script Studio draws one for you from your schema.json — sections, controls, row editors, validation, history and the save bar — and /<yourResource> opens it. The work that used to be steps 4 and 5 below is now schema work: see Schema Extensions, and Your own control / Your own page for the two escape hatches.
What is still current on this page:
createScriptConfig(step 3) — how your own game UI reads settings at runtime. Unchanged, and every dirk resource still uses it.ConfigPanel(steps 4–5) — kept for the per-script panels that already exist. Use it to maintain one, not to start one.
Overview
The script config system lets you build a full admin configuration panel for any FiveM resource with:
- Live settings that apply without server restart
- Undo / redo with full edit history
- Version conflict detection (optimistic concurrency)
- Change audit log with admin attribution
- JSON editor for bulk/advanced edits
- Reset to defaults with confirmation
The architecture flows like this:
Step-by-Step Setup
1. Define Your Schema
Create schema.json in your resource root. This is a JSON Schema that defines every setting, its type, and its default value.
Schema extensions:
| Extension | Purpose |
|---|---|
x-serverOnly | Never sent to client — server-only secrets |
x-renamedFrom | Auto-migrate old key path to new key path |
x-arrayKey | Merge arrays by identity field instead of index (put on every editable array) |
x-installItem / x-installItemList | Auto-generate the INSTALLATION/itemsToAdd/* files + missing-items audit from item fields |
x-itemPicker / x-itemTitle / x-vector4 | Admin-panel UI widgets: item-search field / array-card title field / world-position picker |
defaults.json is optional — if provided, it supplies the initial default values. Otherwise defaults are derived from the "default" fields in schema.json.
2. Register on the Lua Side
See dirk_lib → scriptConfig for full details. The minimal setup:
src/server/scriptConfig.lua
src/client/scriptConfig.lua
3. Create the TypeScript Config Store
In your resource's web/src/stores/, create a file that defines your settings types, Zod schema, and calls createScriptConfig:
4. Build the Admin Panel
Create web/src/components/Admin/main.tsx with your nav items and section routing:
5. Build Section Components
Each admin section uses useFormField and useFormActions from dirk-cfx-react to bind to the form state managed by ConfigPanel:
API Reference
createScriptConfig<T>(defaultValue)
Factory function that creates a Zustand store and NUI integration for your settings type. Call once at module level.
Returns:
| Property | Type | Description |
|---|---|---|
store | StoreApi<T> | Zustand store — use as a hook for reactive reads |
updateScriptConfig | (data: Partial<T>) => Promise<NuiResponse<T>> | Send partial update to server via NUI |
getScriptConfigHistory | (params?) => Promise<HistoryResponse> | Fetch paginated change history |
useScriptConfigHooks | () => void | Call inside your admin component to register NUI listeners |
ConfigPanel
The main admin UI shell. Renders a full-screen modal with sidebar navigation, undo/redo, save/discard, history, JSON editor, and reset.
| Prop | Type | Required | Description |
|---|---|---|---|
navItems | NavItem[] | yes | Sidebar navigation items { id, icon, label } |
title | string | yes | Panel title |
subtitle | string | no | Panel subtitle |
open | boolean | yes | Whether the panel is visible |
onClose | () => void | no | Close handler (defaults to fetchNui("CLOSE_ADMIN_SECTION")) |
children | (activeTab: string) => ReactNode | yes | Render function receiving the active tab ID |
defaultConfig | T | yes | Default settings object for reset |
schema | { safeParse } | no | Zod schema for JSON editor validation |
resetConfirmText | string | no | Text user must type to confirm reset |
width | string | no | Panel width (default: "70vh") |
height | string | no | Panel height (default: "85vh") |
Built-in sidebar features:
- Undo / Redo — Step through edit history
- Save — Calls
updateSettingswith all pending changes, shows unsaved count badge - History — Paginated audit log modal with search/filter
- Discard — Revert to last saved state
- Manual Edit (JSON) — Full JSON editor with schema validation
- Reset Defaults — Wipe to defaults with confirmation modal
useForm
Advanced form state hook with deep nesting, undo/redo, and Zod validation. Used internally by ConfigPanel but can be used standalone.
Key methods:
| Method | Description |
|---|---|
setValue(path, value) | Set a nested value (e.g. "basic.debug") |
getValue(path) | Get a nested value |
reset() | Reset to initial values |
reinitialize(newValues) | Reset with new initial values |
undo() | Undo last change |
redo() | Redo undone change |
validate() | Run validation, returns { success, errors } |
getInputProps(path) | Returns { value, onChange, error } for Mantine inputs |
isDirty() | Whether any values have changed |
getChangedFields() | Array of paths that have been modified |
Context Hooks
These hooks access the form state within FormProvider (set up by ConfigPanel):
| Hook | Returns | Description |
|---|---|---|
useFormField(path) | T[path] | Reactive value at a nested path |
useFormFields(...paths) | [T[p1], T[p2], ...] | Reactive values at multiple paths |
useFormActions() | { setValue, reset, ... } | All form mutation methods |
useFormError(path) | string | undefined | Validation error for a field |
useFormErrors() | Record<string, string> | All current validation errors |
NUI Callback Reference
The settings system communicates with dirk_lib through these NUI callbacks (handled automatically):
| Callback | Direction | Purpose |
|---|---|---|
NUI_READY | UI → Lua | Signals that the NUI is loaded and ready |
GET_SETTINGS | UI → Lua | Fetches server config (currency, colours, etc.) |
GET_LOCALES | UI → Lua | Fetches locale strings |
GET_ITEMS | UI → Lua | Fetches inventory item definitions |
OPEN_ADMIN_SECTION | Lua → UI | Opens the admin panel |
CLOSE_ADMIN_SECTION | UI → Lua | Closes the admin panel |
UPDATE_SCRIPT_CONFIG | UI → Lua | Sends settings update with expected version |
GET_FULL_SCRIPT_CONFIG | UI → Lua | Admin panel full fetch (includes x-serverOnly paths) |
GET_SERVER_ONLY_SCRIPT_CONFIG | UI → Lua | Fetches the server-only sliver for the editing admin |
GET_SCRIPT_CONFIG_HISTORY | UI → Lua | Fetches paginated change history |
RESET_SCRIPT_CONFIG | UI → Lua | Resets settings to schema defaults |
All NUI callbacks are registered automatically by dirk_lib's scriptConfig module. You don't need to set them up manually.
Version Conflict Handling
When two admins edit settings simultaneously:
- Admin A opens the panel → receives settings +
client_versionhash - Admin B saves a change → server's version hash updates
- Admin A tries to save → sends their
expectedVersion - Server detects mismatch → returns
success: falsewithlatestData - UI automatically merges the latest data back into the form
- Admin A can review and re-save
This prevents silent overwrites and ensures all changes are tracked.