From 2bacdd2a2038263f2476e008f28b416c899d7c03 Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Tue, 16 Jan 2024 23:31:12 +0100 Subject: [PATCH] fix(client/vehicle): vehicle keys issues --- client/main.lua | 3 ++- client/vehicle/main.lua | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/client/main.lua b/client/main.lua index 6dafd98..3ab6aae 100644 --- a/client/main.lua +++ b/client/main.lua @@ -10,8 +10,9 @@ Config = { discordActionLink = GetConvar("discordActionLink", "https://discord.gg/Z9Mxu72zZ6"), discordActionText2 = GetConvar("core:discordActionText2", "STORE"), discordActionLink2 = GetConvar("core:discordActionLink2", "https://andyyy.tebex.io/category/fivem-scripts"), - randomUnlockedVehicleChance = GetConvarInt("core:randomUnlockedVehicleChance", 30), disableVehicleAirControl = GetConvarInt("core:disableVehicleAirControl", 1) == 1, + randomUnlockedVehicleChance = GetConvarInt("core:randomUnlockedVehicleChance", 30), + requireKeys = GetConvarInt("core:requireKeys", 1) == 1, useInventoryForKeys = GetConvarInt("core:useInventoryForKeys", 1) == 1, groups = json.decode(GetConvar("core:groups", "[]")), compatibility = json.decode(GetConvar("core:compatibility", "[]")) diff --git a/client/vehicle/main.lua b/client/vehicle/main.lua index 0aa2b41..9938901 100644 --- a/client/vehicle/main.lua +++ b/client/vehicle/main.lua @@ -480,22 +480,35 @@ CreateThread(function() local wait = 500 while true do Wait(wait) + + local reset = true playerVehicle = cache.seat == -1 and cache.vehicle - if playerVehicle then - if Config.disableVehicleAirControl and not vehicleClassNotDisableAirControl[GetVehicleClass(playerVehicle)] and (IsEntityInAir(playerVehicle) or IsEntityUpsidedown(playerVehicle)) then - wait = 0 - DisableControlAction(0, 59) -- disable vehicle air control. - DisableControlAction(0, 60) - elseif not GetIsVehicleEngineRunning(playerVehicle) and not hasVehicleKeysCheck(playerVehicle) then - wait = 0 - DisableControlAction(0, 59) - if DoesEntityExist(playerVehicle) and IsVehicleEngineStarting(playerVehicle) then - SetVehicleEngineOn(playerVehicle, false, true, true) -- don't turn on engine if no keys. - end - else - wait = 500 + + local entering = GetVehiclePedIsEntering(cache.ped) + if entering and DoesEntityExist(entering) and IsVehicleNeedsToBeHotwired(entering) then + SetVehicleNeedsToBeHotwired(entering, false) + end + + if not playerVehicle then goto skip end + + if Config.disableVehicleAirControl and not vehicleClassNotDisableAirControl[GetVehicleClass(playerVehicle)] and (IsEntityInAir(playerVehicle) or IsEntityUpsidedown(playerVehicle)) then + wait = 0 + reset = false + DisableControlAction(0, 59) -- disable vehicle air control. + DisableControlAction(0, 60) + end + if Config.requireKeys and not GetIsVehicleEngineRunning(playerVehicle) and not hasVehicleKeysCheck(playerVehicle) then + wait = 0 + reset = false + DisableControlAction(0, 59) + DisableControlAction(0, 71) + if DoesEntityExist(playerVehicle) and IsVehicleEngineStarting(playerVehicle) then + SetVehicleEngineOn(playerVehicle, false, true, true) -- don't turn on engine if no keys. end - elseif wait ~= 500 then + end + + ::skip:: + if (reset or not playerVehicle) and wait ~= 500 then wait = 500 end end