Exports, events & hooks ​
What other resources may rely on: cameras, birds and dashboards that feed or read a case. np_surveillance depends on none of them. Everything below is server-side unless marked client.
Rules that hold for all of it:
- Values that leave np_surveillance are plain copies. Changing them changes nothing inside.
- Exports answer
nil,falseor an empty list until np_surveillance has firednp_surveillance:server:ready. Wait for that event (or checkGetResourceState('np_surveillance') == 'started'and retry) before the first call. - np_surveillance fires the ready event again after every restart. A restart forgets sources, device types and hooks, so register them again then.
- Hooks, and
onIntelsubscriptions, are removed when the registering resource stops. - Call exports as
exports.np_surveillance:<name>(...).
Server exports ​
| Export | Returns | What |
|---|---|---|
getCase(id) |
{ id, title, status, threatLevel, lead, createdBy, createdAt, updatedAt, members, subjects } or nil |
One case with its members and linked subjects |
listCases(filter) |
{ case, … } |
Cases, newest update first. filter = { status?, member = identifier, limit? } |
addIntel(entry) |
intelId or nil, code |
Add one intel entry to the stream: validated, admissibility decided, fanned out. Codes: not_ready, unknown_case, invalid_params, payload_too_big, or the reason of a beforeIntel veto |
registerSource(name, def) |
bool |
Register an intel source. def = { label, icon, layer, kind } |
pingSource(name, id, coords, data) |
bool |
Report a live point for a source. data.caseId also files it as intel (kind = data.kind, or 'ping'; data.payload, data.severity, data.subjectId, data.target) |
registerDeviceType(def) |
bool |
Register a device type. def = { id, label, icon, item, category, pingSeconds, warrant } |
tagSubject(caseId, subjectRef, data) |
the subject or nil, code |
Create or update a subject and link it to a case. subjectRef is a reference string (character id), a subject id or { ref, name }; data = { name?, tier?, aliases? } |
canAccess(src, caseId, role) |
bool |
May this player see and act on the case at role? True for a member with that role (a lead satisfies investigator) and for staff |
isCovered(kind, target, at) |
bool |
Is a warrant covering kind and target in force at at (now by default)? Always true while warrants are off |
onIntel(fn) |
fn |
Subscribe: fn(intel) runs for every entry added |
registerHook(name, fn) |
id or nil |
Register a hook |
removeHook(id) |
bool |
Remove a hook |
np_jobs and pack-facing exports ​
np_surveillance consumes pack-owned features and remains an ordinary resource. Current defaults use police.mdt for
investigation access, police.cases for lead/member management, police.warrants.request for requests and
legal.warrant_sign for signing through the optional np_legal provider. Missing or unknown mappings use the existing
np_faction/framework checks; live feature denials are authoritative. Existing permission-node aliases and export/event
signatures remain compatible.
New APIs include openCase(def, opts), findCaseByRef(resource, id), closeCase, addCaseMember /
removeCaseMember, tapLine / untapLine, deployDevice, requestWarrant, decideWarrant, amendWarrant,
revokeWarrant, getWarrant, listWarrants, and requireWarrant. Mutating player actions accept an actor and repeat
the server's role, case membership and warrant checks. Trusted resource calls can omit actor where documented.
The optional np_legal provider owns decisions while retaining np_surveillance's local warrant records and proof
metadata. If its request export fails after registration, the local request remains pending and local approval is
blocked. Local approval is also blocked while provider registration is pending. If np_legal is absent, local judge
decisions remain available. No unified-warrant migration is made. Added server-local caseMember, warrantIssued, and warrantRevoked
events are additive. See the np_jobs resource integration guide and the full
integration contract.
An intel entry is { caseId, subjectId?, kind, source = { type, id }, payload?, coords?, target?, severity?, warrantId? },
described on Cases & intel. The copy you receive in onIntel and in the intel event is
{ id, caseId, subjectId, kind, source, payload, coords, severity, admissible, warrantId, createdAt }.
-- a camera resource: announce itself once at start and on every np_surveillance restart
local function register()
exports.np_surveillance:registerSource('np_cctv', { label = 'CCTV', icon = 'video', layer = 'cameras' })
exports.np_surveillance:registerDeviceType({ id = 'cctv_camera', label = 'CCTV Camera', category = 'camera' })
end
register()
AddEventHandler('np_surveillance:server:ready', register)
-- when a camera sees a flagged subject on an active case
exports.np_surveillance:pingSource('np_cctv', cameraId, coords, {
caseId = caseId, subjectId = subjectId, kind = 'sighting', severity = 3,
payload = { camera = cameraId, still = url },
})
-- react to the whole stream
exports.np_surveillance:onIntel(function(intel)
if intel.kind == 'sighting' and intel.severity >= 4 then --[[ ... ]] end
end)
-- only act for people who belong to the case
if exports.np_surveillance:canAccess(src, caseId, 'investigator') then --[[ ... ]] end
registerSource and registerDeviceType work before the ready event; everything that reads or writes cases waits for it.
Client exports ​
client
| Export | Returns | What |
|---|---|---|
IsConsoleOpen() |
bool |
The investigations console is open on this client |
GetRole() |
'investigator', 'lead', 'judge', 'staff' or nil |
The player's role, as the server last told this client |
IsBusy() |
bool |
A field action is running (planting a device, a minigame) |
A client resource that must win (a cutscene, a call) may trigger np_surveillance:client:cancel (a local client event,
optional argument: a reason) to stop a running field action.
Hooks ​
local id = exports.np_surveillance:registerHook(name, fn)
exports.np_surveillance:removeHook(id)
Hooks run synchronously, in registration order, each protected by pcall: a hook that errors is skipped. An unknown name
returns nil.
Veto hooks. fn(payload) returns false, reason to refuse. Any other return lets it through.
| Hook | Payload | Runs when |
|---|---|---|
beforeIntel |
{ intel } |
An intel entry is about to be stored |
beforeWarrant |
{ warrant } |
A warrant is about to be requested |
beforeDevice |
{ device } |
A device is about to be registered |
beforeCaseAccess |
{ source, caseId, role } |
Runs on case-access checks; return false, reason to veto the access |
Value hooks. fn(payload, value) returns a new value; each hook sees the last one.
| Hook | Payload, value | What |
|---|---|---|
intelSeverity |
{ intel }, severity 0..5 |
Adjust an entry's severity. Severity drives the alert stream |
-- nothing a camera says about the police station may reach a case
exports.np_surveillance:registerHook('beforeIntel', function(p)
if p.intel.source.type == 'np_cctv' and p.intel.payload.network == 'LSPD · Mission Row' then
return false, 'private'
end
end)
-- every sighting of a wanted plate is an emergency
exports.np_surveillance:registerHook('intelSeverity', function(p, severity)
if p.intel.kind == 'sighting' and p.intel.target == '46EEK572' then return 5 end
return severity
end)
Events ​
Server-local events (AddEventHandler, never over the network). Payloads are public copies.
| Event | Payload |
|---|---|
np_surveillance:server:ready |
none. np_surveillance finished starting (fired again after every restart) |
np_surveillance:server:intel |
{ intel }, for every entry added |
np_surveillance:server:caseOpened |
{ case } |
np_surveillance:server:caseClosed |
{ case, reason } |
np_surveillance:server:subject |
{ caseId, subject } |
np_surveillance:server:warrant |
{ warrant }, when a request is decided or a warrant is revoked |
np_surveillance:server:device |
{ device }, when one is registered or updated |
np_surveillance:server:alert |
{ alert }: { caseId, intelId, kind, severity, coords?, at } |
AddEventHandler('np_surveillance:server:alert', function(p)
if p.alert.severity >= 5 then
TriggerEvent('my_dispatch:silentAlarm', p.alert.coords, ('Case #%d'):format(p.alert.caseId))
end
end)
Permission nodes ​
The nodes np_surveillance registers with np_admin are listed on Access, commands & admin.