Addon pages and SDK ​
np_admin is an addon host (npAddon.host({ api = 1, label = 'np_admin' })). An addon
(np_anticheat is the first) adds its own pages to the staff panel: sidebar entries under its own group heading,
rendered as an iframe from the addon's resource inside the panel's main area. The addon talks to the panel through a
small SDK (np-admin.js) and to its server through page RPCs that run through np_admin's RPC pipeline (staff
check, permission node, duty, rate limit, payload check, protected handler and normalized errors). Addons log their
domain-specific actions explicitly through the audit export.
addon resource np_admin
server registerPage ─────────────────▶ session.pages (filtered by perm) ─▶ sidebar group
registerPageRpc ◀────────────── admin.rpc('name') (staff, perm, duty, rate, payload)
sendPageMessage ──────────────▶ admin.on('event')
setPageBadge ──────────────▶ sidebar badge
client (optional) RegisterNUICallback ◀ admin.nui('name') straight from the iframe to the addon's client
web/dist/index.html ◀─── iframe ─────── panel shell ⇄ SDK (postMessage): context, rpc, notify, confirm, go, action
Manifest ​
np_addon 'np_admin'
dependency 'np_admin' -- when the addon is useless without the panel
files { 'web/dist/index.html', 'web/dist/**/*' }
All registrations happen inside npAddon.attach('np_admin', function(host) ... end, { api = 1 }). They are
owner-tracked: np_admin drops an addon's pages, RPCs and badges when the addon stops.
Server exports (api 1) ​
| Export | Returns | |
|---|---|---|
registerPage(id, def) |
true | false, code |
Sidebar entry + iframe page. Re-registering your own id replaces it |
unregisterPage(id) |
true | false, code |
Only the owner (or np_admin) |
registerPageRpc(name, fn(src, params), opts?) |
true | false, code |
Callable from the SDK as admin.rpc(name, params) by pages of your resource |
sendPageMessage(target, event, data) |
true |
target = player src | 'staff' (on duty) | 'allstaff'. Delivered to your resource's pages as admin.on(event) |
setPageBadge(id, count, hot?) |
true | false, code |
Sidebar counter of one of your pages (0 clears). Pushed to all staff |
kick(target, reason) |
true | false, err |
Same as the panel's kick: audit log names the invoking resource |
screenshot(target, { timeout? }) |
{ url?, image? } | nil, err |
Yields (default timeout 5000 ms). Needs screenshot-basic |
getStaffState(src) |
{ duty, noclip, godmode, invisible, spectating } |
spectating = target src or nil |
Server event (local, never net): np_admin:staffState (src, key, value) whenever duty, noclip, godmode, invisible
or spectating changes for a staff member.
Client export: openPage(id, params?) opens the panel on an addon page (params arrive in the page context / route
event).
registerPage(id, def) ​
id matches ^[a-z0-9_.-]{1,48}$ and is global (another resource's id → false, 'taken').
| Field | |
|---|---|
label |
1–32 chars |
icon |
Font Awesome 6 name ('shield-virus') or full classes ('fa-brands fa-discord') |
group |
Sidebar heading (1–24 chars). Defaults to the addon's resource name. Pages of one group are listed together, after np_admin's own groups |
order |
Sort order inside the group (default 100) |
ui |
Path inside your resource ('web/dist/index.html') → https://cfx-nui-<resource>/<path>, or an http(s):// URL (dev server). Pages of the same resource with the same ui share one iframe: the panel keeps it mounted and switches pages with a route event, so the page state survives navigation |
route |
1–64 chars handed to the iframe ('overview', 'cases'). Defaults to the page id |
perm |
Permission node or fn(src) -> bool needed to see the page (the server filters the list per staff member) |
hot |
Badge style (red) |
registerPageRpc(name, fn, opts) ​
name matches ^[a-z0-9_.-]{1,64}$, scoped to the invoking resource. opts:
{ perm = 'node' | fn(src, params) -> bool, duty = bool, rate = ms, latent = bool }.
The handler gets the staff member's src (never trust ids sent by the UI) and returns a JSON-able value, or
nil, 'code' / false, 'code' / nil, { code, message }. Errors reach the SDK as AdminError { code, message }.
SDK ​
Served by np_admin at https://cfx-nui-np_admin/web/dist/sdk/ (source web/public/sdk/):
| File | |
|---|---|
np-admin.js |
ES module, default export + window.NPAdmin |
np-admin.d.ts |
Types |
np-admin.css |
The panel's Nimbus tokens and components (nb-* classes) on a transparent page background, so pages look native |
import admin from './np-admin/np-admin.js'
const ctx = await admin.ready() // handshake; resolves the context below
ctx.page // { id, route, params }
ctx.resource // the addon resource name
ctx.me // { src, name, groups, duty }
ctx.theme // np_admin theme (brand / strength / material), also applied as CSS vars
ctx.inGame // false in a browser; ctx.standalone = true outside the panel
admin.can('anticheat.cases.claim') // UI only, the server checks again
await admin.rpc('cases.list', { open: true }) // registerPageRpc handler; throws AdminError
await admin.nui('waypoint', { x, y }) // POST https://<resource>/waypoint (your client Lua)
admin.on('route', ({ route, params }) => …) // another sidebar page of this iframe was opened
admin.on('detection', (d) => …) // sendPageMessage events
admin.on('theme', (t) => …); admin.on('visibility', ({ visible }) => …); admin.on('session', (me) => …)
admin.notify({ type: 'success' | 'error' | 'info', title, message })
await admin.confirm({ title, message, confirmText, destructive }) // boolean
await admin.prompt({ title, placeholder, multiline }) // string | null
admin.go('players', { player: 17 }) // a core view, or 'page:<id>' with params
await admin.action('players.spectate', 17, { on: true }) // run an np_admin action (same pipeline as the palette)
admin.close() // close the panel
// browser dev: admin.mock.rpc(name, fn), admin.mock.context(partial); ignored in game
Protocol: postMessage with { npadmin: 1, id?, kind, ... } both ways. The panel only answers frames it created and
only for their own resource. The iframe is transparent; it fills nb-adm__main and draws its own top bar (the SDK
CSS has .nb-adm__top and friends; the close button calls admin.close()).
Wire protocol ​
All server push messages use np_admin:push(topic, data), forwarded by the client to the NUI as
{ type: 'push', topic, data }. The SDK exposes page messages through admin.on(event, fn).
session.get includes pages: Page[]. Every page item has this exact shape:
Page = {
id: string, resource: string, label: string, icon: string, tint?: string,
group: string, order: number, url: string, route: string, hot: boolean, badge: number
}
url is the absolute https://cfx-nui-<resource>/<ui> URL for a resource path; an http:// or https:// ui
URL is returned unchanged. A page appears only for a staff member who passes its perm. The same filtered array is
re-pushed on topic pages to staff when a page is registered or unregistered, and to the affected player when
their permissions change. Losing staff access sends an empty array.
| Topic | Exact data | Recipients |
|---|---|---|
pages |
Page[] (same shape/filter as session.get.pages) |
Staff, or the player whose permissions changed |
pageBadge |
{ id: string, count: number, hot: boolean } |
All staff, on every badge change |
pageMessage |
{ resource: string, event: string, data: any } |
sendPageMessage target: one src, on-duty 'staff', or all staff 'allstaff' |
Badge values are also present on a page item as badge (count) and hot (red badge style). Setting count to 0
clears the counter. sendPageMessage is delivered to the SDK listeners for the sending resource's pages; addons
should use distinct event names within their resource.
Client export openPage(id, params?) opens { type: 'open', view: 'page:<id>', params }. The iframe receives those
params in its context / route event. A page can use admin.go('page:<id>', params) for the same navigation.