Integrating a resource ​
How a resource hooks into np_admin: permissions, editable settings, the audit log and staff tools. np_admin stays optional. The resource vendors one file and keeps working on servers without np_admin, and no ACE is involved.
Converting an existing resource?
- Permissions: §2 has a prompt you can hand to your coding agent.
- Settings: Converting a config walks through turning a
config.luainto np_admin settings. The Config converter writes the settings file in your browser, without uploading anything.
1. Vendor the lib ​
- Copy
np_admin/lib/np_admin.luainto your resource, e.g.bridge/np_admin.lua. - Load it after your config:
shared_scripts {
'shared/config.lua',
'bridge/np_admin.lua', -- after every config file
'shared/np_admin_settings.lua', -- optional, see Settings
}
Don't use @np_admin/... includes or dependencies { 'np_admin' }. They would make np_admin mandatory.
The addon lib
np_admin ships a second lib, lib/np_addon.lua (global npAddon), vendored the same way to bridge/np_addon.lua. It
is for resources that extend another resource (an addon of np_phone, for example) or are extended themselves. It has
nothing to do with permissions; see Addons.
The lib defines the global npAdmin:
| Function | Side | |
|---|---|---|
npAdmin.can(src, node) / npAdmin.can(node) |
server / client | May this player do it? The client answers from np_admin's cache, for UI only |
npAdmin.limit(src, key) |
server | A group limit, e.g. ban.max_duration |
npAdmin.isStaff(src) / npAdmin.isStaff() |
server / client | |
npAdmin.getGroups(src) |
server | |
npAdmin.permissions(list) |
server | Register your nodes |
npAdmin.settings(def) |
shared | Register editable settings |
npAdmin.onChange(key | '*', fn) |
shared | fn(value, old, key) after a setting changed |
npAdmin.get(key) |
shared | Current value of a registered setting |
npAdmin.log(category, entry) |
server | Forward a log entry. Returns false when np_admin isn't running |
npAdmin.action(def) |
server | Register a staff action |
npAdmin.notifyStaff({ title, message, icon, tint }) |
server | Toast to every staff member on duty |
npAdmin.openPanel(view) / npAdmin.openMenu() |
client | |
npAdmin.running() |
shared | Is np_admin started? |
npAdmin.fallback |
server | Override the behaviour without np_admin |
2. Permissions ​
Route your permission check through the lib:
-- before
function S.isAdmin(src) return IsPlayerAceAllowed(src, 'np_x.admin') end
-- after
function S.isAdmin(src) return npAdmin.can(src, 'np_x.admin') end
Then register your nodes, so they show up with labels in the permission matrix:
if IsDuplicityVersion() then
npAdmin.permissions({
{ node = 'np_x.admin', label = 'X admin', category = 'X', description = 'Open the X staff panel' },
{ node = 'np_x.use', label = 'Use X', category = 'X' },
})
end
- Nodes are dotted strings. Staff can grant wildcards (
np_x.*), and an explicit deny always wins. - Start your nodes with your resource name.
Without np_admin ​
npAdmin.can then allows:
- the server console;
- identifiers listed in the convar
np_admin_fallback(set np_admin_fallback "license:abc,discord:123"); - on es_extended, the groups in
np_admin_fallback_groups(defaultadmin,superadmin).
Everyone else is refused. Override this per resource:
npAdmin.fallback = function(src, node)
return npAdmin.defaultFallback(src) or MyFramework.isAdmin(src)
end
On the client, npAdmin.can(node) returns false while np_admin isn't running. Use it to show or hide UI only; the
server decides.
Let your coding agent do it ​
Converting an existing resource means finding every permission check: ACE calls, framework group checks, hard-coded admin lists and restricted commands. A coding agent (Claude Code, Codex, Cursor …) can do that for you:
- Copy the lib into the resource as
bridge/np_admin.lua(step 1). - Open the resource folder in your agent and give it the prompt below.
- Review the diff and the node list it reports.
Integrate this FiveM resource's permission checks with np_admin.
Context
- np_admin's integration lib is already in this resource as bridge/np_admin.lua. Don't edit that file. It defines the global `npAdmin` and keeps working when np_admin isn't installed.
- np_admin has its own permission nodes. Don't use ACE anywhere: no IsPlayerAceAllowed, add_ace or add_principal.
- Use the global exactly as written: `npAdmin` (lowercase n).
Tasks
1. fxmanifest.lua: add 'bridge/np_admin.lua' to shared_scripts, after every config file. Don't add dependencies { 'np_admin' } or any '@np_admin/...' include; np_admin must stay optional.
2. Find every permission check in the resource:
- IsPlayerAceAllowed / IsAceAllowed
- ExecuteCommand('add_ace …') or ExecuteCommand('add_principal …')
- framework group or permission checks, e.g. xPlayer.getGroup() or QBCore.Functions.HasPermission
- hard-coded admin lists of licenses or identifiers
- commands registered as restricted: RegisterCommand(name, handler, true)
3. Server side: replace each check with npAdmin.can(src, '<node>'). Node names are lowercase and dotted, and start with the resource name: '<resource>.admin', '<resource>.<feature>'. Use one node per distinct power. If an existing ACE name already has that shape, reuse it.
4. Restricted commands: register them unrestricted (RegisterCommand(name, handler, false)). Make `if src ~= 0 and not npAdmin.can(src, '<node>') then return end` the first line of the handler.
5. Client side: use npAdmin.can('<node>') only to show or hide UI. Make sure the server checks the same node again before it acts.
6. Register every node once, on the server, with a label and a category (the resource's display name):
if IsDuplicityVersion() then
npAdmin.permissions({
{ node = '<resource>.admin', label = 'Admin', category = '<Resource name>', description = 'What it allows' },
})
end
Put this in a new shared/np_admin_permissions.lua, loaded after the lib, or in an existing server file.
7. Keep the behaviour on servers without np_admin. The lib already allows the server console, the identifiers in the convar np_admin_fallback and the ESX groups in np_admin_fallback_groups. If the resource had its own admin list or framework group check, keep it as the fallback:
npAdmin.fallback = function(src, node)
return npAdmin.defaultFallback(src) or <the old check>(src)
end
8. Remove the ACE setup this replaces: add_ace lines in the README or docs, and ExecuteCommand calls that grant ACE.
9. Change nothing else. Don't rename functions, events or config keys.
When you're done, report:
- every node, with a one-line description of what it guards;
- every file you changed;
- every check you weren't sure about, with its file and line.
3. Settings ​
Expose part of your Config in Resource settings:
-- shared/np_admin_settings.lua (shared_script, after the lib)
npAdmin.settings({
label = 'My resource', icon = 'box-open', tint = 'orange', target = Config,
categories = { 'General', 'Limits' },
fields = {
{ key = 'Enabled', category = 'General', type = 'toggle', label = 'Enabled', apply = 'live', scope = 'shared' },
{ key = 'Limits.perHour', category = 'Limits', type = 'number', label = 'Per hour', min = 0, max = 100, apply = 'live', scope = 'server' },
{ key = 'Mode', category = 'General', type = 'select', options = { 'easy', 'hard' }, apply = 'restart' },
{ key = 'Logs.webhook', category = 'General', type = 'secret', scope = 'server' },
},
})
npAdmin.onChange('Mode', function(value, old) print('mode is now', value) end)
keyis a dotted path intotarget(numeric parts index arrays).- Defaults are whatever
Configholds when you register, soconfig.luastays the source of truth. np_admin stores only the overrides and writes them intoConfig: on the server before your code reads it, on clients forscope = 'shared'keys throughGlobalState['npcfg:<resource>']. - Secrets stay on the server. Only staff with
np_admin.settings.secretssee them.
Already have a config.lua? Converting a config has the step-by-step version, and an agent
prompt for this part. The Config converter writes the settings file for you. Every field
type and limit is in the Settings reference.
Field options ​
| Option | |
|---|---|
type |
toggle number slider select multiselect text textarea color list keybind coords secret json |
label, help, category |
Display |
min, max, step, unit |
Numbers and sliders |
options |
Strings, numbers, booleans or { value, label } for select / multiselect |
item |
Element type of a list: 'string' or 'number' |
pattern, maxLength |
Text validation (pattern is a Lua pattern) |
scope |
'server' (default) or 'shared' (also sent to clients) |
apply |
See below |
permission |
Extra node needed to edit this field |
apply: tell staff the truth ​
| Value | Use it when |
|---|---|
live |
Your code reads Config each time it needs the value |
reload |
Clients pick it up on their next init |
restart |
The value is read once at start, e.g. local x = Config.y at file level |
Settings of stopped resources ​
Point np_admin at the schema file in fxmanifest.lua. np_admin then lists your settings even while the resource is
stopped:
np_admin_settings 'shared/np_admin_settings.lua'
4. Audit log ​
Forward your log entries and keep your own webhook as a fallback:
function X.log(action, src, fields)
npAdmin.log('np_x', { action = action, actor = src, message = fields.message, data = fields })
-- existing webhook code stays
end
entry takes action, message, actor and target (server id, identifier or { name, identifier }) and data.
The resource is filled in by np_admin.
5. Staff tools ​
Register actions. They appear under Resource tools in the quick menu, the panel and the palette:
npAdmin.action({
name = 'np_x.reset', label = 'Reset player progress', icon = 'rotate-left', perm = 'np_x.admin', target = 'player',
args = { { key = 'reason', type = 'text', label = 'Reason' } },
handler = function(src, target, args) X.reset(target) return true end,
})
- np_admin checks the permission, the duty state and the rate limit, runs the handler and writes the audit entry.
targetis'player'or'none'.argsuse the same field types as settings;confirm = trueasks first.- Return
false, 'message'to show an error.
6. Server theme ​
Staff set one theme for every np_* UI in np_admin (see Server theme). The lib hands it to your resource, live, on both sides:
npAdmin.theme() -- { brand = '#3D74FF' | nil, strength = 'tiles', material = 'frosted' }
npAdmin.onTheme(function(theme) ... end) -- runs once right away, then on every change
Your NUI gets it automatically ​
If your resource has a ui_page, the lib sends this at start and on every change:
SendNUIMessage({ action = 'theme', type = 'theme', data = theme })
- A page that loads
nimbus-theme.jsneeds nothing else. The script listens for{ action: 'theme' }and applies brand, strength and material. - A React or Vue page: handle the
thememessage next to your other messages. Then callNimbusTheme.apply(data), or set the ramp variables,data-nb-brand,data-nb-strengthanddata-nb-materialon the.nb-uiroot. - The page may still be loading when your resource starts. The lib sends again after 2 s and 10 s. To be exact,
call
npAdmin.sendTheme()from your NUI'sreadycallback.
Your own theme logic ​
If your resource has its own theme config or player preferences, turn the automatic message off and merge yourself:
npAdmin.themeNui = false -- in a client file loaded after the lib
npAdmin.onTheme(function(theme)
local brand = Config.Theme.brand or theme.brand -- an explicit resource brand wins
SendNUIMessage({ action = 'theme', data = { brand = brand, strength = theme.strength, material = theme.material } })
end)
Keep such config defaults at nil, so the server theme applies until someone sets them.
7. Restart safety ​
The lib re-registers permissions, settings and actions on its own whenever np_admin (re)starts, through the
np_admin:ready event. No ordering in server.cfg is required.
React to permission changes (for example to refresh a cached role) with the server event
np_admin:permissionsChanged (src).
8. Optional value tracing ​
The current vendored lib also provides server-only npAdmin.flow(recOrList), npAdmin.flowRef(prefix) and
npAdmin.assetHandler(unit, def). Report successful moves once, pair sale legs with one ref, and include a known
counterparty whenever possible. Do not duplicate np_inventory item reports or np_banking bank reports. The lib
returns false for flow reporting while np_admin is stopped and re-registers asset handlers after restart.
See Value tracing / Wertflüsse (Deutsch) for examples, current coverage and recovery limits. Generic vehicle/housing ownership handlers need their own implementation; registering an owner lookup alone does not enable revert or lock.