Today i give you a simple but very effective script, we found that having 100s of cars would take a stupid amount of time to balance within the gta v speeds of things - so we came up with a very simple but a HUGE time saver of a script
What does it do?
This script allows you to hard limit any category/car within the qbcores vehicle.lua script.
Please note if your vehicle is not in that list it wont be limited, this is why we added a way to limit a car by the name and not the class.
if you want text to be on screen to say the max speed of the car but this under the scripts code
– below is the text on screen you can move this
local textX = 0.015
local textY = 0.080
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = GetPlayerPed(-1)
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * 2.236936
local category = GetVehicleClass(vehicle)
local limit = speedLimits[category]
local name = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
local limitByName = speedLimitsByName[name]
if limitByName then
limit = limitByName
end
if limit and speed > limit then
SetEntityMaxSpeed(vehicle, limit * 0.44704) – convert mph to m/s
else
SetEntityMaxSpeed(vehicle, 999.0) – set the default maximum speed of the vehicle here
end
DrawHudText(“~b~Max Car speed: ~w~” … tostring(math.floor(limit)) … " mph", textX, textY, 0.4)
end
end
end)
function DrawHudText(text, x, y, scale)
SetTextFont(4)
SetTextProportional(1)
SetTextScale(scale, scale)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(2, 0, 0, 0, 150)
SetTextDropShadow()
SetTextOutline()
SetTextEntry(“STRING”)
AddTextComponentString(text)
DrawText(x, y)
end
if i i put in an spawn name of the car i want an limit on in the speedlimitsmyname it wil still get the motorcycles catagory i want all my addon cars on an different limit do you know how i can fix that?
Hey there, i tried to define custom speedlimits to my vanilla cars, but the script grabbed the values from the lines above, where every category is defined. If i blend them out, my custom set speedlimit does not apply to my vehicle. Screenshot is provided. Can you help me out here? Screenshot by Lightshot
try this - replace all the code with this - not tested as I don’t have a server to do so right now
local speedLimitsByName = {
[“fxxk”] = 135.0, – fxxk
}
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = GetPlayerPed(-1)
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * 2.236936
local name = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
local limit = speedLimitsByName[name]
if limit then
SetEntityMaxSpeed(vehicle, limit * 0.44704)
SetTextComponentFormat(“STRING”)
AddTextComponentString(“Max Speed: " … tostring(limit) … " MPH”)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
else
SetEntityMaxSpeed(vehicle, 999.0)
end
end
end)
you may need to remove the category that the cars are based in so it does not grab it - I will look into the code more later when I have a chance but I don’t have a lot of free time right now to dedicate