Exports & events
On this page
Server exports: density
Lua
exports['saf-traffic']:SetDensity('rush') -- a preset id, or a table:
exports['saf-traffic']:SetDensity({ vehicle = 1.0, random = 1.0, parked = 0.8, ped = 1.0, scenario = 1.0,
vehicleBudget = 3, pedBudget = 3 })
exports['saf-traffic']:SetSchedule(true, { { from = '07:00', to = '09:00', preset = 'rush' } })Server exports: items
Where an item goes is one of: coords + radius, coords + road = true (the nearest road),
segs = { road ids }, or box = { x1, y1, x2, y2 }.
Lua
local ok, id = exports['saf-traffic']:AddClosure({ coords = vec3(215.0, -810.0, 30.0), road = true,
label = 'Crash on Strawberry Ave', minutes = 30, announce = 'nearby' })
exports['saf-traffic']:AddClosure({ coords = vec3(-1000.0, -2700.0, 14.0), radius = 60, mode = 'slow' })
exports['saf-traffic']:AddJam({ coords = vec3(800.0, -1200.0, 30.0), radius = 250, level = 3, cars = 12 })
exports['saf-traffic']:AddSpeedZone({ coords = vec3(-400.0, 100.0, 60.0), radius = 80, speed = 20 })
exports['saf-traffic']:AddDetour({ segs = { 120, 121 }, via = { 300, 301 }, speed = 15 })
exports['saf-traffic']:EditItem(id, { label = 'Crash cleared, one lane', mode = 'slow' })
exports['saf-traffic']:RemoveClosure(id) -- also RemoveJam, RemoveSpeedZone, RemoveItem
exports['saf-traffic']:ClearAll() -- or ClearAll('jam')
exports['saf-traffic']:GetState() -- density, rush, items, schedule...Options for the add exports
| Option | Values | What it does |
|---|---|---|
label | text | Name shown in the panel and announcements |
minutes | number | End timer. 0 means no end |
announce | 'off', 'nearby', 'all' | Who hears about it |
when | 'always', 'rush' | Active all the time, or only in rush hour |
mode | 'full', 'slow' | Closures: shut the road or slow one lane |
speed | number | Speed for slow closures, speed zones and detours, in Config.SpeedUnit |
props | boolean | Place barriers and cones |
peds | boolean | Close footpaths too |
level | 1 to 4 | Jams: Slow to Stopped |
cars | number | Jams: extra AI cars |
stopGo | boolean | Jams: stop and go |
Return values
The setters return ok, message. The add exports return ok, id. Changes are logged under the calling
resource's name.
Client exports
Lua
exports['saf-traffic']:GetState() -- density, rush and the active items as this player has them
exports['saf-traffic']:GetDensity()Events and state
Lua
-- server: after every change
AddEventHandler('saf-traffic:server:updated', function(state) end)
-- client: after the player receives a change
AddEventHandler('saf-traffic:client:updated', function(state) end)
-- anywhere: a small summary for HUDs
GlobalState['saf-traffic'] -- { preset, rush, closures, jams, speedZones, detours }Example: close a road from a crash script
Lua
-- server, in your own resource
RegisterNetEvent('my-crash:serious', function(coords)
local ok, id = exports['saf-traffic']:AddClosure({
coords = coords, road = true, label = 'Serious crash', minutes = 20, announce = 'nearby',
})
if not ok then print('Closure failed: ' .. tostring(id)) end
end)