From 2acd506504a8b5e02d21168c4725f160a893f1c4 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Tue, 5 Aug 2025 12:34:25 +0100 Subject: [PATCH] Improve cleanup of distance based peds When changing character, this *should* remove the zone to allow the script to make a new one when switching --- shared/make/makePed.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/shared/make/makePed.lua b/shared/make/makePed.lua index 69c47b0..3af763d 100644 --- a/shared/make/makePed.lua +++ b/shared/make/makePed.lua @@ -1,5 +1,6 @@ --- A table to keep track of all created Peds. local Peds = {} +local distPeds = {} --- Creates a distance-based Ped (pedestrian) that spawns when the player enters a specified area. -- @@ -21,7 +22,7 @@ local Peds = {} function makeDistPed(data, coords, freeze, collision, scenario, anim, synced, func) local zoneCoords = type(data) == "table" and data.coords or coords local randName = keyGen()..keyGen() - createCirclePoly({ + distPeds[#distPeds+1] = createCirclePoly({ name = randName, coords = vec3(zoneCoords.x, zoneCoords.y, zoneCoords.z - 1.03), radius = 50.0, @@ -31,6 +32,7 @@ function makeDistPed(data, coords, freeze, collision, scenario, anim, synced, fu end, onExit = function() DeletePed(Peds[randName]) + Peds[randName] = nil end, debug = debugMode, }) @@ -245,6 +247,16 @@ function GenerateRandomPedData(data) return newTable end +onPlayerUnloaded(function() + for i = 1, #distPeds do + for k in pairs(Peds) do + DeletePed(Peds[k]) + end + removeZoneTarget(distPeds[i]) + end + distPeds = {} +end) + --- Cleans up all created Peds when the resource stops. onResourceStop(function() for k in pairs(Peds) do