[Release] Leave Engine Running - Includes Keep Door Open [1.0]

Direct downlaod doesn’t work by the way, just wanted to point that out.

hihgh

@RageYT Should be working now. I pushed a quick fix which removed the old direct…

@WestCoast Hello sir.

2 Likes

Thanks :grinning:

1 Like

Great script! If it doesn’t work for you make sure “Leave Engine Running” is disabled in your simple trainer

Yeah that would help haha

2 Likes

As always good job you never cease to amaze, my friend. Good work!

1 Like

Would it be possible to change the “Hold Y to leave engine running” to “Hold Y to turn engine off”? I’ve been in a server and if you held Y or “F” for so long it would turn the engine off. I’m looking for something like that.

Is there a way to reverse the script so you hold to turn it off and press to leave it running?

3 Likes

Can you leave the radio on while outside the car?

Yes. It works as it would like you jump out whileoving. If that makes sense.

It doesnt work. when i get out of my vehicle the engine is still on

Can someone edit this so it stays on when you hit f to exit, and you have to hold f to turn engine off when exiting?

1 Like

This script allows our players to start the engine of a car that died with our damage script.

is there any way how to make it automatic? so you dont have to hold “F”.

Is there some way I can change this so the engine stays on when “F” is pressed instead of held? And engine turns off when “F” is held? I have Tried changing “IsControlPressed” to “IsControlJustPressed” and have added “and timeHeld < 10” all to no avail and I’m not really a scripting guru either…

I figured out how to do exactly this… This is the code I used

-------------------------------------------
--- Leave Engine Running, Made by FAXES ---
-------------------------------------------

--- Config ---
RestrictEmer = true -- Only allow this feature for emergency vehicles.
keepDoorOpen = false -- Keep the door open when getting out.

--- Code ---
local notify = false

function ShowNotification(text)
    SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local ped = GetPlayerPed(-1)
        local veh = GetVehiclePedIsIn(ped, false)

        if not notify then
            if IsPedInAnyVehicle(ped, true) then
                ShowNotification("Tap ~b~F ~w~to keep engine running.")
                notify = true
            end
        end
        if RestrictEmer then
            if GetVehicleClass(veh) == 18 then
                if IsPedInAnyVehicle(ped, false) and IsControlPressed(2, 75) and not IsEntityDead(ped) then
                    Citizen.Wait(150)
                    if IsPedInAnyVehicle(ped, false) and IsControlReleased(2, 75) and not IsEntityDead(ped) then
                        SetVehicleEngineOn(veh, true, true, false)
                        if keepDoorOpen then
                            TaskLeaveVehicle(ped, veh, 256)
                        else
                            TaskLeaveVehicle(ped, veh, 0)
                        end
                    end
                end
            end
        else
            if IsPedInAnyVehicle(ped, false) and IsControlPressed(2, 75) and not IsEntityDead(ped) then
                Citizen.Wait(150)
                if IsPedInAnyVehicle(ped, false) and IsControlPressed(2, 75) and not IsEntityDead(ped) then
                    SetVehicleEngineOn(veh, true, true, false)
                    if keepDoorOpen then
                        TaskLeaveVehicle(ped, veh, 256)
                    else
                        TaskLeaveVehicle(ped, veh, 0)
                    end
                end
            end
        end
	end
end)
1 Like

If anyones still looking for a way to make it like gta 4 style where you have to hold F to turn the engine off

Edit: Seems I made a mistake, edited in the fixed one

-------------------------------------------
--- Leave Engine Running, Made by FAXES ---
-------------------------------------------

--- Config ---
RestrictEmer = false -- Only allow this feature for emergency vehicles.
keepDoorOpen = true -- Keep the door open when getting out.

--- Code ---
local notify = false

function ShowNotification(text)
    SetNotificationTextEntry("STRING")
    AddTextComponentString(text)
    DrawNotification(false, false)
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local ped = GetPlayerPed(-1)
        local veh = GetVehiclePedIsIn(ped, false)

        if not notify then
            if IsPedInAnyVehicle(ped, true) then
                ShowNotification("Hold ~b~F ~w~to toggle engine.")
                notify = true
            end
        end

        if IsPedInAnyVehicle(ped, false) then
            if IsControlPressed(1, 23) and not IsEntityDead(ped) then
                SetVehicleEngineOn(veh, false, true, false)
                if keepDoorOpen then
                    TaskLeaveVehicle(ped, veh, 256)
                end
            elseif IsControlJustReleased(1, 23) and not IsEntityDead(ped) then
                SetVehicleEngineOn(veh, true, true, false)
            end
        end
	end
end)


1 Like

You should PR it on GitHub :wink: