From 75602a7e489ebb6334c189d4d62374ec4789ce10 Mon Sep 17 00:00:00 2001 From: xerenon <44570681+xerenon@users.noreply.github.com> Date: Sun, 14 Mar 2021 07:32:20 +0700 Subject: [PATCH] Fix Cruise Control So we are getting wrong about cruise control. We though it is a speed limit function but it not. Now we are will merge this pull request to main branch. Thanks for @xerenon for contribute with project. --- client/main.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/main.lua b/client/main.lua index a12fb12..9cf2cae 100644 --- a/client/main.lua +++ b/client/main.lua @@ -10,6 +10,9 @@ local vehData = { prevVelocity = {x = 0.0, y = 0.0, z = 0.0}, }; +local inair = 0 +local cruiseSpeeding = 0 + local playerPed = nil; -- Thread Citizen.CreateThread(function() @@ -103,10 +106,29 @@ Citizen.CreateThread(function() cruiseEnabled = not cruiseEnabled; triggerNUI("toggleCruise", { hasCruise = isDriver, cruiseStatus = cruiseEnabled }); vehData['cruiseSpd'] = vehData['currSpd']; + cruiseSpeeding = vehData['cruiseSpd']; end local maxSpeed = cruiseEnabled and vehData['cruiseSpd'] or GetVehicleHandlingFloat(currVeh,"CHandlingData","fInitialDriveMaxFlatVel"); SetEntityMaxSpeed(currVeh, maxSpeed); + + local roll = GetEntityRoll(currVeh) + + + if cruiseEnabled and not IsEntityInAir(currVeh) and inair >= 100 and not (roll > 75.0 or roll < -75.0) then + if cruiseSpeeding < maxSpeed then + cruiseSpeeding = cruiseSpeeding + 0.15 + end + + + SetVehicleForwardSpeed(currVeh, cruiseSpeeding) + + elseif cruiseEnabled and not IsEntityInAir(currVeh) then + inair = inair + 1 + cruiseSpeeding = vehData['currSpd']; + elseif cruiseEnabled then + inair = 0 + end else cruiseEnabled = false; end