Skip to content

Commit

Permalink
optimize when loop is active
Browse files Browse the repository at this point in the history
Co-authored-by: Solareon <[email protected]>
  • Loading branch information
Manason and solareon authored Oct 25, 2024
1 parent c095b87 commit 86527cf
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,28 @@ local function onVehicleAttemptToEnter(vehicle)
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), lockState)
end

CreateThread(function()
while true do
if LocalPlayer.state.isLoggedIn then
local isLoggedIn = false

local function playerEnterVehLoop()
CreateThread(function()
while isLoggedIn do
local vehicle = GetVehiclePedIsTryingToEnter(cache.ped)
if vehicle ~= 0 then
onVehicleAttemptToEnter(vehicle)
end
Wait(100)
end
Wait(100)
end)
end

CreateThread(function()
if LocalPlayer.state.isLoggedIn then
playerEnterVehLoop()
end
end)

AddStateBagChangeHandler('isLoggedIn', ('player:%s'):format(cache.serverId), function(_, _, value)
isLoggedIn = value
if not value then return end
playerEnterVehLoop()
end)

0 comments on commit 86527cf

Please sign in to comment.