Skip to content

Exports ​

What other resources may rely on. np_environmental depends on none of them. Apart from np_prophandler and np_npchandler (required), every sibling it talks to is optional.

All exports below are server-side unless listed under client exports. Exports answer nil / false / {} until np_environmental is ready (np_environmental:ready), and every table they return is a plain copy. A test checks that the documented exports, hooks and events and the code name the same set, both ways.

Server exports ​

server

Export Returns
GetScenes() Live scenes: { { id, template, label, kind, coords, heading, stage, severity, state, spawnedAt, reportedAt } }
GetScene(id) The scene (same fields plus tasks, reports, units, removedObjects), or nil
GetTemplate(id) The template, or nil
GetTemplates() { Template }, enabled and disabled; code-defined ones marked code = true
SpawnScene(templateId, where?, opts?) Scene id, or nil, 'error_code'
ClearScene(id, reason?) boolean
RemoveScene(id) boolean. Removes without payout (the quiet despawn rule does not apply)
ReportScene(src, id, service, text?) Report id, or nil, 'error_code'
IsSceneKnown(src, id) false, 'seen' or 'inspected'
GetCitizen(identifier | src) The citizen record, or nil
RegisterTemplate(def) Template id, or nil, 'invalid_template'
RegisterFaction(key, def) true, or false, 'invalid_faction'
registerHook(name, fn) Hook id, or nil for an unknown name. See Hooks
removeHook(id) boolean

SpawnScene ​

lua
local id, err = exports.np_environmental:SpawnScene(templateId, where, opts)
Argument Description
templateId A template id ('fallen_tree')
where Coordinates { x, y, z, w? }, a spawn point id, or nil for the director's pick of a free spawn point
opts { heading?, quiet = true }

Errors: not_found, no_spawn, invalid_template, vetoed:<reason>. Runs the beforeSpawn hook with source = 'export'.

lua
-- a weather resource: a flooded underpass whenever a storm starts
AddEventHandler('myweather:changed', function(weather)
  if weather == 'THUNDER' then
    local id, err = exports.np_environmental:SpawnScene('flooded_underpass')
    if not id then print('no scene: ' .. tostring(err)) end
  end
end)

ClearScene ​

ClearScene(id, reason?) clears and pays like the task flow. reason defaults to 'export', one of tasks, command, staff, export (staff pays no finder's tip). Runs the beforeClear hook.

ReportScene ​

ReportScene(src, id, service, text?) files a report for a player, with the same rules as the player's own report: the player must have discovered the scene or be within Config.Scenes.reportRadius of it. service is '311' or '911'. Errors include not_found, nothing_here, already_reported, cooldown, too_fast.

lua
-- an MDT forwards a 311 call that came in by text
local reportId, err = exports.np_environmental:ReportScene(src, sceneId, '311', 'Tree across Route 68')

GetCitizen ​

lua
local c = exports.np_environmental:GetCitizen(source)   -- or a character identifier
-- c = { identifier, reports, useful, falseReports, tips, level, levelLabel, rank, next = { label, at } | nil, points }

level is the id from Config.Citizen.levels ('reliable'), levelLabel its localised label, rank its position (1 = Newcomer), next the next level. See Citizen rank.

RegisterTemplate ​

RegisterTemplate(def) adds a code-defined template from another resource: picked by the director like any other, not editable in game, not stored, removed when that resource stops. def has the shape of a template and is validated the same way (nil, 'invalid_template' when it fails). See Code templates.

RegisterFaction ​

lua
exports.np_environmental:RegisterFaction('harbour', {
  label = 'Harbour Patrol', icon = 'anchor', tint = 'blue', service = '911', needsDuty = true,
  jobs = { harbour = 0 },
})

def = { label, icon, tint, service = '311' | '911', needsDuty = true, jobs = { <job> = <min grade> } }. The faction can then be put on templates in the editor and answers its service like the ones in Config.Factions.

Client exports ​

client

Export Returns
GetKnownScenes() Scenes this player has discovered that are still live: { { id, template, label, kind, icon, tint, coords, stage, severity } }
GetNearestScene() { id, template, label, kind, coords, distance } of the nearest known scene, or nil
IsWorking() boolean: the player is doing a task right now
lua
-- a HUD hides its minimap tile while the player works a scene
if exports.np_environmental:IsWorking() then hideMinimap() end

The item use exports np_environmental.traffic_cone / np_environmental.road_flare are for the inventory (see Items), not an API.