Disable npc + car spawning

any idea on how to stop npc’s + vehicles from spawning?

local weatherType = "EXTRASUNNY"

Citizen.CreateThread(function()
    local player = PlayerPedId()

    while true do
        SetVehicleDensityMultiplierThisFrame(0.0)
		SetPedDensityMultiplierThisFrame(0.0)
		SetRandomVehicleDensityMultiplierThisFrame(0.0)
		SetParkedVehicleDensityMultiplierThisFrame(0.0)
		SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0)
		SetGarbageTrucks(0)
        SetRandomBoats(0)
        SetWeatherTypeNowPersist(weatherType)
        SetWeatherTypeNow(weatherType)
        SetOverrideWeather(weatherType)
        NetworkOverrideClockTime(12, 0, 0)
        SetIgnoreLowPriorityShockingEvents(player, true)
        SetPoliceIgnorePlayer(player, true)
        SetDispatchCopsForPlayer(player, false)
        SetMaxWantedLevel(0)
        SetPlayerWantedLevel(player, 0, false)
        SetPlayerWantedLevelNow(player, false)
        RemovePeskyVehicles(player, 5000.0)

        Citizen.Wait(1)
	end
end)

function RemovePeskyVehicles(player, range)
    local pos = GetEntityCoords(playerPed) 

    RemoveVehiclesFromGeneratorsInArea(
        pos.x - range, pos.y - range, pos.z - range, 
        pos.x + range, pos.y + range, pos.z + range
    );
end

It also freeze the time to noon, sets the weather to also being sunny and remove wanted levels. I’m sure you can edit that out.

Why is it in a loop?

You are correct, not all the function calls need to be in there.
Atleast the *ThisFrame functions do definitely need to be in the loop, otherwise it won’t do anything.

I guess i’m too lazy to find out what can or can’t be in the loop haha

and he can try this too:
SetPedNonCreationArea(-6000.0, -6000.0, -6000.0, 10000.0, 10000.0, 8000.0)

1 Like

Oh neat, but it’s only for peds though. But still a nice suggestion :slight_smile:

(I guess vehicles would never spawn because they won’t have a ped in them :thinking:)

Try This:

Citizen.CreateThread(function()
	while true do
		Wait(0)
		SetVehicleDensityMultiplierThisFrame(0.0)
		SetPedDensityMultiplierThisFrame(0.0)
		SetRandomVehicleDensityMultiplierThisFrame(0.0)
		SetParkedVehicleDensityMultiplierThisFrame(0.0)
		SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0)
	end
end)

In this the time isn’t freeze, the weather isn’t only sunny and the wanted level isn’t remove

where i have to place this code ?

2 Likes

where do i put this?

You create a __resource.lua and a client.lua, if you don’t know how to do that then you should learn how to do it, or just copy it from other script and edit it.

Hey! Is it possible to use this to prevent NPC vehicles from spawning in certain areas? Like let’s say for example there’s a parking lot, but it’s full of NPC vehicles that i don’t want to be there. Would it be possible to set a range to prevent them from spawning? I’d like to do this in multiple areas around the map. Thanks in advance!

If I want to close the car that goes on the road But I want the NPC walking to remain. What do i have to do

1 Like