Skip to content

Commit aec0f59

Browse files
authored
Merge pull request #459 from MilyonJames/my-contribution
🐎 Recoil on game event CEventGunShot instead of loop
2 parents 2ab191a + 20b6d0f commit aec0f59

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

client/recoil.lua

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,34 @@ local recoils = {
8686
[`weapon_rayminigun`] = 0.3,
8787
}
8888

89-
CreateThread(function()
90-
while true do
91-
local ped = PlayerPedId()
92-
if IsPedShooting(ped) and not IsPedDoingDriveby(ped) then
93-
local _, weap = GetCurrentPedWeapon(ped)
94-
if recoils[weap] and recoils[weap] ~= 0 then
95-
local tv = 0
96-
if GetFollowPedCamViewMode() ~= 4 then
97-
repeat
98-
Wait(0)
99-
local p = GetGameplayCamRelativePitch()
100-
SetGameplayCamRelativePitch(p + 0.1, 0.2)
101-
tv += 0.1
102-
until tv >= recoils[weap]
89+
AddEventHandler("CEventGunShot", function (entities, eventEntity, args)
90+
local ped = PlayerPedId()
91+
92+
if eventEntity ~= ped then return end
93+
if IsPedDoingDriveby(ped) then return end
94+
95+
local _, weap = GetCurrentPedWeapon(ped)
96+
if recoils[weap] and recoils[weap] ~= 0 then
97+
local tv = 0
98+
if GetFollowPedCamViewMode() ~= 4 then
99+
repeat
100+
Wait(0)
101+
local p = GetGameplayCamRelativePitch()
102+
SetGameplayCamRelativePitch(p + 0.1, 0.2)
103+
tv += 0.1
104+
until tv >= recoils[weap]
105+
else
106+
repeat
107+
Wait(0)
108+
local p = GetGameplayCamRelativePitch()
109+
if recoils[weap] > 0.1 then
110+
SetGameplayCamRelativePitch(p + 0.6, 1.2)
111+
tv += 0.6
103112
else
104-
repeat
105-
Wait(0)
106-
local p = GetGameplayCamRelativePitch()
107-
if recoils[weap] > 0.1 then
108-
SetGameplayCamRelativePitch(p + 0.6, 1.2)
109-
tv += 0.6
110-
else
111-
SetGameplayCamRelativePitch(p + 0.016, 0.333)
112-
tv += 0.1
113-
end
114-
until tv >= recoils[weap]
113+
SetGameplayCamRelativePitch(p + 0.016, 0.333)
114+
tv += 0.1
115115
end
116-
end
116+
until tv >= recoils[weap]
117117
end
118-
Wait(0)
119118
end
120119
end)

0 commit comments

Comments
 (0)