From fc43b7507814d435cfcf6cf3d3d0cbc25c94b908 Mon Sep 17 00:00:00 2001 From: rubin Date: Mon, 9 Jan 2023 19:50:09 +0300 Subject: [PATCH] cruise control add key stop - S/Space --- TruckHUD.lua | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/TruckHUD.lua b/TruckHUD.lua index 56e2b8b..7b78e44 100644 --- a/TruckHUD.lua +++ b/TruckHUD.lua @@ -1020,33 +1020,41 @@ function doPickup() end end +function check_press_key(table) + local result = false + local result_key_text = "" + for i = 1, #table do + if isKeyDown(vkeys[table[i]]) then + result = true + result_key_text = table[i]:gsub("VK_", "") + break + end + end + return result, result_key_text +end + +cruise = false function doCruise() if not inifiles.Settings.Cruise then return end - if cruise == nil then cruise = false end - if not isCharInAnyCar(playerPed) then + additional_key_stop = { "VK_W", "VK_S", "VK_SPACE" } + local car = storeCarCharIsInNoSave(playerPed) + if not isCharInAnyCar(playerPed) or not isCarEngineOn(car) then if cruise then cruise = false - printStringNow('~R~Cruise Control - OFF', 1500) + printStringNow('~R~cruise control - OFF', 1500) end return end - local car = storeCarCharIsInNoSave(playerPed) - if cruise and not isCarEngineOn(car) then - cruise = false - printStringNow('~R~Cruise Control - OFF', 1500) - return - end - if not sampIsChatInputActive( ) and not sampIsDialogActive( ) and not sampIsCursorActive( ) then - if pressW ~= nil and not isKeyDown(87) then - pressW = nil - end - if not cruise and isKeyDown(87) and isKeyDown(vkeys[inifiles.Settings.Key4]) and isCarEngineOn(car) and isCharInAnyCar(playerPed) then + if not sampIsChatInputActive() and not sampIsDialogActive() and not sampIsCursorActive() then + if not cruise and isKeyDown(vkeys["VK_W"]) and isKeyDown(vkeys[inifiles.Settings.Key4]) then + repeat + wait(100) + until not isKeyDown(vkeys["VK_W"]) cruise = true - pressW = true - printStringNow('~G~Cruise Control - ON', 1500) - elseif cruise and not isKeyDown(vkeys[inifiles.Settings.Key4]) and isKeyDown(87) and pressW == nil then + printStringNow('~G~cruise control - ON', 1500) + elseif cruise and not isKeyDown(vkeys[inifiles.Settings.Key4]) and select(1, check_press_key(additional_key_stop)) then cruise = false - printStringNow('~R~Cruise Control - OFF', 1500) + printStringNow('~R~cruise control - OFF', 1500) end end if cruise then