Jump to content

RPG Time Limiter


WiBox

Recommended Posts

rpgLimiter = {}
function shotCheck(weapon)
    if ( weapon == 35 or weapon == 36 ) then
        rpgLimiter[localPlayer] = true
        setTimer( function()
            rpgLimiter[localPlayer] = false
        end, 10000, 1)		
        toggleControl( "fire", false)
        toggleControl( "aim-wepaon", false)
    end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, shotCheck)

function disableRPGonSwitch( privSlot, newSlot)
    if ( ( ( getPedWeapon( localPlayer, newSlot) == 35 ) or ( getPedWeapon( localPlayer, newSlot) == 36 ) ) and ( rpgLimiter[localPlayer] == true ) ) then	
        toggleControl( "fire", false)
        toggleControl( "aim-wepaon", false)
    else
        toggleControl( "fire", true)
        toggleControl( "aim-wepaon", true)
    end    
end
addEventHandler("onClientPlayerWeaponSwitch", root, disableRPGonSwitch)

I'm trying to make a limit between each RPG shots, but for some reasons when I use "onClientRender" instead of "onClientPlayerWeaponSwitch" it works...

Link to comment
  • Moderators

Try this method 

 

rpgLimiter = {}


function projectileCreation( creator )
	local projectileType = getProjectileType( source )
	if projectileType == 19 or projectileType == 20 then
		if ( isTimer(rpgLimiter[localPlayer]) ) then 
			setElementPosition ( source,0,0,-500)
			destroyElement(source)
		else 
			rpgLimiter[localPlayer] = setTimer(function () end,10000,1)
		end 
	end
end
addEventHandler( "onClientProjectileCreation", getRootElement( ), projectileCreation )

 

Link to comment

I'm trying to make my scripts with no FPS drop, if I use many setTimers, won't it affect it?

On 19/01/2020 at 18:20, !#NssoR_) said:
  1. rpgLimiter = {}
  2.  
  3.  
  4. function projectileCreation( creator )
  5. local projectileType = getProjectileType( source )
  6. if projectileType == 19 or projectileType == 20 then
  7. if ( isTimer(rpgLimiter[localPlayer]) ) then
  8. setElementPosition ( source,0,0,-500)
  9. destroyElement(source)
  10. else
  11. rpgLimiter[localPlayer] = setTimer(function () end,10000,1)
  12. end
  13. end
  14. end
  15. addEventHandler( "onClientProjectileCreation", getRootElement( ), projectileCreation )

It worked, but isn't there a way so the player won't be able to aim with the weapon?

Link to comment
11 hours ago, WiBox said:

make my scripts with no FPS drop

You can create a timer after you switched to the RPG and remove it if you switched to another weapon

11 hours ago, WiBox said:

won't be able to aim

Use toggleControl("aim_weapon", false) on each onClientWeaponSwitch event triggering and allow to aim when the timer executes out (just insert toggleControl("aim_weapon", true) inside the timer)

Link to comment

Man it's not about the way of how I wrote is wrong, it's about the "toggleControl("aim_weapon", false) isn't working only if I used "onClientRender" or 'onClientPreRender". I've tried the way you said, but it's still the same I used "print' to make sure that it's arriving to the command "toggleControl("aim_weapon", false) but that command isn't triggering... the logic of the script I wrote isn't wrong:

rpgTimer = {}
function shotCheck(weapon)
    if ( weapon == 35 or weapon == 36 ) then
		rpgTimer[localPlayer] = setTimer( function()
			toggleControl( "fire", true)
			toggleControl( "aim_weapon", true)
		end, 60000, 1)	
		toggleControl( "fire", false)
		toggleControl( "aim_weapon", false)
	end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, shotCheck)

function disableRPGonSwitch( privSlot, newSlot)
	if ( ( ( getPedWeapon( localPlayer, newSlot) == 35 ) or ( getPedWeapon( localPlayer, newSlot) == 36 ) ) and ( isTimer(rpgTimer[localPlayer]) ) )then		
		toggleControl( "fire", false)
		toggleControl( "aim_weapon", false)
	else
		toggleControl( "fire", true)
		toggleControl( "aim_weapon", true)
    end    
end
addEventHandler("onClientPlayerWeaponSwitch", root, disableRPGonSwitch)

But still, and plus... Do you want to laugh?

function shotCheck(weapon)
    if ( weapon == 35 or weapon == 36 ) then
		toggleControl( "fire", false)
		toggleControl( "aim_weapon", false)
	end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, shotCheck)

I've tried it like that, it should disable Aiming and firing any type of weapon, ain't I right? It didn't stop anything, RPG neither the M4...

Also, I tried that way in Server-Side

rpgTimer = {}
function shotCheck(weapon)
		rpgTimer[source] = setTimer( function()
			toggleControl( source, "fire", false)
			toggleControl( source, "aim_weapon", false)
		end, 60000, 1)	
		toggleControl( source, "fire", false)
		toggleControl( source, "aim_weapon", false)
end
addEventHandler("onPlayerWeaponFire", root, shotCheck)

Nothing at all...

So, is there a special way if using this command "toggleControl", or it should've a time because I've detected something while using it, if you use it, the RPG stop firing for 0.3seconds, the weapon aiming goes back like you're aiming horizontally... I felt like I have to activate the "toggleControl" each 0.3seconds

It happend in this code:

rpgTimer = {}
function shotCheck(weapon)
    if ( weapon == 35 or weapon == 36 ) then
		rpgTimer[localPlayer] = setTimer( function()
			toggleControl( "fire", true)
			toggleControl( "aim_weapon", true)
		end, 60000, 1)	
		toggleControl( "fire", false)
		toggleControl( "aim_weapon", false)
	end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, shotCheck)

function disableRPGonSwitch( privSlot, newSlot)
	if ( ( ( getPedWeapon( localPlayer, newSlot) == 35 ) or ( getPedWeapon( localPlayer, newSlot) == 36 ) ) and ( isTimer(rpgTimer[localPlayer]) ) )then		
		toggleControl( "fire", false)
		toggleControl( "aim_weapon", false)
	else
		toggleControl( "fire", true)
		toggleControl( "aim_weapon", true)
    end    
end
addEventHandler("onClientPlayerWeaponSwitch", root, disableRPGonSwitch)

 

Link to comment

Nevermind, in another script that my friend added, he used once you enter a specific area you can't use your weapons and he used the event handler "onClientRender" so it seems while it was getting disable here, in my friend's script it re enable it... Thank you.

  • Like 1
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...