Jump to content

Ajuda setTimer


Recommended Posts

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 by Ragnar
Link to comment
  • Other Languages Moderators
  • 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)

 

  • Thanks 1
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...