Jump to content

RPGs anti Spam


Chris!i!

Recommended Posts

antiSpam = {}
function antiSpamRPG(thePlayer)
    if isTimer(antiSpam[thePlayer]) then 
    local slot = getPedWeaponSlot(thePlayer)
    if (slot == 7) then
    toggleControl(thePlayer, "aim_weapon", false)
    toggleControl(thePlayer, "fire", false)
        cancelEvent() 
else
antiSpam[thePlayer] = setTimer(function(thePlayer) antiSpam[thePlayer] = nil end, 7000, 1, thePlayer)
toggleControl(thePlayer, "aim_weapon", true)
toggleControl(thePlayer, "fire", true)
end
end
end
addEventHandler("onPlayerWeaponFire", getRootElement(), antiSpamRPG)

first function works, but the second one the player keeps firing RPGs no limit...

Link to comment

You don't really need to do that server side, you can achieve the same thing client side, which in my opinion much better.

 

local cdTimer

function antiSpamRPG(weap)
   	if isTimer(cdTimer) then
		return
	end
	
	local slot = getPedWeaponSlot(localPlayer)
	if (slot == 7) then
		toggleControl("aim_weapon", false)
		toggleControl("fire", false)
		
		cdTimer = setTimer( function()
			toggleControl("aim_weapon", true)
			toggleControl("fire", true)
		end, 7000, 1 )
	end

end
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), antiSpamRPG)

 

Link to comment
function antiSpamRPG(weapon)
    if isTimer(cdTimer) then return end
    if (weapon == 35) then
        toggleControl("aim_weapon", false)
        toggleControl("fire", false)
        cdTimer = setTimer( function()
            toggleControl("aim_weapon", true)
            toggleControl("fire", true)
        end, 7000, 1 )
    end
end
addEventHandler("onClientPlayerWeaponFire",localPlayer, antiSpamRPG)

 

Edited by Walid
Link to comment
cdTimer = {}
function antiSpamRPG(weapon)
    if isTimer(cdTimer[localPlayer]) then return end
    if (weapon == 35) then
        toggleControl("aim_weapon", false)
        toggleControl("fire", false)
        cdTimer[localPlayer] = setTimer( function()
            toggleControl("aim_weapon", true)
            toggleControl("fire", true)
        	killTimer(cdTimer[localPlayer])
        end, 7000, 1 )
    end
end
addEventHandler("onClientPlayerWeaponFire",localPlayer, antiSpamRPG)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...