-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(recoils): remove endless loop
- Loading branch information
Showing
1 changed file
with
36 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |