[Release] Vehicle Speed Limiter (Cruise control alternative)

Up until recently our community was using a cruise control script released on the forums. It was great, but players discovered that if you enabled cruise control, the vehicle did not experience traction or speed loss on turns and terrain changes. This prompted me to look into allowing players to restrict the vehicle speed without any menu.

It’s simple. Every time there is a new driver, speed limiter is reset. Pressing Y will activate, shift+Y to disable. Works with customs cars (handling.meta)

I did not package as a resource as I don’t believe it should be in it’s own. To install, simply add any client script.

-------------------------------------------------------------------------------
-- Title: Speed limiter.
-- Author: Serpico -- twitch.tv/SerpicoTV
-- Description: This script will restict the speed of the vehicle when
--              INPUT_MP_TEXT_CHAT_TEAM is pressed. To disable, press
--              INPUT_VEH_SUB_ASCEND + INPUT_MP_TEXT_CHAT_TEAM
-------------------------------------------------------------------------------
local useMph = false -- if false, it will display speed in kph

Citizen.CreateThread(function()
  local resetSpeedOnEnter = true
  while true do
    Citizen.Wait(0)
    local playerPed = GetPlayerPed(-1)
    local vehicle = GetVehiclePedIsIn(playerPed,false)
    if GetPedInVehicleSeat(vehicle, -1) == playerPed and IsPedInAnyVehicle(playerPed, false) then

      -- This should only happen on vehicle first entry to disable any old values
      if resetSpeedOnEnter then
        maxSpeed = GetVehicleHandlingFloat(vehicle,"CHandlingData","fInitialDriveMaxFlatVel")
        SetEntityMaxSpeed(vehicle, maxSpeed)
        resetSpeedOnEnter = false
      end
      -- Disable speed limiter
      if IsControlJustReleased(0,246) and IsControlPressed(0,131) then
        maxSpeed = GetVehicleHandlingFloat(vehicle,"CHandlingData","fInitialDriveMaxFlatVel")
        SetEntityMaxSpeed(vehicle, maxSpeed)
        showHelpNotification("Speed limiter disabled")
      -- Enable speed limiter
      elseif IsControlJustReleased(0,246) then
        cruise = GetEntitySpeed(vehicle)
        SetEntityMaxSpeed(vehicle, cruise)
        if useMph then
          cruise = math.floor(cruise * 2.23694 + 0.5)
          showHelpNotification("Speed limiter set to "..cruise.." mph. ~INPUT_VEH_SUB_ASCEND~ + ~INPUT_MP_TEXT_CHAT_TEAM~ to disable.")
        else
          cruise = math.floor(cruise * 3.6 + 0.5)
          showHelpNotification("Speed limiter set to "..cruise.." km/h. ~INPUT_VEH_SUB_ASCEND~ + ~INPUT_MP_TEXT_CHAT_TEAM~ to disable.")
        end
      end
    else
      resetSpeedOnEnter = true
    end
  end
end)

function showHelpNotification(msg)
    BeginTextCommandDisplayHelp("STRING")
    AddTextComponentSubstringPlayerName(msg)
    EndTextCommandDisplayHelp(0, 0, 1, -1)
end

10 Likes

Nice.
(20 charrrrrrrrr)

1 Like

i cant disable it, shift+y doesnt work

Looks like it doesn’t count modified engine or turbo upgrade, and after disabling it sets max speed to default value without upgrades?

1 Like

I’ve been running the script on our servers for some time now. No issues reported by our players. No one has lost perf upgrade boost while using the limiter. Are you getting any errors in log? How are you testing it?

Looks Nice. It will be making an appearance in my server soon.

same here. did you figure it out?

Saw this on the server, I like it nice work!

Stopped using it. (20 char)

Fine script, if you could actually disable the limiter again =D

1 Like

It’s a silly question, but how can I install it on my server to work for all players? :sweat_smile:

so i dont know why but it does not work for me … nothing happens when i press the buton

This is conflicting with the controller function to change your perspective (V) on controller it’s the View Key

It’s been changed to code 137 (CapsLock), is there supposed to be compatibility crossed over to the controller, is there a way to fix or disable?

I am having the same issue

for these who aren’t capable finding cause for script breaking.

Add

  while ESX == nil do
    TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
    Citizen.Wait(0)
  end

replace

showHelpNotification

with

ESX.ShowNotification

and delete

function showHelpNotification(msg)
    BeginTextCommandDisplayHelp("STRING")
    AddTextComponentSubstringPlayerName(msg)
    EndTextCommandDisplayHelp(0, 0, 1, -1)
end

Cause is BeginTextCommandDisplayHelp("STRING") not available anymore

So what exactly is the protocol for getting this implemented? Just paste this into the handling.meta file for each car? and then implementing the fix that Epri said?

C’est MAJ+Y

anyway there is a chance you could make it have a button to increase and decrease the speed???

Works just Fine, i customized the script and its working great, good job dude!

Works perfectly!! Thanks for this!

1 Like