Skip to content

Commit a30a731

Browse files
authored
Update reload_c.lua (#656)
- Adds a custom reload system that prevents reloading while performing certain actions (e.g., jumping, climbing, swimming, etc.). - Includes checks to avoid reload while inside a vehicle or if the ammo is already full. - Also adds a small random delay to prevent instant reload exploits.
1 parent 7772654 commit a30a731

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

[gameplay]/reload/reload_c.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
local reloadKey = "r"
2+
local reloadCmd = "reload"
3+
14
local blockedTasks = {
25
["TASK_SIMPLE_JUMP"] = true,
36
["TASK_SIMPLE_LAND"] = true,
@@ -14,19 +17,16 @@ local blockedTasks = {
1417
}
1518

1619
local function reloadTimer()
17-
if blockedTasks[getPedSimplestTask(localPlayer)] then
18-
return
19-
end
20-
20+
local task = getPedSimplestTask(localPlayer)
21+
if blockedTasks[task] then return end
22+
if isPedInVehicle(localPlayer) then return end
23+
if getPedAmmoInClip(localPlayer) == getPedTotalAmmo(localPlayer) then return end
2124
triggerServerEvent("relWep", localPlayer)
2225
end
2326

24-
-- The jump task is not instantly detectable and bindKey works quicker than getControlState
25-
-- If you try to reload and jump at the same time, you will be able to instant reload.
26-
-- We work around this by adding an unnoticable delay to foil this exploit.
27-
2827
local function reloadWeapon()
29-
setTimer(reloadTimer, 50, 1)
28+
setTimer(reloadTimer, math.random(50, 120), 1)
3029
end
31-
addCommandHandler("Reload weapon", reloadWeapon)
32-
bindKey("r", "down", "Reload weapon")
30+
31+
bindKey(reloadKey, "down", reloadCmd)
32+
addCommandHandler(reloadCmd, reloadWeapon)

0 commit comments

Comments
 (0)