Events & hooks ​
Server events ​
server
Local server events (AddEventHandler). np_prison:jailed and np_prison:released are also sent to the inmate's
client under the same name (RegisterNetEvent on the client).
| Event | Payload | Fired when |
|---|---|---|
np_prison:server:ready |
none | np_prison finished starting; exports answer from now on |
np_prison:jailed |
{ source, identifier, name, facility, cell, security, months, by, reason } |
A player was booked |
np_prison:released |
{ source, identifier, name, facility, status, monthsServed, by, reason } |
An inmate left: status = 'released', 'paroled' or 'escaped'; source is nil for an offline release |
np_prison:sentenceChanged |
{ source, identifier, delta, monthsTotal, monthsServed, monthsLeft, by, reason } |
Time was added or taken off |
np_prison:behaviourChanged |
{ source, identifier, delta, value, previous, by, reason } |
The behaviour score changed |
np_prison:alertChanged |
{ facility, level, previous, by, reason } |
A facility's alert level changed |
np_prison:seized |
{ source, identifier, items = { { name, count, label, metadata } }, by } |
Contraband was taken at booking |
AddEventHandler('np_prison:jailed', function(e)
print(('%s booked into %s, cell %s, for %d months by %s'):format(e.name, e.facility, e.cell, e.months, e.by))
end)
AddEventHandler('np_prison:released', function(e)
if e.status == 'escaped' then -- put them on your own wanted list
end
end)
Dispatch ​
Fired for every siren, escape and breach call (name in Config.Escape.dispatch.event), next to cd_dispatch,
ps-dispatch, qs-dispatch, core_dispatch and the MDT when they run:
| Event | Payload |
|---|---|
np_prison:dispatch |
{ facility, label, kind = 'siren' | 'escape' | 'breach', code, title, message, coords = { x, y, z }, jobs, blip = { sprite, colour, scale, seconds }, name?, identifier? } |
Alternatives ​
| Event | Payload |
|---|---|
np_prison:ankleMonitor |
{ source, identifier, name, coords = { x, y, z }, kind = 'ankle_monitor' }: the wearer left the house-arrest zone. Name in Config.Alternatives.monitor.dispatchEvent ('' = off) |
Hooks ​
local id = exports.np_prison:registerHook(name, function(payload) ... end, opts?)
exports.np_prison:removeHook(id)
Hooks run synchronously in registration order, each with its own copy of the payload. Errors are logged and skipped; hooks of a stopped resource are removed.
| Hook | Payload | Answer |
|---|---|---|
beforeJail |
{ source, identifier, name, months, facility, security, by, reason } |
false, reason vetoes; { months?, facility?, security? } changes them. Changes chain: each hook gets the values the hooks before it set (a parole violation and an escape penalty add up) |
afterJail |
the np_prison:jailed payload |
ignored |
beforeRelease |
{ source, identifier, status, by, reason, monthsLeft } |
false, reason vetoes. A refused automatic release is tried again when the sentence changes |
afterRelease |
the np_prison:released payload |
ignored |
sentenceChanged |
the np_prison:sentenceChanged payload |
ignored |
behaviourChanged |
the np_prison:behaviourChanged payload |
ignored |
alertChanged |
the np_prison:alertChanged payload |
ignored |
fineCharged |
{ source, identifier, amount, charged, unpaid, by, reason, charges } |
ignored. A fine of an accepted charge sheet; charges = penal code ids |
The release desk holds an inmate whose time is up without vetoing beforeRelease, so your hooks only see the real
release.
-- a courthouse resource: no automatic release while a trial is pending
exports.np_prison:registerHook('beforeRelease', function(p)
if p.status == 'released' and Trials.pending(p.identifier) then return false, 'trial pending' end
end)
-- double the sentence for anyone booked during a city-wide state of emergency
exports.np_prison:registerHook('beforeJail', function(p)
if GlobalState.emergency then return { months = p.months * 2 } end
end)
Events np_prison listens to ​
Net events, permission checked (Config.Permissions), so menus and MDTs written for other jail scripts keep working:
| Event | Arguments | Permission |
|---|---|---|
np_prison:jailPlayer |
target, months, facility?, reason? |
jail |
np_prison:unjailPlayer |
target, reason? |
unjail |
pickle_prisons:jailPlayer |
target, months, prisonIndex | facility? |
jail (Config.Compat.pickle) |
pickle_prisons:unjailPlayer |
target |
unjail (Config.Compat.pickle) |
esx_jail:sendToJail |
target, months |
jail (Config.Compat.esxJail) |
Client events: np_prison:jailDialog (target?) and pickle_prisons:jailDialog (target?) open the sentencing screen
(target nil = the nearest player).
Other net events (np_prison:rpc, np_prison:rpcResult, np_prison:init, np_prison:sync, np_prison:nui,
np_prison:notify and the module events np_prison:<module>:*) are internal.