Jump to content

Comando com tempo para usar


Recommended Posts

Olá. Gostaria de pedir a ajuda de vocês para criar um comando que tenha tempo para usar. Ex: o player digita "/comando" e só pode usar o comando novamente depois de 1 minuto.

No caso gostaria pra dar alguns items como:

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

Link to comment
  • Moderators

Como dito por manawydan, você pode usar a função setTimer e uma variável para definir um valor booleano que irá permitir/negar o uso do comando.

Use uma tabela para definir a boolean para para permitir o uso de cada jogador, se for variável irá afetar todos os jogadores.

Além disso, o seu código não vai funcionar porque tem erros.

local kitarmasCommand = {} 
local tempo = 60000 
  
addCommandHandler("kitarmas",  
function(source) 
    if (kitarmasCommand[source] and kitarmasCommand[source] == false) then 
        outputChatBox("Aguarde 1 minuto para usar este comando novamente", source, 225, 0, 0) 
        return 
    end 
    giveWeapon(source, 4, 200, true) 
    giveWeapon(source, 24, 200, true) 
     
    setTimer( function() 
        kitarmasCommand[source] = false 
    end, tempo, 1 
    ) 
end 
) 
  
addEventHandler("onPlayerQuit", root,  
function() 
    if kitarmasCommand[source] then 
        kitarmasCommand[source] = nil 
    end 
end 
) 

Edited by Guest
Link to comment

Tenta esse

local kitarmasCommand = { } 
local tempo = 60000 
  
addCommandHandler ( "kitarmas", 
    function ( source ) 
        if ( kitarmasCommand [ source ] ) then 
            return outputChatBox ( "Aguarde 1 minuto para usar este comando novamente", source, 225, 0, 0 ) 
        end 
        giveWeapon ( source, 4, 200, true ) 
        giveWeapon ( source, 24, 200, true ) 
        kitarmasCommand [ source ] = true 
        setTimer (  
            function ( ) 
                kitarmasCommand [ source ] = false 
            end 
        , tempo, 1 
        ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        if ( kitarmasCommand [ source ] ) then 
            kitarmasCommand [ source ] = nil 
        end 
    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...