Way to check, if engine is running?

Hi!

Maybe I am just tired and can’t see it, but how could I check in the script, if engine is running? For cruise control.

Everything works, but cruise control is set by current entity speed and doesn’t take in account, if engine is running or not :smile:

function activateCruise()


	local ped = GetPlayerPed(-1)
	local vehicle = GetVehiclePedIsIn(ped, false)
	local speed = GetEntitySpeed(vehicle)
	DisableControlAction(0, 170, true)
	
	
	cruiseSpeed = speed

	--if ped and vehicle and IsPedInAnyVehicle(ped, false) and GetPedInVehicleSeat(vehicle, -1) == ped and speed*2.23694+0.5 > 20 and not IsPedInAnyBoat(ped) and not IsPedInAnyPlane(ped) and (IsDisabledControlJustPressed(0, 168) or (IsControlJustPressed(0, 27) and IsControlJustPressed(0, 99))) then

		if not cruiseControl then
			DisplayNotification("Activated at a speed of "..math.floor(speed*2.23694+0.5).."mph.")
			cruiseControl = true
			setSpeed()
		else
			DisplayNotification("Cruise Control: Deactivated.")
			cruiseControl = false
		end
	--end

	if cruiseControl and (not IsPedInAnyVehicle(ped, false) or not GetPedInVehicleSeat(vehicle, -1) == ped or not IsVehicleOnAllWheels(vehicle)) then
		DisplayNotification("Cruise Control: Deactivated.")
		cruiseControl = false
	end

	
end

Citizen.CreateThread(function()
while true do
	Citizen.Wait(10)
	local ped = GetPlayerPed(-1)
	local vehicle = GetVehiclePedIsIn(ped, false)
	local speed = GetEntitySpeed(vehicle) 
	

	if ped and vehicle and cruiseControl then
		LastVehicleHealth = GetEntityHealth(vehicle)

		if IsControlPressed(1, 71) or IsControlPressed(1, 72) or GetEntityHealth(vehicle) < LastVehicleHealth then
			cruiseControl = false
			DisplayNotification("Cruise Control: Deactivated.")
			
		end
	end

	if cruiseControl and speed*2.23694+0.5 < 20 then
		DisplayNotification("Cruise Control: Deactivated.")
		cruiseControl = false
	end
      end
    end)


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

		if ped and vehicle and cruiseControl and IsVehicleOnAllWheels(vehicle) then
			SetVehicleForwardSpeed(vehicle, cruiseSpeed)
		end
	end
  end)
 end

Hi,

You can use this function: https://runtime.fivem.net/doc/reference.html#_0xAE31E7DF9B5B132E

Works perfectly, thank you <3

Now, would you have an idea how to tell the game that I don’t wanna start the engine just by getting into the car?

I would like to write it, so you have to press button for 1 sec, to start it up :smiley:

In this resource, you have some usefull events: [Release] Extended Events

So, you can try:

AddEventHandler("ee:onPlayerEnterVehicle", function(vehicle)
        SetVehicleEngineOn(vehicle, false, true, false)
end)