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
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