Jump to content

[HELP]Script with timer


Recommended Posts

Posted

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.

Posted (edited)
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
Posted

The script loads fine,

start: Resource 'kitarmas' started 

but dont show

'You have to wait '.. timeToWaitFor..' second' 

or

'Syntex /kitarmas [weapon] [ammo]' 

and don't give anny gun ;s

I already put the weapon/ammo id.

Posted
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 
); 

Posted

@Blaawee i want to set the ids in a array, for example: arrayWeapon = { 8, 24, 28} / arrayAmmo = { 100, 200, 300} and unpack it on "getWeaponIDFromName( weapon )" and "tonumber( ammo )". But i don't know how.. Im new on lua

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