How to prevent peds and cars spawning from a specific area

Hi everyone,

I’m looking for a script or a native to prevent peds and cars spawning from a specific area but not clearing them because i need to Spawn my own peds in this area.
The following code can’t work for me because it’s for the entire Map:

if Config.NoPeds then
	Citizen.CreateThread(function()
		while true do
			Citizen.Wait(1)
	    	SetVehicleDensityMultiplierThisFrame(0.0)
			SetPedDensityMultiplierThisFrame(0.0)
			SetRandomVehicleDensityMultiplierThisFrame(0.0)
			SetParkedVehicleDensityMultiplierThisFrame(0.0)
			SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0)
			local playerPed = GetPlayerPed(-1)
			local pos = GetEntityCoords(playerPed) 
			RemoveVehiclesFromGeneratorsInArea(pos['x'] - 500.0, pos['y'] - 500.0, pos['z'] - 500.0, pos['x'] + 500.0, pos['y'] + 500.0, pos['z'] + 500.0);
			SetGarbageTrucks(0)
			SetRandomBoats(0)
		end
	end)
end

Is that possible to modify it for a specific area?

This 2 native don’t work because they clear all peds and cars:
ClearAreaOfPeds, ClearAreaOfVehicles

Thanks

and similar?

Tip for the snippet you posted. It’s nowadays not the correct way of removing entities map wide. No need to run natives every frame (the PST couple don’t even need to run every frame). BUT these natives can be used for certain areas! Just put a distance check before calling the Set* natives. The garbage trucks and boats you just need to run once afaik.

But running a native once like the one shown by deterministic_bubbles, if it works like is described, sometimes they don’t haha.

SetRoadsInArea could be a good native but that only working with cars traffic and i have a huge area to do
For my project i need to prevent ped and car spawning from the north of the map and keep a normal “life” in the main city in the south

I’ve seen this one but same problem the area is too big
Is that possible to prevent them to spawn everywhere except in a circle area ?
the red zone is the one where i want peds and cars spawning

If something is too big, you have to break it up into pieces to make it easier. You can use zones and apply behavior depending on the zone. That’s already smaller. You can then take each zone that’s supposed to be empty and apply the SetRoadsInArea and SetPedPathsInArea taking the most top left and bottom right coordinate for that zone. I’m sure there’s an easy way to get that.

You could also do it other ways. For example listening on entityCreating and just cancelling everything that is within a certain zone.

I think you can have more control by making use of zones.

how do i use zones?

Did you get a answer?

Did you find a way to do this is the end? I’m really looking for the same thing

1 Like