Skip to content

Instantly share code, notes, and snippets.

@userMacieG
Last active October 27, 2022 23:42
Show Gist options
  • Save userMacieG/b482e7e1cce742728d34451e042a99a6 to your computer and use it in GitHub Desktop.
Save userMacieG/b482e7e1cce742728d34451e042a99a6 to your computer and use it in GitHub Desktop.
Turn engine on and off via key
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')
@userMacieG
Copy link
Author

Hello, do you know a way to make this work for boats?

This should work also for boats

@zZOGZz
Copy link

zZOGZz commented Oct 27, 2022

It isnt working for boats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment