From 2bab95a34e3ecb599b571e39e988ea9812ccd1fe Mon Sep 17 00:00:00 2001 From: Yorick <125297057+Yorick20022@users.noreply.github.com> Date: Tue, 22 Oct 2024 23:57:12 +0200 Subject: [PATCH] (fix) Prevents player from spawning car when frozen --- resource/menu/client/cl_freeze.lua | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/resource/menu/client/cl_freeze.lua b/resource/menu/client/cl_freeze.lua index f22f67b06..016e695f6 100644 --- a/resource/menu/client/cl_freeze.lua +++ b/resource/menu/client/cl_freeze.lua @@ -28,12 +28,48 @@ RegisterNetEvent('txcl:freezePlayerOk', function(isFrozen) sendSnackbarMessage('info', localeKey, true) end) +local isPlayerFrozen = false + RegisterNetEvent('txcl:setFrozen', function(isFrozen) debugPrint('Frozen: ' .. tostring(isFrozen)) - --NOTE: removed the check for vehicle, but could be done with + --NOTE: removed the check for vehicle, but could be done with -- IsPedInAnyVehicle for vehicles and IsPedOnMount for horses local playerPed = PlayerPedId() - TaskLeaveAnyVehicle(playerPed, 0, 16) + + if isFrozen and IsPedInAnyVehicle(playerPed, false) then + TaskLeaveAnyVehicle(playerPed, 0, 16) + end + + isPlayerFrozen = isFrozen FreezeEntityPosition(playerPed, isFrozen) sendFreezeAlert(isFrozen) + + -- Logic to delete vehicle/horse that the player is trying to spawn + if isFrozen then + CreateThread(function() + while isPlayerFrozen do + if IS_FIVEM then + if IsPedInAnyVehicle(playerPed, false) then + local veh = GetVehiclePedIsUsing(playerPed) + Wait(0) + if DoesEntityExist(veh) then + DeleteEntity(veh) + end + end + Wait(100) + else + if IS_REDM then + if IsPedOnMount(playerPed) then + local horse = GetVehiclePedIsUsing(playerPed) + Wait(0) + if DoesEntityExist(horse) then + DeleteEntity(horse) + end + end + Wait(100) + end + end + end + end) + end end)