MTS_LoneWolf Posted November 2, 2021 Posted November 2, 2021 (edited) function DelayMessage(player) outputChatBox ("Instant text!") setTimer ( function() outputChatBox ( "5 second delay text!") end, 5000, 2 ) setTimer ( function() outputChatBox ( "Final text") end, 10001, 1 ) end addCommandHandler("msg", DeleyMessage) Existe alguma forma de cancelar a função DelayMessage antes de que ela enviasse toda as mensagens? usando alguma outra function function stopmsg() pararevento"delayMessage" end addCommandHandler("parar",stopmsg) Edited November 2, 2021 by MTS_LoneWolf
Moderators Lord Henry Posted November 4, 2021 Moderators Posted November 4, 2021 (edited) Coloque os timers dentro de variáveis e então vc pode usar killTimer nas variáveis. local TheTimers = {} -- Tabela vazia, onde ficarão os timers. function DelayMessage(thePlayer) outputChatBox ("Instant text!") TheTimers[1] = setTimer(function() -- Cria o primeiro timer e coloca ele na 1 posição da tabela. outputChatBox("5 seconds delay text!") end, 5000, 2) TheTimers[2] = setTimer(function() -- Cria o segundo timer e coloca ele na 2 posição da tabela. outputChatBox("Final text") end, 10001, 1) end addCommandHandler("msg", DelayMessage) addCommandHandler("parar", StopMsg() for i,v in pairs (TheTimers) do -- Para cada item da tabela TheTimers, faça: if (isTimer(v)) then -- Se o item é um timer ativo, então: killTimer(v) -- Cancela esse timer. TheTimers[i] = nil -- Anula a variável dele para desocupar memória. end end end) Edited November 4, 2021 by Lord Henry Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now