From 1e6b0f4c490cd9666512cd45d40d9123dfa0949a Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Sun, 27 Aug 2023 01:31:54 +0200 Subject: [PATCH] feat(client/vehicle): cruise control keybind --- client/vehicle.lua | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/client/vehicle.lua b/client/vehicle.lua index 7306dd1..6293d64 100644 --- a/client/vehicle.lua +++ b/client/vehicle.lua @@ -632,5 +632,79 @@ exports("keyControl", function(action, slot) end end) +local cruiseSpeedSet = 0 +local cruiseSpeedVehicle = 0 +local cruiseControlEnabled = false + +local function cruiseControl() + cruiseSpeedVehicle = GetEntitySpeed(playerVehicle) * 2.236936 + if not playerVehicle then + lib.notify({ + title = "Cruise control", + description = "Vehicle cruise control disabled.", + type = "inform", + position = "bottom-right", + duration = 3000 + }) + return + end + if cruiseSpeedVehicle < cruiseSpeedSet/3 then + lib.notify({ + title = "Cruise control", + description = "Vehicle cruise control disabled.", + type = "inform", + position = "bottom-right", + duration = 3000 + }) + return + end + if cruiseSpeedVehicle < cruiseSpeedSet then + SetControlNormal(0, 71, 0.6) + end + return true +end + +lib.addKeybind({ + name = "vehicleCruiseControl", + description = "Toggle vehicle cruise control", + defaultKey = "", + onPressed = function(self) + if cruiseControlEnabled and cruiseSpeedVehicle-1 > cruiseSpeedSet then + cruiseSpeedSet = cruiseSpeedVehicle + return lib.notify({ + title = "Cruise control", + description = ("Increased to %d mph."):format(math.floor(cruiseSpeedSet)), + type = "inform", + position = "bottom-right", + duration = 3000 + }) + elseif cruiseControlEnabled then + cruiseControlEnabled = false + return lib.notify({ + title = "Cruise control", + description = "Vehicle cruise control disabled.", + type = "inform", + position = "bottom-right", + duration = 3000 + }) + end + if not playerVehicle then return end + cruiseControlEnabled = true + cruiseSpeedVehicle = math.floor(GetEntitySpeed(playerVehicle) * 2.236936) + cruiseSpeedSet = cruiseSpeedVehicle + lib.notify({ + title = "Cruise control", + description = ("Set to %d mph."):format(math.floor(cruiseSpeedSet)), + type = "inform", + position = "bottom-right", + duration = 3000 + }) + CreateThread(function() + while cruiseControlEnabled and cruiseControl() do Wait(0) end + cruiseControlEnabled = false + end) + end +}) + end end)