Jump to content

[HELP]Script with timer


Recommended Posts

Hello, i need help to create a script with time to use. If i use the command "/command" i have to wait "x" seconds to use it again. Ex:

  
addCommandHandler("kitarmas", true) 
  giveWeapon(source, 4, 200, true) 
  giveWeapon(source, 24, 200, true) 
end 
  

Thx and sorry for my bad english.

Link to comment
local status = { }; 
local timeToWaitFor = 5; 
  
addCommandHandler( 'kitarmas', 
    function( player, _, weapon, ammo ) 
        if status[ player ] then 
            return outputChatBox( 'You have to wait '.. timeToWaitFor..' second', player, 255, 0, 0, true ); 
        end 
        if not weapon and not ammo then 
            return outputChatBox( 'Syntex /kitarmas [weapon] [ammo]', player, 255, 0, 0, true ); 
        end 
        giveWeapon( player, tonumber( weapon ), tonumber( ammo ), true ); 
        status[ player ] = true; 
        setTimer( 
            function( ) 
                status[ player ] = false 
            end,     
        timeToWaitFor * 1000, 1 ) 
    end 
); 

Edited by Guest
Link to comment
local status = { }; 
local timeToWaitFor = 5; 
  
addCommandHandler( 'kitarmas', 
    function( player, _, weapon, ammo ) 
        if status[ player ] then 
            return outputChatBox( 'You have to wait '.. timeToWaitFor..' second', player, 255, 0, 0, true ); 
        end 
        if not weapon and not ammo then 
            return outputChatBox( 'Syntex /kitarmas [weapon] [ammo]', player, 255, 0, 0, true ); 
        end 
        giveWeapon( player, getWeaponIDFromName( weapon ), tonumber( ammo ), true ); 
        outputChatBox ( 'You got a ' .. getWeaponIDFromName( weapon ), player, 0, 255, 0, true ); 
        status[ player ] = true; 
        setTimer( 
            function( ) 
                status[ player ] = false 
            end,     
        timeToWaitFor * 1000, 1 ) 
    end 
); 

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...