Jump to content

[DÚVIDA|RESOLVIDO] Comando em tantos segundos


Recommended Posts

Galera, queria pegar o comando abaixo e fazer com que a cada 10 segundos todos os players usaram este comando.

Já tentei com: addEvent e addEventHandler mas não consegui fazer.

Comando (Server-side)

function Whistle(player, command) 
    if isPedInVehicle(player) then 
        if player ~= hunter then 
            if whistles[player] == nil then 
                local blip = createBlipAttachedTo(player, 0, 2, 0, 255, 0) 
                setTimer(destroyElement, 5000, 1, blip) 
                triggerClientEvent("playWhistle", player) 
                outputChatBox("[WHISTLE] "..getPlayerName(player).." #ffffffhas whistled!", root, 255, 255, 255, true) 
                 
                whistles[player] = true 
                whistlesTime[player] = setTimer(function() whistles[player] = nil end, 15000, 1) 
            else 
                local remaining, executesRemaining, totalExecutes = getTimerDetails(whistlesTime[player]) 
                outputChatBox("[WHISTLE] You need to wait "..math.floor(remaining/1000).." more seconds!", player, 255, 255, 255, true) 
            end 
        end 
    end 
end 
addCommandHandler("whistle", Whistle) 

Edited by Guest
Link to comment
Não entendi oque você quer exatamente, Adicionar um delay para o jogador poder digitar o comando novamente ou fazer todos os jogadores digitarem o comando ?

Não... queria que tipo, depois de 10 segundos todos os jogadores utilizem o comando.

Acredito eu que usaria:

ExecuteCommandHandler

SetTimer

Eu fiz isso, porém não sei que argumento usar....

function ForceCommand(xxxx) 
    executeCommandHandler("apitar", xxx) 
end 
setTimer(ForceCommand, 10000, 0) 

Link to comment
[...]
function ForceCommand(xxxx) 
    executeCommandHandler("apitar", xxx) 
end 
setTimer(ForceCommand, 10000, 0) 

Como você não tem a variável de um jogador você tem que fazer um loop com todos os jogadores e executar o comando para cada um deles.

function ForceCommand() 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        executeCommandHandler( "apitar", player ); 
    end 
end 
  
setTimer(ForceCommand, 10000, 0) 

Porem é mais eficiente executar a função logo em vez de 'chamar' o comando.

function ForceCommand() 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        Whistle(player); -- peguei Whistle do seu primeiro post, troque se desejar outra função. 
    end 
end 
  
setTimer(ForceCommand, 10000, 0) 

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