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