hello, is there a way to set it so that NPCs do not spawn in certain places or that cars do not drive there. thanks
local disableZone = {
center = vector3(100.0, 100.0, 100.0), -- Center of the disable zone
radius = 200.0 -- Radius of the disable zone in meters
}
-- Function to check if an entity is within the disable zone
function isEntityInDisableZone(entity)
local entityCoords = GetEntityCoords(entity)
local distance = #(entityCoords - disableZone.center)
return distance <= disableZone.radius
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000) -- Check every second
-- Disable Peds
local pedCount = GetNumberOfPedsInGroup()
for i = 0, pedCount - 1 do
local ped = GetPedAtIndex(i)
if DoesEntityExist(ped) and isEntityInDisableZone(ped) then
DeleteEntity(ped)
end
end
-- Disable Vehicles
local vehicleCount = GetNumberOfVehiclesInGroup()
for i = 0, vehicleCount - 1 do
local vehicle = GetVehicleAtIndex(i)
if DoesEntityExist(vehicle) and isEntityInDisableZone(vehicle) then
DeleteEntity(vehicle)
end
end
end
end)
function GetNumberOfPedsInGroup()
local handle, ped = FindFirstPed()
local pedCount = 0
repeat
pedCount = pedCount + 1
local success, ped = FindNextPed(handle)
until not success
EndFindPed(handle)
return pedCount
end
function GetPedAtIndex(index)
local handle, ped = FindFirstPed()
local currentIndex = 0
local result = nil
repeat
if currentIndex == index then
result = ped
break
end
currentIndex = currentIndex + 1
local success, ped = FindNextPed(handle)
until not success
EndFindPed(handle)
return result
end
function GetNumberOfVehiclesInGroup()
local handle, vehicle = FindFirstVehicle()
local vehicleCount = 0
repeat
vehicleCount = vehicleCount + 1
local success, vehicle = FindNextVehicle(handle)
until not success
EndFindVehicle(handle)
return vehicleCount
end
function GetVehicleAtIndex(index)
local handle, vehicle = FindFirstVehicle()
local currentIndex = 0
local result = nil
repeat
if currentIndex == index then
result = vehicle
break
end
currentIndex = currentIndex + 1
local success, vehicle = FindNextVehicle(handle)
until not success
EndFindVehicle(handle)
return result
end
So i hope this Helps but im to lazy to explain it