Skip to content

Commit

Permalink
refactor(recoils): remove endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon committed Jul 10, 2024
1 parent d8c0dfd commit ce85159
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions qbx_recoils/client.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
local recoils = require 'qbx_recoils.config'

CreateThread(function()
while true do
if IsPedShooting(cache.ped) and not IsPedDoingDriveby(cache.ped) then
local _, wep = GetCurrentPedWeapon(cache.ped, true)
if recoils[wep] and recoils[wep] ~= 0 then
-- luacheck: ignore
local tv = 0
if GetFollowPedCamViewMode() ~= 4 then
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
SetGameplayCamRelativePitch(p + 0.1, 0.2)
tv += 0.1
until tv >= recoils[wep]
else
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
if recoils[wep] > 0.1 then
SetGameplayCamRelativePitch(p + 0.6, 1.2)
tv += 0.6
else
SetGameplayCamRelativePitch(p + 0.016, 0.333)
local function recoilLoop()
CreateThread(function()
while cache.weapon do
if IsPedShooting(cache.ped) and not IsPedDoingDriveby(cache.ped) then
local _, wep = GetCurrentPedWeapon(cache.ped, true)
if recoils[wep] and recoils[wep] ~= 0 then
-- luacheck: ignore
local tv = 0
if GetFollowPedCamViewMode() ~= 4 then
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
SetGameplayCamRelativePitch(p + 0.1, 0.2)
tv += 0.1
end
until tv >= recoils[wep]
until tv >= recoils[wep]
else
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
if recoils[wep] > 0.1 then
SetGameplayCamRelativePitch(p + 0.6, 1.2)
tv += 0.6
else
SetGameplayCamRelativePitch(p + 0.016, 0.333)
tv += 0.1
end
until tv >= recoils[wep]
end
end
end
Wait(350) -- might be able to reduce time here for more recoil
end
Wait(350)
end
end)
end)
end

lib.onCache('weapon', function(weapon)
Wait(5)
if not weapon then return end
recoilLoop()
end)

0 comments on commit ce85159

Please sign in to comment.