diff --git a/client/main.lua b/client/main.lua index d72a4a5..62c61f6 100644 --- a/client/main.lua +++ b/client/main.lua @@ -218,8 +218,8 @@ RegisterNetEvent('qb-vehiclekeys:client:RemoveKeys', function(plate) end) RegisterNetEvent('qb-vehiclekeys:client:ToggleEngine', function() - local EngineOn = GetIsVehicleEngineRunning(GetVehiclePedIsIn(PlayerPedId())) local vehicle = GetVehiclePedIsIn(PlayerPedId(), true) + local EngineOn = GetIsVehicleEngineRunning(vehicle) if HasKeys(QBCore.Functions.GetPlate(vehicle)) then if EngineOn then SetVehicleEngineOn(vehicle, false, false, true) @@ -777,3 +777,22 @@ RegisterNUICallback('engine', function() ToggleEngine(GetVehicle()) SetNuiFocus(false, false) end) + +-- New function to disable vehicle controls when the engine is off +Citizen.CreateThread(function() + while true do + Citizen.Wait(0) + local playerPed = PlayerPedId() + local vehicle = GetVehiclePedIsIn(playerPed, false) + + if vehicle and GetPedInVehicleSeat(vehicle, -1) == playerPed then + if not GetIsVehicleEngineRunning(vehicle) then + -- Disable controls if the engine is off + DisableControlAction(0, 71, true) -- Disable acceleration + DisableControlAction(0, 72, true) -- Disable braking + DisableControlAction(0, 63, true) -- Disable left turn + DisableControlAction(0, 64, true) -- Disable right turn + end + end + end +end)