Skip to content

Events, state bags & commands ​

Client events ​

client

Local events (AddEventHandler), fired on each client:

Event Arguments Fired when
np_prophandler:ready { enabled, epoch } np_prophandler's client started and its exports are up, before the first snapshot. Again after every restart. See Ready
np_prophandler:spawned id, entity, data A streamed prop was created on this client, or a networked prop streamed in. data is the prop's data table
np_prophandler:despawned id, entity A streamed prop is about to be deleted, or a networked prop streamed out. Raised before deletion, so the handle is still valid
np_prophandler:doorState id, locked The lock state of a door this client has in its door system changed
np_prophandler:placement handle, 'confirm' | 'cancel', pose, reason A placement was confirmed or cancelled, besides its onConfirm / onCancel. Fires for every resource's placements
lua
AddEventHandler('np_prophandler:spawned', function(id, entity, data)
  if id:find('^np_inventory:drop_') then
    drops[id] = entity
  end
end)

AddEventHandler('np_prophandler:despawned', function(id, entity)
  drops[id] = nil
end)
  • The events fire for every resource's props. Filter by your id prefix.
  • Client-only props from addLocalProp fire the same events with their plain id.
  • Do not delete the entity. Remove or disable the prop instead.
  • Your own interact events are fired with (id, entity, data, receipt, option) on the client, or (id, netId, data, receipt, option) on the server with server = true. option is the chosen option's name.

Server events ​

server

Event Arguments Fired when
np_prophandler:ready { enabled, epoch } np_prophandler started and accepts registrations (after its own config definitions). Fires on every start. See Ready
np_prophandler:doorMinigame id, playerSource, result, unlocking A door game ended (won or lost), e.g. to alert the police on a failed pick
np_prophandler:doorChanged id, locked, playerSource A door's lock state changed. playerSource is the player who toggled it through the interact prompt, 0 for setDoorLocked
lua
AddEventHandler('np_prophandler:doorChanged', function(id, locked, playerSource)
  if id == 'np_police:front' and playerSource ~= 0 then
    print(('%s %s the front door'):format(GetPlayerName(playerSource), locked and 'locked' or 'unlocked'))
  end
end)

Ready ​

Everything a resource registers lives in np_prophandler's memory, so a restart drops it. Register in a handler for np_prophandler:ready and once on your own start:

lua
local function registerAll()
  exports.np_prophandler:registerProps(MyProps)
end
AddEventHandler('np_prophandler:ready', registerAll)
if GetResourceState('np_prophandler') == 'started' then registerAll() end

The payload is { enabled, epoch }: enabled is Config.PropHandler.enabled, epoch the sync epoch of this run (the client has its own per-run epoch). The server event and the client event work the same way; on the client, use it for addLocalProp, setCanInteract and attachments. See Installation.

Net events ​

These are internal. Listed so you know what they are; don't trigger them yourself, except through the exports.

Event Direction Arguments Purpose
np_prophandler:doorToggleRequest client → server id Toggle request from the door prompt or requestDoorToggle. The server re-checks it
np_prophandler:setAttachment client → server owner, key, attachment | nil Synced attach / detach. Validated and rate-limited
np_prophandler:snapshotRequest client → server nonce Asks for a full snapshot. See Sync
np_prophandler:snapshot server → client payload Full snapshot: props, net ids, world entries and doors
np_prophandler:snapshotReceived client → server nonce Confirms a snapshot
np_prophandler:state server → all clients changes One state change with its revision
np_prophandler:bucket server → client bucket The player's routing bucket changed
np_prophandler:debug server → client counts Toggles the client debug print. Sent only after the permission check

Sync ​

  • A client asks for a snapshot when it starts. Every change after that is one state message with a consecutive revision. A client that sees a gap asks for a new snapshot.
  • Each request carries a nonce. Only the reply to the latest request is accepted, and never one older than the state already held.
  • The server answers one request per player per server.snapshotMinIntervalMs (30 s). The first is always answered. A client retries after that interval plus 5 s.
  • Snapshots with more than server.latentSnapshotThreshold (64) entries are sent as a latent event. No new snapshot goes to that player until the client confirms it or server.latentTimeoutMs (60 s) passes. State messages that arrive before the snapshot are held and applied on top of it.
  • Entries that did not change keep their entity across a snapshot.
  • Each start of np_prophandler has a new epoch, so clients drop state from a previous run.

State bags ​

Bag On Value Written by
np_prophandler:id Entity (networked props) The prop id The server, when it creates the entity. Clients use it to match the entity to the prop
np_prophandler:attached Player { [fullKey] = { attachment, … } } The server only. A value a client writes itself is replaced on the next tick. See Attached props

Full keys are s:<resource>:<key> for setPlayerAttachments and c:<resource>:<key> for client attach with synced = true.

lua
-- server: is this player carrying anything from np_gangs?
local bag = Player(source).state['np_prophandler:attached'] or {}
local carrying = bag['s:np_gangs:crate'] ~= nil

Commands ​

Command Who What it does
prophandler_debug Server console Prints the framework, registered props (networked, active), world entries, doors, attachments and the sync revision
/prophandler_debug Players allowed np_prophandler.debug Toggles a print of the client counts to F8 every debugPrintIntervalMs (5 s). Others get no answer

The permission is checked with np_admin's npAdmin.can(source, 'np_prophandler.debug'). The node is registered with np_admin as Prop handler debug, so staff grant it in np_admin's permissions panel. Without np_admin, the vendored lib allows the server console, identifiers listed in the np_admin_fallback convar, and on ESX the groups in np_admin_fallback_groups (default admin,superadmin). See np_admin → Without np_admin.