[Release][CFX][FX] CruiseControl

Hi there folks.

This is a cruisecontrol resource i have had for quite some time but did not bother to release. However a couple of friends of mine asked for it so i thought why not just release it on the forums.

How it works:
When driving click the Y button (default on nordic keyboards) and the cruisespeed will be set.

If you want to increase the speed just speed up alittle on W and the cruisecontroller will reset the speed to the new current one.

If you want to turn it off push the Y button but without touching any other button at the same time, or it will not work.

You can also turn it off by breaking below around the 40 km/h.

Version 1.0
pv-cruisecontrol.zip (1.0 KB)

8 Likes

Just tried It. Great Job! Seems to work perfect.
Thank you so much!

Works great ! Thanks for sharing!

Halla :smiley:
Opportunity to change key to turn on and off

Mulighet og endre tast for pÄ og av ?

Yep, you can either rebind your Y key to something else or change line 37

if IsControlJustPressed(1, 246) then

where 246 is your keycode. You may find possible keycodes her LINK TO KEYCODES

Controls controls controls
 not keys

Yes, im sorry sensei you are right. controls


Sorry, I meant no disrespect by that. Maybe I should have added a, lol. Lol

1 Like

I did not take it as a disrespect :wink: So no worries :smiley:

2 Likes

Tried to change. nothing happend :frowning: when i change it back it works


What i am doing wrog

This looks sick imma try it out

I’m trying to get this to work with MPH not KMH it works but doesnt set the right speed, helpful tips for this?

Changing from ‘KMH’ to ‘MPH’

It’s very easy to change it from kmh to mph. Follow below:

  1. Open /cl_cruisecontrol.lua
  2. Look for Line19 that looks like this:
NotificationMessage("CruiseControl: ~g~ TÆNDT ~w~ - ~b~ " .. cruiseKm .." km/t")
  1. Change this line to look like this:
NotificationMessage("CruiseControl: ~g~ TÆNDT ~w~ - ~b~ " .. cruiseMph .."mph")

Suggested Changes

This text: “TÆNDT” and “SLUKKET” makes no sense so you could change it to something like:

NotificationMessage("CruiseControl: ~g~ ON ~w~ - ~b~ " .. cruiseMph .."mph")
NotificationMessage("CruiseControl: ~r~ OFF")

This will display:
‘CruiseControl: ON - XXmph’
&
‘CruiseControl: OFF’

Get rid of notifications all together for integration with CarHud

If you want to get rid of all the notifications because you’re integrating this plugin with ‘Carhud’ then replace your cl_cruisecontrol.lua with this:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
		if IsControlJustPressed(1, 56) then
			TriggerEvent('pv:setCruiseSpeed')
		end
	end
end)

local cruise = 0

AddEventHandler('pv:setCruiseSpeed', function()
	if cruise == 0 and IsPedInAnyVehicle(GetPlayerPed(-1), false) then
		if GetEntitySpeedVector(GetVehiclePedIsIn(GetPlayerPed(-1), false), true)['y'] > 0 then
			cruise = GetEntitySpeed(GetVehiclePedIsIn(GetPlayerPed(-1), false))
			local cruiseKm = math.floor(cruise * 3.6 + 0.5)
			local cruiseMph = math.floor(cruise * 2.23694 + 0.5)
			
			
			Citizen.CreateThread(function()
				while cruise > 0 and GetPedInVehicleSeat(GetVehiclePedIsIn(GetPlayerPed(-1), false), -1) == GetPlayerPed(-1) do
					local cruiseVeh = GetVehiclePedIsIn(GetPlayerPed(-1), false)
					if IsVehicleOnAllWheels(cruiseVeh) and GetEntitySpeed(GetVehiclePedIsIn(GetPlayerPed(-1), false)) > (cruise - 2.0) then
						SetVehicleForwardSpeed(GetVehiclePedIsIn(GetPlayerPed(-1), false), cruise)
					else
						cruise = 0
						break
					end
					if IsControlPressed(1, 8) then
						cruise = 0
					end
					if IsControlPressed(1, 32) then
						cruise = 0
						TriggerEvent('pv:setNewSpeed')
					end
					if cruise > 44 then
						cruise = 0
						break
					end
					Wait(200)
				end
				cruise = 0
			end)
		else
			cruise = 0
		end
	else
		if cruise > 0 then
		end
		cruise = 0
	end
end)

AddEventHandler('pv:setNewSpeed', function()
	Citizen.CreateThread(function()
		while IsControlPressed(1, 32) do
			Wait(1)
		end
		TriggerEvent('pv:setCruiseSpeed')
	end)
end)

function NotificationMessage(message)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(message)
	DrawNotification(0,1)
end

Boats are exploited in this script in terms if you hit the cruise control button over and over again it will make the boat fly. I offer my fix below.

Even though this script is old, it still works perfectly and is still very relevant today, and with a slight modification to it to disable it if the player is in a boat, its perfect.

Replace with the following code from line 13

Line 13 code:

if cruise == 0 and IsPedInAnyVehicle(GetPlayerPed(-1), false) then

With:

if IsPedInAnyBoat(GetPlayerPed(-1), false) then
cruise = 0
NotificationMessage(“CruiseControl: ~r~ BOATS CAN’T!”)
elseif cruise == 0 and IsPedInAnyVehicle(GetPlayerPed(-1), false) then

How would I edit the code so when I change speeds, it auto turns off cruise control?