diff --git a/[gameplay]/reload/reload_c.lua b/[gameplay]/reload/reload_c.lua index fd2d45396..a8933f570 100644 --- a/[gameplay]/reload/reload_c.lua +++ b/[gameplay]/reload/reload_c.lua @@ -1,3 +1,6 @@ +local reloadKey = "r" +local reloadCmd = "reload" + local blockedTasks = { ["TASK_SIMPLE_JUMP"] = true, ["TASK_SIMPLE_LAND"] = true, @@ -14,19 +17,16 @@ local blockedTasks = { } local function reloadTimer() - if blockedTasks[getPedSimplestTask(localPlayer)] then - return - end - + local task = getPedSimplestTask(localPlayer) + if blockedTasks[task] then return end + if isPedInVehicle(localPlayer) then return end + if getPedAmmoInClip(localPlayer) == getPedTotalAmmo(localPlayer) then return end triggerServerEvent("relWep", localPlayer) end --- The jump task is not instantly detectable and bindKey works quicker than getControlState --- If you try to reload and jump at the same time, you will be able to instant reload. --- We work around this by adding an unnoticable delay to foil this exploit. - local function reloadWeapon() - setTimer(reloadTimer, 50, 1) + setTimer(reloadTimer, math.random(50, 120), 1) end -addCommandHandler("Reload weapon", reloadWeapon) -bindKey("r", "down", "Reload weapon") \ No newline at end of file + +bindKey(reloadKey, "down", reloadCmd) +addCommandHandler(reloadCmd, reloadWeapon)