Events & hooks ​
Hooks ​
server
local id = exports.np_environmental:registerHook(name, fn)
exports.np_environmental:removeHook(id)
Hooks run synchronously in registration order. Returning false (optionally false, reason) or a string (the reason)
vetoes. A hook that errors is skipped and logged. The hooks of a resource are removed when it stops.
| Name | Payload | Return |
|---|---|---|
beforeSpawn |
{ template (id), coords, heading, spawn (id), source = 'director' | 'staff' | 'export' | 'chain', by? } |
Veto: the scene is not spawned (a director roll counts as a miss, reason vetoed) |
beforeTask |
{ source, identifier, scene (id), task (id), faction } when a player starts a task step |
Veto: the step answers vetoed:<reason> |
beforeClear |
{ scene, reason, by? } |
Veto: the scene stays live |
payout |
{ scene, reason, payouts = { { identifier, faction, amount, account } }, tip = { identifier, amount } | nil } |
Change amounts in place; a veto pays nothing |
-- no scenes during a server event
exports.np_environmental:registerHook('beforeSpawn', function(ctx)
if GlobalState.eventMode then return false, 'event running' end
end)
-- double pay on weekends
exports.np_environmental:registerHook('payout', function(ctx)
if os.date('*t').wday == 1 or os.date('*t').wday == 7 then
for _, p in ipairs(ctx.payouts) do p.amount = p.amount * 2 end
end
end)
-- only certified members may cut a fallen tree (ctx.scene and ctx.task are ids)
exports.np_environmental:registerHook('beforeTask', function(ctx)
if ctx.task == 'cut_trunk' and not isCertified(ctx.identifier) then
return 'You are not certified for the chainsaw.'
end
end)
With Config.Payout.society = true the payouts entries carry account = 'society' and job instead of an
identifier.
Server events ​
server
Server-local (AddEventHandler), never sent over the network. Scenes are passed in the GetScene shape.
| Event | Arguments | Fired when |
|---|---|---|
np_environmental:ready |
none | The resource is ready (exports answer from now on) |
np_environmental:rolled |
{ hit, template, scene, reason } |
Every director roll, hit or miss |
np_environmental:spawned |
scene |
A scene spawned (director, staff, export, chain) |
np_environmental:discovered |
src, scene |
A player saw a scene for the first time |
np_environmental:reported |
src, scene, report |
A report was filed. report = { id, service, text, precise, pin, name, at, voice?, kind?, hurt? } |
np_environmental:stageChanged |
scene, stage |
A scene got worse |
np_environmental:taskDone |
src, scene, taskId |
A task was finished |
np_environmental:cleared |
scene, reason, payouts |
A scene was cleared. reason = 'tasks' | 'command' | 'staff' | 'export' |
np_environmental:expired |
scene |
The lifetime ran out (the scene is removed later, when nobody is near) |
np_environmental:removed |
scene |
The scene is gone from the world |
AddEventHandler('np_environmental:cleared', function(scene, reason, payouts)
local total = 0
for _, p in ipairs(payouts) do total = total + p.amount end
sendToDiscord(('%s cleared (%s), $%d paid'):format(scene.label, reason, total))
end)
AddEventHandler('np_environmental:reported', function(src, scene, report)
if report.service == '911' and report.hurt then
-- forward to an MDT
end
end)
Events np_environmental listens to ​
| Event | From | Effect |
|---|---|---|
np_inventory:server:ready |
np_inventory | Registers the items again |
np_phone:emergency:location |
np_phone | A caller sent their location on an emergency line: a voice report (voice reports) |
np_phone:islandAction |
np_phone | Accept / Map on an alert's Live Activity |
np_prophandler:spawned / np_prophandler:despawned |
np_prophandler | The client looks up scene props streamed by np_prophandler |
np_npchandler:spawned / np_npchandler:despawned |
np_npchandler | The client looks up scene peds streamed by np_npchandler |
np_npchandler:ready |
np_npchandler | The server registers the scene peds again |
np_prophandler:ready |
np_prophandler | The server registers the scene props again |
Framework events (esx:setJob, QBCore:Client:OnJobUpdate, QBCore:Client:SetDuty, player loaded / unloaded) keep
jobs and duty current.
Net events (np_environmental:rpc, :rpcResult, :init, :state, :sync, :nui, :scenes, :view,
:closures, :alert, :task:cancel, …) are internal. See the NUI contract.
Commands and keys ​
| Command / key | Who | What |
|---|---|---|
/report |
Everyone | Report a scene (the np_phone app when it runs) |
/scenes · F6 |
Faction members | The scene board |
/event cleanup |
Factions on the scene's list, staff | Clear the scene you stand at |
/envadmin |
Staff (editor) |
The template editor |
/envdirector |
Staff (director) |
The director |
| Where | Keys |
|---|---|
| At a scene | E inspect · G call it in · F work on a task (E once inspected) · H photo (np_phone) |
| Report form | Enter send · Esc close |
| Board | LMB select · Wheel zoom · Enter accept · H hand over · F6 close |
| Editor | LMB move · R rotate · N new object · W place in world; walking: E drop, BACKSPACE back |
| Director | LMB inspect · T teleport · Del remove scene |
Keys come from Config.Client.keys and Config.Commands.boardKey; players can rebind F6 in the FiveM key
bindings.