Skip to content

Converting a config ​

Most FiveM resources come with a config.lua that server owners edit by hand, followed by a restart. This page shows how to make that config editable in np_admin instead: staff change values in a form, the changes are logged, and most of them apply without a restart. Your config.lua stays as it is.

It works for any resource: ESX, QBCore, Qbox or standalone, your own or a third-party one you maintain.

Skip the typing

The Config converter reads your config.lua in the browser and writes the settings file from this guide for you. Nothing is uploaded. Use this page to understand and review what it generates.

The idea in one minute ​

config.lua  ──defaults──▶  np_admin_settings.lua  ──registers──▶  np_admin
   ▲                                                                │
   └──────────── overrides written back into Config ◀───────────────┘
  • config.lua keeps the defaults. Nothing in it changes, and the resource still runs without np_admin.
  • A settings file lists which keys staff may edit, how each one is edited, and when a change takes effect.
  • np_admin stores only the overrides and writes them back into your Config table, on the server and, for shared keys, on every client. Your code goes on reading Config.Something like it always did.

You need three things: the lib, a settings file, and two lines in fxmanifest.lua.

Step 1 · Vendor the lib ​

Copy np_admin.lua into your resource as bridge/np_admin.lua. It's the same file in every resource, so don't edit it. It defines npAdmin and does nothing at all on servers without np_admin.

Step 2 · List your settings ​

Take this typical config:

lua
-- config.lua
Config = {}
Config.Debug = false
Config.CooldownMinutes = 15
Config.SuccessChance = 65
Config.Payout = { min = 250, max = 900, account = 'money' }
Config.Police = { jobs = { 'police', 'sheriff' }, required = 2 }
Config.Webhook = GetConvar('myrob_webhook', '')
Config.StartLocation = vector4(-1082.31, -247.12, 37.76, 207.5)
Config.Notify = function(src, msg) TriggerClientEvent('esx:showNotification', src, msg) end

Create shared/np_admin_settings.lua with one field per value staff should edit. The key is the path below Config, written with dots:

lua
-- shared/np_admin_settings.lua
npAdmin.settings({
  label = 'Store robberies', icon = 'sack-dollar', tint = 'green', target = Config,
  categories = { 'General', 'Payout', 'Police' },
  fields = {
    { key = 'Debug',           category = 'General', type = 'toggle', label = 'Debug output', apply = 'live', scope = 'shared' },
    { key = 'CooldownMinutes', category = 'General', type = 'number', label = 'Cooldown', min = 0, max = 240, unit = 'min', apply = 'live', scope = 'server' },
    { key = 'SuccessChance',   category = 'General', type = 'slider', label = 'Success chance', min = 0, max = 100, step = 1, unit = '%', apply = 'live', scope = 'server' },
    { key = 'StartLocation',   category = 'General', type = 'coords', label = 'Start location', apply = 'restart', scope = 'shared' },
    { key = 'Webhook',         category = 'General', type = 'secret', label = 'Discord webhook', convar = 'myrob_webhook' },

    { key = 'Payout.min',     category = 'Payout', type = 'number', label = 'Minimum', min = 0, unit = '$', apply = 'live', scope = 'server' },
    { key = 'Payout.max',     category = 'Payout', type = 'number', label = 'Maximum', min = 0, unit = '$', apply = 'live', scope = 'server' },
    { key = 'Payout.account', category = 'Payout', type = 'select', label = 'Paid into', options = { 'money', 'bank', 'black_money' }, apply = 'live', scope = 'server' },

    { key = 'Police.jobs',     category = 'Police', type = 'list',   label = 'Police jobs', apply = 'live', scope = 'server' },
    { key = 'Police.required', category = 'Police', type = 'number', label = 'Cops required', min = 0, max = 20, apply = 'live', scope = 'server' },
  },
})

Config.Notify isn't listed: functions can't be settings, so they stay in config.lua.

Which field type for which value ​

In your config Field type Notes
true / false toggle
a number number, or slider with min / max Add unit ('s', 'min', '$', '%', 'm') and limits; np_admin enforces them
one of a few strings select with options Staff can only pick valid values. Options keep their type: 1 isn't '1'
several of a few strings multiselect with options Stored as an array
a short string text pattern (a Lua pattern) and maxLength validate on the server
a long or multi-line string textarea Up to 4096 characters
'#rrggbb' color
{ 'police', 'sheriff' } list Add item = 'number' for { 1, 2, 3 }
a key name ('E', 'F7') keybind
vector3 / vector4 coords See Vectors
webhook, token, password, API key secret Server only, masked in the panel. See Secrets
a nested table (shops, items, zones) json Staff replace the whole table at once

Every property is listed in the Settings reference.

Step 3 · Load it in the manifest ​

lua
-- fxmanifest.lua
shared_scripts {
  'config.lua',                    -- unchanged
  'bridge/np_admin.lua',           -- after every config file
  'shared/np_admin_settings.lua',  -- after the lib
}

np_admin_settings 'shared/np_admin_settings.lua'   -- lists the settings even while the resource is stopped

Restart the resource. It appears under Resource settings in np_admin, with one form per category, the defaults from config.lua, and a badge on every field telling staff when a change takes effect.

Step 4 · Make apply honest ​

The apply badge is a promise to staff, so it has to match how your code reads the value:

apply Your code… Example
live reads Config.X at the moment it needs it if math.random(100) <= Config.SuccessChance then inside the robbery handler
reload reads it on the client when the player loads in a client building its UI from Config on playerLoaded
restart copies it once when the file loads local cooldown = Config.CooldownMinutes * 60000 at the top of the file

The most common reason a value can't be live is a copy at file level. Moving the read into the function makes it live:

lua
-- before: read once, so a change needs a restart
local COOLDOWN = Config.CooldownMinutes * 60000
local function onCooldown(last) return GetGameTimer() - last < COOLDOWN end

-- after: read on every call, so changes apply live
local function onCooldown(last) return GetGameTimer() - last < Config.CooldownMinutes * 60000 end

When a value is used to build something once, e.g. blips, zones, targets or a loop interval, keep the setup code and rebuild it when the value changes:

lua
npAdmin.onChange('StartLocation', function(value, old)
  RemoveBlip(blip)
  blip = createBlip(value)
end)

npAdmin.onChange('*', fn) fires for every key and passes fn(value, old, key). When you're unsure, restart is always true.

Let the converter check it

Give the Config converter your client and server scripts as well. It finds every read of Config.X and marks values read at file level as restart and values read only inside functions as live. It also marks values read by a client script as shared.

Step 5 · Pick the scope ​

scope Use it when
shared A client script reads the value. np_admin replicates the override to every client through GlobalState['npcfg:<resource>'], and the lib writes it into the client's Config
server Only server scripts read it. The value never leaves the server

secret fields are always server.

Special cases ​

Vectors and coords ​

A coords field edits a position as x, y, z (and w, the heading, when the default has one). np_admin stores the value as a plain { x = …, y = …, z = …, w = … } table. Once staff override it, Config.StartLocation is a table, not a vector, and vector maths like #(pos - Config.StartLocation) breaks. Convert it where you use it:

lua
local c = Config.StartLocation
local start = vec3(c.x, c.y, c.z)

Tables full of vectors (shop lists with coords = vector3(…)) have the same issue when edited as json. Either convert them where you read them, or leave them in config.lua.

Secrets and convars ​

Webhooks, tokens and passwords belong in secret fields:

  • they never reach a client;
  • they are masked for staff without np_admin.settings.secrets;
  • every change is logged, without the value.

If the value comes from a convar today, keep the convar as the fallback:

lua
{ key = 'Webhook', type = 'secret', label = 'Discord webhook', convar = 'myrob_webhook' }

WARNING

A secret written into a shared_script config file is still readable by every client that downloads the resource. Move secrets to a server-only file or a convar. np_admin can't hide what you ship to clients.

A server-only config ​

If Config only exists on the server (server_scripts { 'config.lua' }), load the settings file there too. target = Config has to exist wherever the file runs:

lua
shared_scripts { 'bridge/np_admin.lua' }
server_scripts { 'config.lua', 'server/np_admin_settings.lua' }
np_admin_settings 'server/np_admin_settings.lua'

Several config files or a glob ​

For shared/config/*.lua, or config files without "config" in their name, tell np_admin which files hold the defaults, in load order:

lua
np_admin_config 'shared/config/00_core.lua'
np_admin_config 'shared/config/shops.lua'

Big tables: shops, items, zones ​

You have two options for a list of records:

  • expose it whole as one json field;
  • expose the handful of numbers staff actually tune, e.g. Shops.1.price. A path segment made of digits addresses an array slot.

json values are limited to 16 KB.

Locales ​

Config.Locale = 'en' works best as a select with the languages you ship, e.g. options = { 'en', 'de' }. It's usually reload, because clients load their strings once.

Your Config is called something else ​

Pass that table: target = Cfg or target = MyRes.Config. A config written as return { … } in a module needs to be assigned to a global table first, so the settings file and np_admin can reach it.

Let your coding agent do it ​

The settings file is mechanical, but apply and scope need someone to read the code. A coding agent can do both:

  1. Copy the lib into the resource as bridge/np_admin.lua.
  2. Optional: run your config through the Config converter and save the result as shared/np_admin_settings.lua. The agent then reviews that file instead of starting from scratch.
  3. Give your agent this prompt in the resource folder, then review the diff.
text
Make this FiveM resource's config editable in np_admin (Resource settings), without changing how the resource behaves.

Context
- np_admin's integration lib is in this resource as bridge/np_admin.lua. Don't edit it. It defines the global `npAdmin` (lowercase n) and does nothing when np_admin isn't installed.
- np_admin reads the defaults from the Config table, stores only the overrides, and writes them back into Config. Your code keeps reading Config.X as before.
- If shared/np_admin_settings.lua already exists, it was generated by a tool. Review and correct it rather than rewriting it from scratch.

Tasks
1. Read every config file and every client and server script.
2. Create or complete shared/np_admin_settings.lua with a single call:
     npAdmin.settings({
       label = '<Resource name>', icon = '<font awesome name>', tint = 'blue', target = Config,
       categories = { … },
       fields = { { key = 'Path.below.Config', category = …, type = …, label = …, apply = …, scope = … }, … },
     })
   - key: the dotted path below Config. Digit segments index arrays ('Shops.1.price').
   - Only values a server owner would tune. Skip functions, model hashes, internal tables and anything computed at runtime.
   - type:
     - booleans → toggle
     - numbers → number with sensible min/max and a unit; percentages → slider 0-100 with unit '%'
     - a closed set of strings → select with options
     - free text → text; long text → textarea; '#rrggbb' → color
     - arrays of strings or numbers → list (item = 'number' for numbers)
     - key names → keybind
     - vector3/vector4 → coords
     - webhooks, tokens, passwords, API keys → secret (add convar = '<name>' if the value came from GetConvar)
     - big nested tables → json, or a few dotted keys for the values people actually tune
   - apply, decided by how the code reads each value:
     - read where it's used, inside a function → 'live'
     - read by a client once, when the player loads → 'reload'
     - copied once at file level (local x = Config.y), or used to build blips/zones/threads once → 'restart'
     When unsure, use 'restart'.
   - scope: 'shared' if any client script reads the value, otherwise 'server'. Secrets are always 'server'.
3. fxmanifest.lua:
   - shared_scripts order: the config files, then 'bridge/np_admin.lua', then 'shared/np_admin_settings.lua'.
   - Add the line: np_admin_settings 'shared/np_admin_settings.lua'
   - If the config is loaded by a glob, or from files without "config" in their name, add one np_admin_config '<path>' line per config file, in load order.
   - If Config only exists on the server, load the settings file as a server_script instead.
   - Don't add dependencies { 'np_admin' } or any '@np_admin/...' include.
4. Code changes, only where needed for correctness:
   - Overridden coords arrive as plain { x, y, z, w } tables, not vectors. Where the code does vector maths on such a value, convert it first: local c = Config.X; local v = vec3(c.x, c.y, c.z).
   - Where something is built once from a setting (blips, zones, targets), you may rebuild it in npAdmin.onChange('<key>', function(value, old) … end) and mark the field 'live'. If you don't, mark it 'restart'.
   - Don't move other reads around and don't rename config keys.
5. Secrets written into a shared_script config file are still downloaded by every client. Don't move them yourself; flag them in your report.

When you're done, report:
- the fields per category, with type, apply and scope;
- the values you deliberately left out, and why;
- every file you changed;
- the secrets that clients can still read.

Checklist ​

  • [ ] bridge/np_admin.lua is an unchanged copy of the lib and loads after every config file.
  • [ ] The settings file loads after the lib, wherever Config exists.
  • [ ] np_admin_settings '<path>' is in fxmanifest.lua, plus np_admin_config lines if your config uses a glob.
  • [ ] Every apply is true. A value cached at file level is restart, unless you rebuild it in onChange.
  • [ ] Values read by a client script are scope = 'shared'.
  • [ ] Secrets are secret fields and aren't shipped in shared files.
  • [ ] Code that does vector maths on a coords field converts the table first.
  • [ ] The resource still works with np_admin stopped. npAdmin.settings is a no-op then, and Config keeps the values from config.lua.