Skip to content

Exports, events & hooks ​

What other resources may rely on: a shop script that logs the till on a camera, a dispatch that reacts to after-hours motion, a job that registers a police network, an MDT that saves a clip. np_cctv depends on none of them. Everything below is server-side unless marked client.

Rules that hold for all of it:

  • Exports never throw. A call that cannot be answered returns nil, false or an empty list, and answers that way until np_cctv has started.
  • Tables you get are plain copies. Changing them changes nothing in np_cctv. Exports never expose an owner's identifier; an event carries one only where its row says so.
  • Wait for np_cctv:server:ready (or check GetResourceState('np_cctv') == 'started' and retry) before the first call. np_cctv fires it again after every restart; hooks are removed when your resource stops and have to be registered again.

np_cctv has no hard dependency but oxmysql and np_prophandler. With np_surveillance running it files intel there: that is np_cctv calling np_surveillance, not an API of np_cctv (Integrations).

Hooks ​

server

lua
local id = exports.np_cctv:registerHook(name, fn)
exports.np_cctv:removeHook(id)

Hooks run synchronously, in registration order. A hook that errors is logged and skipped. Hooks of a stopped resource are removed. An unknown name returns nil.

Hook Payload Return
beforePlace { source, identifier, kind = 'camera' | 'recorder', type?, coords, networkId?, recorderId? } false, reason refuses the install
beforeView { source, identifier, networkId, cameraId? } false, reason refuses opening or switching to that site
beforeClip { source, identifier, cameraId, networkId, from, to, kind } false, reason refuses a clip or still
beforeExport { source, identifier, clipId, networkId } false, reason refuses the USB stick or the case hand-over
beforeBlind { source, identifier, cameraId, action = 'cover' | 'clean' | 'recorder:take' | 'recorder:smash' } false, reason refuses working on a lens or recorder
retentionHours { recorderId, networkId }, hours A number replaces how long a recorder keeps its rolling buffer
motionSubjects { cameraId, networkId }, list A list replaces the subjects the camera can see: { { id, kind = 'person' | 'vehicle', coords, source? } }

The first five are veto hooks: fn(payload) returns false, reason to refuse, anything else lets it through. The last two are value hooks: fn(payload, value) returns a new value, anything else keeps it. Value hooks run in order and each sees the last value.

lua
-- no new cameras inside the police station
exports.np_cctv:registerHook('beforePlace', function(p)
  if p.kind == 'camera' and #(vector3(p.coords.x, p.coords.y, p.coords.z) - stationCoords) < 40.0 then
    return false, 'not here'
  end
end)

-- a week of buffer for every recorder on the police network
exports.np_cctv:registerHook('retentionHours', function(p, hours)
  if p.networkId == policeNetworkId then return 168 end
end)

Server exports ​

server

Export Returns Notes
registerCameraType(def) true | false, code Adds a camera type at runtime: { id, model, fov, range, item?, label?, minFov?, maxFov?, maxRange?, pan?, tilt?, zoomMax?, offset?, icon?, price? }. Give it an item the inventory knows (Items). Code: invalid_params
getCamera(id) PublicCamera | nil Shapes
listCameras(filter?) PublicCamera[] filter = { networkId?, owner? (identifier or server id), type?, status?, recorderId?, near = { coords, radius }? }
getNetwork(id) Network | nil { id, key, label, kind, ownerName, hours, cameras, online, blind, recorders = { PublicRecorder } } (counts)
listNetworks(who?) Network[] With who (a server id): only the networks that player may watch
registerNetwork(def) id | false, code A network owned by jobs, idempotent by key: { key, label, kind?, jobs = { job = lowestGradeToWatch }, manage = lowestGradeToManage?, hours? = { open, close } }. Codes: invalid_params, forbidden (the key belongs to a player's site)
saveClip(cameraId, { from, to }, kind?) PublicClip | nil, code kind = 'manual' | 'motion' | 'event' (default 'manual'); unix seconds. Codes: unknown_camera, bad_window, too_long, no_footage, clip_limit, recorder_gone
isViewable(src, networkId) boolean The player is the owner, holds a key, has the job grade, or is staff
logEvent(target, kind, data?) PublicEvent | PublicEvent[] | nil, code target is a camera id, or { coords, radius, max? } for the cameras that record around a place. kind is 'register', 'footage', 'tamper', 'custom' ... data = { label?, detail?, subject?, duration?, clip? }; clip is a number of seconds before now and also saves a clip
openMonitor(src, networkId?, terminalId?) true | false, code Opens the monitor on that player's client. Their access is checked (no_access)
queryFootage(filter) sanitized event rows Actor-scoped footage query; window defaults to 24 hours and is capped at Config.Recording.queryMaxHours (168 hours by default), future end times clamp to now, and result count is capped at 500
pullFootage(actor, cameraId, window) PublicClip | nil, code Saves a clip after site-scoped desk/footage authorization
registerBusinessNetwork(src, factionId, def) PublicNetwork | nil, code Register an idempotent np_faction-owned business site
registerBusinessCamera(src, networkId, cameraDef) PublicCamera | nil, code Place a fixed camera on an owned network; actor must be nearby, with a placed same-network recorder in range and under capacity
registerTerminal(def) / unregisterTerminal(id) boolean | false, code / boolean Register or remove a monitor desk; only the registering resource can remove it, and registrations are cleaned up on resource stop
getViewers(networkId?) / closeMonitor(src) viewer list / boolean Read active desk viewers or close a player's monitor
attachCamera(src, kind, opts) / detachCamera(cameraId, actor?) camera id / boolean Manage a bodycam or dashcam; no current pack feature owns bodycam access, so attachment follows the legacy manage policy
registerHook(name, fn) id | nil Hooks; removed when your resource stops
removeHook(id) boolean

useItem is also exported: the callback np_inventory and ox_inventory call when one of np_cctv's items is used (server = { export = 'np_cctv.useItem' }). Other resources have no reason to call it.

lua
-- a shop script logs the till opening on the camera that watches it,
-- and keeps what the cameras saw of a hold-up
exports.np_cctv:logEvent({ coords = tillCoords, radius = 8.0, max = 1 }, 'register', { detail = '$240 sale' })
exports.np_cctv:logEvent({ coords = tillCoords, radius = 30.0 }, 'custom', { label = 'Hold-up', clip = 180 })

-- save the last three minutes of one camera
local now = os.time()
local clip, code = exports.np_cctv:saveClip(cameraId, { from = now - 180, to = now })

-- register a police network once np_cctv is up
AddEventHandler('np_cctv:server:ready', function()
  exports.np_cctv:registerNetwork({ key = 'mrpd', label = 'MRPD Mission Row', kind = 'pd',
    jobs = { police = 0 }, manage = 3 })
end)

Shapes ​

lua
-- PublicCamera
{ id, networkId, recorderId, label, type, serial, slot, coords, heading, pitch, fov, range,
  status = 'online' | 'offline' | 'blinded', mode }

-- PublicRecorder
{ id, networkId, label, serial, coords, heading, capacityHours, maxCameras, backup, status, since, usage }

-- PublicEvent
{ id, cameraId, networkId, kind, subject?, at, duration, label, detail? }

-- PublicClip
{ id, cameraId, networkId, kind, startedAt, duration, label, exported, hasImage, cameraLabel? }

Event kinds: motion, after_hours, offline, blinded, cleaned, restored, tamper, register, footage, custom. See Footage.

Client exports ​

client

Export Returns Notes
IsViewing() boolean The monitor or a camera's full view is open on this client
OpenMonitor(networkId?) boolean Asks the server to open the monitor. It only answers next to the site's own gear, or for staff

Client events ​

client

np_cctv sends these to its own clients (net events). They are not an API; they are listed so you do not clash with them.

Event Payload
np_cctv:client:openMonitor The monitor data
np_cctv:client:closeMonitor none
np_cctv:client:place Starts the placement preview

Server events ​

server

Server-local (AddEventHandler), never sent to clients. Payloads are public copies.

Event Payload
np_cctv:server:ready none; np_cctv (re)started and answers exports
np_cctv:server:event { camera = PublicCamera, event = { id, cameraId, networkId, kind, subject?, at, duration, label, detail? } }: a camera logged something. A merged sighting does not repeat it
np_cctv:server:clipSaved { camera = PublicCamera, clip = PublicClip }
np_cctv:server:cameraPlaced { camera = PublicCamera, identifier }
np_cctv:server:cameraRemoved { camera = PublicCamera, reason }
np_cctv:server:recorderDestroyed { recorder = PublicRecorder, how = 'smashed' | 'stolen' }
np_cctv:server:monitorOpened / np_cctv:server:monitorClosed { src, networkId, terminal? } / { src, networkId }
lua
AddEventHandler('np_cctv:server:event', function(p)
  if p.event.kind == 'after_hours' then
    TriggerEvent('my_dispatch:silentAlarm', p.camera.coords, p.camera.label)
  end
end)

AddEventHandler('np_cctv:server:recorderDestroyed', function(p)
  print(('recorder %d was %s'):format(p.recorder.id, p.how))
end)

np_jobs access ​

The optional bridge consumes security.desk for site-scoped monitor and clip access. PTZ remains under existing network permissions until np_security defines a PTZ feature capability. sites, canClip and canExport in its feature config constrain what the guard may access. Police footage access may use police.mdt only when the proper evidence/surveillance section and explicit CCTV site/network scope are configured. The current police pack has no bodycam feature. An unavailable host or unknown feature uses the existing network/terminal job rules; registered feature denials are enforced. See the np_jobs resource integration guide and the full integration contract.