Ragnar Posted August 8, 2019 Share Posted August 8, 2019 (edited) Olá, Como faço pra colocar tempo ao comprar vidar juntamente com mensagem de erro, caso o Jogador tente comprar vida 2 vezes seguidas antes de 30 segundos? Se ele tentou compra vida novamente antes dos 30 segundos, então: outputChatBox("[ERRO]: Espere 30 segundos para comprar vida novamente!",thePlayer, 255, 0, 0) Code: function buyhealth ( thePlayer ) local money = getPlayerMoney ( thePlayer ) if money >= 250 then outputChatBox ('* ' .. getPlayerName(thePlayer) .. ':#696969 Vᴏᴄᴇ ᴄᴏᴍᴘʀᴏᴜ [#00FF00/ᴠɪᴅᴀ#696969] Pᴏʀ: #00FF00R$: 5000', thePlayer, 255, 0, 0, true) local thePlayerhealth = getElementHealth ( thePlayer ) setElementHealth ( thePlayer, 569 ) takePlayerMoney ( thePlayer, 5000 ) else outputChatBox("A Vida Custa 5000$!",thePlayer, 255, 0, 0) end end addCommandHandler ( "vida", buyhealth ) Edited August 8, 2019 by Ragnar Link to comment
Other Languages Moderators Lord Henry Posted August 8, 2019 Other Languages Moderators Share Posted August 8, 2019 Crie uma table vazia fora da função. Ela será usada para armazenar os timers de cada jogador. Cada jogador terá seu próprio timer. Na função, verifica se existe o timer indexado no jogador que executou o comando. Se existir, mostra mensagem de erro. Se não existir, cria o timer e dá a vida normalmente. Quando o timer terminar, anule a variável dele na table. Quando o jogador sair do server, anule a variável dele na table. local timers = {} function buyhealth (thePlayer) if (isTimer (timers[thePlayer])) then -- Se existe o timer desse jogador, então: outputChatBox ("[ERRO]: Espere 30 segundos para comprar vida novamente!", thePlayer, 255, 0, 0) -- Envia isso pra ele e nada acontece. else -- Se não tiver o timer desse jogador, então: timers[thePlayer] = setTimer (function () -- Cria o timer, que dura 30 segundos. timers[thePlayer] = nil -- Depois que terminar o timer, anula a variável do timer. end, 30000, 1) local money = getPlayerMoney (thePlayer) if (money >= 250) then outputChatBox ("* "..getPlayerName (thePlayer)..":#696969 Vᴏᴄᴇ ᴄᴏᴍᴘʀᴏᴜ [#00FF00/ᴠɪᴅᴀ#696969] Pᴏʀ: #00FF00R$: 5000", thePlayer, 255, 0, 0, true) local thePlayerhealth = getElementHealth (thePlayer) setElementHealth (thePlayer, 569) takePlayerMoney (thePlayer, 5000) else outputChatBox ("A vida custa $5000!", thePlayer, 255, 0, 0) end end end addCommandHandler ("vida", buyhealth) 1 Link to comment
Ragnar Posted August 8, 2019 Author Share Posted August 8, 2019 Passei longe da forma que tentei Obrigado @Lord Henry Link to comment
Other Languages Moderators Lord Henry Posted August 8, 2019 Other Languages Moderators Share Posted August 8, 2019 Não se esqueça disso: addEventHandler ("onPlayerQuit", root, function () if (isTimer(timers[source])) then killTimer (timers[source]) timers[source] = nil end end) 1 Link to comment
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