Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(menu): Prevent player from spawning vehicle while frozen #1004

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions resource/menu/client/cl_freeze.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ RegisterNetEvent('txcl:freezePlayerOk', function(isFrozen)
sendSnackbarMessage('info', localeKey, true)
end)

RegisterNetEvent('txcl:setFrozen', function(isFrozen)
debugPrint('Frozen: ' .. tostring(isFrozen))
--NOTE: removed the check for vehicle, but could be done with
-- IsPedInAnyVehicle for vehicles and IsPedOnMount for horses
local isPlayerFrozen = false
RegisterNetEvent('txcl:setFrozen', function(setFrozen)
debugPrint('Frozen: ' .. tostring(setFrozen))
isPlayerFrozen = setFrozen

-- Freeze player
local playerPed = PlayerPedId()
TaskLeaveAnyVehicle(playerPed, 0, 16)
FreezeEntityPosition(playerPed, isFrozen)
sendFreezeAlert(isFrozen)
end)
FreezeEntityPosition(playerPed, setFrozen)
sendFreezeAlert(setFrozen)

-- If frozen, prevent the player from spawning a vehicle
if setFrozen then
CreateThread(function()
while isPlayerFrozen do
local vehicleOrMount = getPedVehicle()
if vehicleOrMount ~= nil then
DeleteEntity(vehicleOrMount)
end
Wait(100)
end
end)
end
end)
16 changes: 16 additions & 0 deletions resource/menu/client/cl_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ function playLibrarySound(sound)
PlaySoundFrontend(redmSoundLibrary[sound][1], redmSoundLibrary[sound][2], true, 1);
end
end

-- Get vehicle that player is in
function getPedVehicle()
local ped = PlayerPedId()
local veh
if IS_REDM and IsPedOnMount(ped) then
veh = GetMount(ped)
else
veh = GetVehiclePedIsIn(ped, false)
end
if veh and veh > 0 then
return veh
else
return nil
end
end
15 changes: 0 additions & 15 deletions resource/menu/client/cl_vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ if not TX_MENU_ENABLED then return end

--[[ NUI CALLBACKS ]]

local function getPedVehicle()
local ped = PlayerPedId()
local veh
if IS_REDM and IsPedOnMount(ped) then
veh = GetMount(ped)
else
veh = GetVehiclePedIsIn(ped, false)
end
if veh and veh > 0 then
return veh
else
return nil
end
end

-- NOTE: this is not a complete list, but most others have the type "automobile"
local vehClassNamesEnum = {
[8] = "bike",
Expand Down