Skip to content

Update reload_c.lua #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions [gameplay]/reload/reload_c.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local reloadKey = "r"
local reloadCmd = "reload"

local blockedTasks = {
["TASK_SIMPLE_JUMP"] = true,
["TASK_SIMPLE_LAND"] = true,
Expand All @@ -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")

bindKey(reloadKey, "down", reloadCmd)
addCommandHandler(reloadCmd, reloadWeapon)