Last active
October 27, 2022 23:42
-
-
Save userMacieG/b482e7e1cce742728d34451e042a99a6 to your computer and use it in GitHub Desktop.
Turn engine on and off via key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local playerPed = PlayerPedId() | |
Citizen.CreateThread(function() | |
while true do | |
local currentPlayerPed = PlayerPedId() | |
if currentPlayerPed ~= playerPed then | |
playerPed = currentPlayerPed | |
SetPedConfigFlag(playerPed, 241, true) -- PED_FLAG_DISABLE_STOPPING_VEHICLE_ENGINE | |
SetPedConfigFlag(playerPed, 429, true) -- PED_FLAG_DISABLE_STARTING_VEHICLE_ENGINE | |
end | |
Citizen.Wait(0) | |
end | |
end) | |
RegisterCommand('engine', function() | |
local vehicle = GetVehiclePedIsIn(playerPed) | |
if not vehicle then | |
-- Player is not in vehicle | |
return | |
end | |
if GetPedInVehicleSeat(vehicle, -1) ~= playerPed then | |
-- Player is not a driver | |
return | |
end | |
if GetVehicleClass(vehicle) == 13 then | |
-- Vehicle is a bike | |
return | |
end | |
SetVehicleEngineOn(vehicle, not GetIsVehicleEngineRunning(vehicle), false, true) | |
end, false) | |
RegisterKeyMapping('engine', "Engine", 'keyboard', 'Y') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work also for boats