Punching Delay

Hey! Is there a possible way to delay punching/melee attacking? To counter spam punch in FiveM, i know one way is to disable player locking entirely, but that would lose player-to-player somewhat fluid fights.

Hi! Here is code that should help you.

local meleeCooldown = false

local function startMeleeCooldown()
    if not meleeCooldown then
        meleeCooldown = true
        Citizen.CreateThread(function()
            while meleeCooldown do
                Citizen.Wait(0) -- Use Wait(0) inside loops that actively disable controls
                DisableControlAction(0, 140, true) -- R 
                DisableControlAction(0, 142, true) -- Left Mouse Button 
            end
        end)
        Citizen.SetTimeout(2000, function()
            meleeCooldown = false
        end)
    end
end


Citizen.CreateThread(function()
    while true do
        Citizen.Wait(200) 
        if IsPedInMeleeCombat(PlayerPedId()) and not meleeCooldown then
            startMeleeCooldown()
        end
    end
end)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.