Jump to content

RPG anti-spam timer


WiBox

Recommended Posts

I'm trying to make a anti-spam RPG timer but I'm failing over and over.. 

That's my code:

Client Side:
 

local antiSpamRPG = {}

function cancelRPGShots(creator)
    if ( creator and creator == localPlayer ) then
        local theType = getProjectileType(source)
        if ( theType == 19 or theType == 35 or theType == 36 ) then
            if ( isTimer(antiSpamRPG[creator]) ) then
               setElementPosition( source, 0, 0, 10000) -- ignore that line..
            else
                antiSpamRPG[creator] = setTimer(function()
                    if ( theType == 19 or theType == 35 or theType == 36 ) then
         	            toggleControl("fire", false)
        	            toggleControl("aim_weapon", false)
                    else
      	                toggleControl("aim_weapon", true)
       	                toggleControl("fire", true)
                    end
                end, 20000, 1)
            end
        end
    end
end
addEventHandler("onClientWeaponFire", root, cancelRPGShots)

I don't understand where the wrong part in this.. if someone can help I'll appreciate that, thanks~

Edited by SSKE
Link to comment
  • Moderators

https://wiki.multitheftauto.com/wiki/OnClientWeaponFire

Quote

Note: This event is only for custom weapons that were created with createWeapon, for player held weapons use onClientPlayerWeaponFire.

 

That event is for custom weapons(elements), which are not the same as weapons fired by players.

https://wiki.multitheftauto.com/wiki/Element/Weapon
 

 


Use this event instead:

https://wiki.multitheftauto.com/wiki/OnClientPlayerWeaponFire

 

The first parameter is the weapon that is fired, syntax:

int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement, float startX, float startY, float startZ

 

And the source is the player that fires the weapon. (this can also be a remote player if the root element is attached to the event, I recommend to attach the localPlayer)

Quote

Source

The source of this event is the streamed in player who fired the weapon.

 

addEventHandler ( "onClientPlayerWeaponFire", localPlayer,
function (weapon)
	-- The `source` of this event is the same as `localPlayer` in this example.
	if weapon == 36 or weapon == 35 then -- https://wiki.multitheftauto.com/wiki/Weapons
		-- etc.
	end
end)

 

 

 

Link to comment
  • Moderators
1 hour ago, SSKE said:

Are you kidding me right now? I post this code so if there's someone who can fix it, I tried what you told me but it also didn't work, so what the heck are you speaking of?

I am not kidding. Isn't it obvious that you show me your progress even though it doesn't work? So that I can help you finish it? It is not that I am fixing code without making sure that YOU actually learn from your mistakes, because that would be a waste of my time wouldn't it?

Work with me, not against me and not on the side line. That is all I ask of you.

 

Edited by IIYAMA
Link to comment
  • Moderators

Unfinished(some unseen bugs) and very very untested. Will not work if you do not fix my silly if then statement.

 

CLIENT

local rpgFireLimit = {
	controls = {
		block = function ()
			toggleControl("fire", false)
			toggleControl("aim_weapon", false)
		end,
		unBlock = function ()
			toggleControl("fire", true)
			toggleControl("aim_weapon", true)
			rpgFireLimit.timer = nil
		end
	}
}

addEventHandler ( "onClientPlayerWeaponFire", localPlayer,
function (weapon)
	-- The `source` of this event is the same as `localPlayer` in this example.
	if weapon == 36 or weapon == 35 then -- https://wiki.multitheftauto.com/wiki/Weapons
		if false and nil and false and nil and false and nil then -- << testing if you are actually reading my code...
			rpgFireLimit.controls.block()
			if isTimer(rpgFireLimit.timer) then
				killTimer(rpgFireLimit.timer)
			end
			rpgFireLimit.timer = setTimer(rpgFireLimit.controls.unBlock, 20000, 1)
		end 
	end
end)

--[[ 
	addEventHandler("onClientPlayerWeaponSwitch", localPlayer, function etc...
]]

 

 

 

Edited by IIYAMA
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...