From 0923fea17290e718f6c9e7c19c28a70701a671dd Mon Sep 17 00:00:00 2001 From: Mycroft Date: Wed, 2 Mar 2022 19:58:50 +0000 Subject: [PATCH] Refactor: CruiseControl - Optimisations --- .../esx_cruisecontrol/client/main.lua | 21 ++++++++----------- [esx_addons]/esx_cruisecontrol/config.lua | 2 ++ [esx_addons]/esx_cruisecontrol/fxmanifest.lua | 7 +------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/[esx_addons]/esx_cruisecontrol/client/main.lua b/[esx_addons]/esx_cruisecontrol/client/main.lua index e1cbd26d..52e65dc9 100644 --- a/[esx_addons]/esx_cruisecontrol/client/main.lua +++ b/[esx_addons]/esx_cruisecontrol/client/main.lua @@ -1,17 +1,14 @@ -local Player = nil local CruisedSpeed, CruisedSpeedKm, VehicleVectorY = 0, 0, 0 -CreateThread(function () - while true do - Wait(0) - if IsControlJustPressed(1, 246) and IsDriver() then - Player = PlayerPedId() - TriggerCruiseControl() - end +RegisterCommand("cruise", function(src) + if IsDriver() then + TriggerCruiseControl() end end) -function TriggerCruiseControl () +RegisterKeyMapping("cruise", "Enable Cruise Control", Config.ToggleKey) + +function TriggerCruiseControl() if CruisedSpeed == 0 and IsDriving() then if GetVehicleSpeed() > 0 and GetVehicleCurrentGear(GetVehicle()) > 0 then CruisedSpeed = GetVehicleSpeed() @@ -20,7 +17,7 @@ function TriggerCruiseControl () ESX.ShowNotification(_U('activated') .. ': ~b~ ' .. CruisedSpeedKm .. ' km/h') CreateThread(function () - while CruisedSpeed > 0 and IsInVehicle() == Player do + while CruisedSpeed > 0 and IsInVehicle() == PlayerPedId() do Wait(0) if not IsTurningOrHandBraking() and GetVehicleSpeed() < (CruisedSpeed - 1.5) then @@ -56,11 +53,11 @@ function IsTurningOrHandBraking () end function IsDriving () - return IsPedInAnyVehicle(Player, false) + return IsPedInAnyVehicle(PlayerPedId(), false) end function GetVehicle () - return GetVehiclePedIsIn(Player, false) + return GetVehiclePedIsIn(PlayerPedId(), false) end function IsInVehicle () diff --git a/[esx_addons]/esx_cruisecontrol/config.lua b/[esx_addons]/esx_cruisecontrol/config.lua index 5290495d..c8214b09 100644 --- a/[esx_addons]/esx_cruisecontrol/config.lua +++ b/[esx_addons]/esx_cruisecontrol/config.lua @@ -1,2 +1,4 @@ Config = {} Config.Locale = 'en' + +Config.ToggleKey = "CAPITAL" diff --git a/[esx_addons]/esx_cruisecontrol/fxmanifest.lua b/[esx_addons]/esx_cruisecontrol/fxmanifest.lua index e4c06165..6ac911a4 100644 --- a/[esx_addons]/esx_cruisecontrol/fxmanifest.lua +++ b/[esx_addons]/esx_cruisecontrol/fxmanifest.lua @@ -13,12 +13,7 @@ dependencies { client_scripts { '@es_extended/imports.lua', '@es_extended/locale.lua', - 'locales/fi.lua', - 'locales/fr.lua', - 'locales/en.lua', - 'locales/es.lua', - 'locales/ge.lua', - 'locales/pl.lua', + 'locales/*.lua', 'client/main.lua', 'config.lua', }