Skip to content

Ambient population ​

Control the game's own peds, traffic and scenarios: density overrides, suppressed areas, and scenario type and group toggles. Every override has an id, belongs to the calling resource and is removed when that resource stops.

lua
-- quiet streets for a parade
exports.np_npchandler:setPopulation('np_events:parade', { peds = 0.1, vehicles = 0.0 },
  { coords = vector3(200.0, -900.0, 30.0), radius = 250.0 })
exports.np_npchandler:suppressArea('np_events:stage', { coords = vector3(195.0, -935.0, 30.7), radius = 40.0, vehicles = true })
exports.np_npchandler:setScenarioGroups('np_events:no_cops', { POLICE_POUND1 = false })

-- afterwards
exports.np_npchandler:clearPopulation('np_events:parade')
exports.np_npchandler:clearPopulation('np_events:stage')
exports.np_npchandler:clearPopulation('np_events:no_cops')

Client or server ​

The same five exports exist on both sides.

  • Client: the override applies to this player only.
  • Server: the override is stored on the server and synced to every client, in the snapshot and on the same revisioned stream as NPC definitions. Clients that join later get it too.

They return true or false, reason. clearPopulation(id) returns true when it removed something.

One id can hold one override of each kind. Setting the same id and kind again replaces it. clearPopulation(id) removes every kind under that id.

Density ​

lua
setPopulation(id, { peds = 0.0, vehicles = 0.0, scenarios = 0.0, parked = 0.0, routingBucket = nil }, area?)
Field Notes
peds Ambient ped density, 0.0 to 1.0
vehicles Traffic density (random and normal), 0.0 to 1.0
scenarios Scenario ped density, 0.0 to 1.0
parked Parked vehicle density, 0.0 to 1.0
routingBucket Only for players in this bucket
area Optional { coords, radius }, radius 1 to 3000. Without it the override applies everywhere

Every value is optional. Overrides stack: for each channel, the lowest value among the overrides that apply to the player wins. Which overrides apply is checked every population.areaCheckIntervalMs (500 ms). The per-frame density natives only run while at least one override applies.

Suppressed areas ​

lua
suppressArea(id, { coords, radius, peds = true, vehicles = false, scenarios = true, routingBucket = nil })
Field Default Notes
coords, radius required Radius 1 to 500
peds true Ambient peds are cleared from the area and kept out of it
vehicles false Vehicle generators in the area are switched off and their vehicles removed; the area is cleared of vehicles
scenarios true A scenario blocking area covers it
routingBucket none Only for players in this bucket
  • Scenario blocking and vehicle generators are set when the override is added and undone when it is removed. Overlapping suppressed areas keep their generators off.
  • While the player is within the radius + population.clearRangeMargin (100 m), the area is cleared every population.clearIntervalMs (1 s).
  • The game has one ped non-creation area at a time. np_npchandler gives it to the nearest suppressed area with peds = true.

Scenario types and groups ​

lua
setScenarioTypes(id, { WORLD_HUMAN_SMOKING = false, WORLD_HUMAN_DRINKING = false })
setScenarioGroups(id, { PRISON_TOWERS = false })

Up to 64 names per call, each true or false. Toggles stack: the newest override of a name wins. Removing the last override of a name restores the game default (scenario types: enabled; groups: the state before the first override).

Refusals ​

'invalid_id', 'invalid_population', 'unknown_field', 'invalid_area', 'invalid_flag', 'invalid_routing_bucket', 'invalid_scenarios'.