[FREE] [STANDALONE] Cruise Control with custom speed

Is there anyway to change notify position?

Actually no, because it uses native notifications, but can be changed by anyother notifications very easy

Would i need to rewrite everything? to do this

No, u just need to change pnt_cruiseControl:Notify events for your notify events, if u want to tell me what notify u uses i can adapt it for you :slight_smile:

im using one from qbcore

pnt_cruiseControl-QbCore.rar (2.8 KB)
Here you have :smiley:

thanks!

2 Likes

Does this script work with planes?

Actually i don’t try it, maybe works

How do I stop it from sending something in chat when I press the keybind?

Hello everyone,

I’m trying to get a Lua script to work, but I’m having some trouble and can’t seem to figure out what’s wrong. I’m using the script to adjust the speed of vehicles in-game, but I’m not able to execute the ‘cc variable’ command that I’ve included in the code.

If anyone has any ideas or suggestions on what might be causing this issue, I would really appreciate your help. Thank you in advance!

server.main
ESX = exports["es_extended"]:getSharedObject()

if Config.Speed  == "km" then
    Config.Speed = 3.6
else
    Config.Speed = 2.237
end

if Config.Command then
    RegisterCommand(Config.CruiseCommand, function(source, args)
        if tonumber(args[1]) then
            local cruiser = math.floor((args[1]) / Config.Speed) + 0.5
            TriggerClientEvent('pnt_cruiseControl:cruiserCar', source, cruiser, args[1])
        else
            TriggerClientEvent('pnt_cruiseControl:Notify', source, Strings["args_invalid"])
        end
    end)
end
client.main
ESX = exports["es_extended"]:getSharedObject()

local cruiseEnabled = false

if Config.Speed == "km" then
    speed = 3.6
else
    speed = 2.237
end

if Config.Command then
    RegisterNetEvent("pnt_cruiseControl:cruiserCar")
    AddEventHandler(
        "pnt_cruiseControl:cruiserCar",
        function(cruiserSpeed, cruiserNotification)
            local ped = PlayerPedId() -- Ped
            local inVehicle = IsPedSittingInAnyVehicle(ped) -- Get if ped is in any vehicle
            local vehicle = GetVehiclePedIsIn(ped, false) -- Get Vehicle In

            Wait(250)

            if not inVehicle then
                return TriggerEvent("pnt_cruiseControl:Notify", Strings["not_in_vehicle"])
            end

            if not (GetPedInVehicleSeat(vehicle, -1) == ped) then
                return TriggerEvent("pnt_cruiseControl:Notify", Strings["not_driver_seat"])
            end

            SetEntityMaxSpeed(vehicle, cruiserSpeed)
            cruiseEnabled = true
            TriggerEvent(
                "pnt_cruiseControl:Notify",
                string.format(Strings["cruiser_set_at"], cruiserNotification, Config.Speed)
            )
        end
    )

    RegisterCommand(
        Config.OffCruiseCommand,
        function()
            local ped = PlayerPedId() -- Ped
            local inVehicle = IsPedSittingInAnyVehicle(ped) -- Get if ped is in any vehicle
            local vehicle = GetVehiclePedIsIn(ped, false) -- Get Vehicle In
            local maxSpeed = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDriveMaxFlatVel") -- Get max speed to reset

            Wait(250)

            if not inVehicle then
                return TriggerEvent("pnt_cruiseControl:Notify", Strings["not_in_vehicle"])
            end

            if not (GetPedInVehicleSeat(vehicle, -1) == ped) then
                return TriggerEvent("pnt_cruiseControl:Notify", Strings["not_driver_seat"])
            end

            SetEntityMaxSpeed(vehicle, maxSpeed)
            cruiseEnabled = false
            TriggerEvent("pnt_cruiseControl:Notify", Strings["no_cruiser"])
        end
    )
end

if Config.KeyMap then
    RegisterCommand(
        "+activatecruiser",
        function()
            local ped = PlayerPedId() -- Ped
            local inVehicle = IsPedSittingInAnyVehicle(ped) -- Get if ped is in any vehicle
            local vehicle = GetVehiclePedIsIn(ped, false) -- Get Vehicle In
            local maxSpeed = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDriveMaxFlatVel") -- Get max speed to reset
            local cruiserSpeed = GetEntitySpeed(vehicle) -- Get the current speed

            Wait(250)

            if not inVehicle then
                return
            end

            if not (GetPedInVehicleSeat(vehicle, -1) == ped) then
                return
            end

            if not cruiseEnabled then
                SetEntityMaxSpeed(vehicle, cruiserSpeed)
                cruiserNotification = math.floor(cruiserSpeed * speed + 0.5)
                cruiseEnabled = true
                TriggerEvent(
                    "pnt_cruiseControl:Notify",
                    string.format(Strings["cruiser_set_at"], cruiserNotification, Config.Speed)
                )
            else
                SetEntityMaxSpeed(vehicle, maxSpeed)
                cruiseEnabled = false
                TriggerEvent("pnt_cruiseControl:Notify", Strings["no_cruiser"])
            end
        end
    )

    RegisterKeyMapping("+activatecruiser", "Activate cruiser", "keyboard", Config.KeyBind)
end

RegisterNetEvent("pnt_cruiseControl:Notify")
AddEventHandler(
    "pnt_cruiseControl:Notify",
    function(msg)
        SetTextFont(0)
        SetNotificationTextEntry("STRING")
        AddTextComponentSubstringPlayerName(msg)
        DrawNotification(false, true)
    end
)

It’s possible that I’m just overlooking something simple, but I’m still having trouble getting the Lua script to work properly. Any help or guidance would be greatly appreciated. Thank you.

Hi, first of all you have any errors in the console? F8 or the server console. Abd for using the cc command you need to put a number or kmh or mph you want

Hello OP :wink:

Thank you for getting in touch. To answer your question, I have no errors in the startup console or in the Open Log (console). The functions are displayed, but when I try to execute the command “/cc 30”, the vehicle accelerates throughout.

If I use the script unchanged (git) , I have the same problem.

@Puntzi Have you possibly adapted and corrected the script?

Try to debug the code because for me works perfectly, put in line 17 print(cruiserSpeed) and print(vehicle)

thx, will check it out, write back soon.