Jump to content

Timer Help


Recommended Posts

Hey, how can i add timer to command handler ?? im using this script and i want to add timer, so player can use /spin once in every 10 minutes

Spoiler

function spincoin(player, cmd, ...)
	local text = table.concat({...}, " ")
	if not ...  then
    	outputChatBox("#2BFF00[Spin Coin]: #FFFFFFYour Spin is Ready use #2BFF00/Spin [money]#FFFFFFto Test your luck", player, 255, 255, 255, true)
	return end
        if tonumber(text) < 1 then
    	outputChatBox("#2BFF00[Spin Coin]: #FFFFFFuse /Spin ( 1 - "..max_spin.." )", player, 255, 255, 255, true)
	return end
	if tonumber(text) > max_spin then 
    	outputChatBox("#2BFF00[Spin Coin]: #FFFFFFSorry, you cannot Spin Money more than #FF000010000 "..max_spin.."!", player, 255, 255, 255, true)
    	outputChatBox(tonumber(text), player, 255, 255, 255, true)
	return end
	if getPlayerMoney(player) < tonumber(text) then
    	outputChatBox("#2BFF00[Spin Coin]: #FFFFFFSorry, You don´t have enough money!", player, 255, 255, 255, true)
		return	
	else
    	coin = math.random(1, 2)
    	if coin == 1 then 
        	outputChatBox("#2BFF00[Spin Coin]: #FF0000"..getPlayerName(player).." #ffffffhas spinned the coin and won #2BFF00+"..tonumber(text).."$ !", player, 255, 255, 255, true)
        	givePlayerMoney(player, tonumber(text))
        elseif coin == 2 then
        	outputChatBox("#2BFF00[Spin Coin]: #FF0000"..getPlayerName(player).." #ffffffhas spinned the coin and lost #FF0000-"..tonumber(text).."$ !", player, 255, 255, 255, true)
        	takePlayerMoney(player, tonumber(text))
    	end	
	end    	
end
addCommandHandler("spin", spincoin)

i mean, when player do /spin he can only /spin again after 10 minutes..

and when 10 minutes finishes, it should indicate player on OutputChatBox like "Your Spin is Ready do /spin to Test your Luck" .

Any help ? :/

 

Link to comment
  • Administrators
local spinTimer

function spincoin(player, cmd, ...)
	if not isTimer(spinTimer) then
		spinTimer = setTimer(function()
			outputChatBox("[Spin Coin]: Your spin is ready! Do /spin to test your luck", player)
			spinTimer = nil
		end, 600000, 1)
		
		local text = table.concat({...}, " ")
		if not ...  then
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFYour Spin is Ready use #2BFF00/Spin [money]#FFFFFFto Test your luck", player, 255, 255, 255, true)
		return end
			if tonumber(text) < 1 then
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFuse /Spin ( 1 - "..max_spin.." )", player, 255, 255, 255, true)
		return end
		if tonumber(text) > max_spin then 
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFSorry, you cannot Spin Money more than #FF000010000 "..max_spin.."!", player, 255, 255, 255, true)
			outputChatBox(tonumber(text), player, 255, 255, 255, true)
		return end
		if getPlayerMoney(player) < tonumber(text) then
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFSorry, You don´t have enough money!", player, 255, 255, 255, true)
			return	
		else
			coin = math.random(1, 2)
			if coin == 1 then 
				outputChatBox("#2BFF00[Spin Coin]: #FF0000"..getPlayerName(player).." #ffffffhas spinned the coin and won #2BFF00+"..tonumber(text).."$ !", player, 255, 255, 255, true)
				givePlayerMoney(player, tonumber(text))
			elseif coin == 2 then
				outputChatBox("#2BFF00[Spin Coin]: #FF0000"..getPlayerName(player).." #ffffffhas spinned the coin and lost #FF0000-"..tonumber(text).."$ !", player, 255, 255, 255, true)
				takePlayerMoney(player, tonumber(text))
			end	
		end    	
	else
		outputChatBox("You already used /spin in the past 10 minutes!", player)
	end
end
addCommandHandler("spin", spincoin)

 

Edited by LopSided_
Link to comment
  • Administrators
29 minutes ago, koragg said:

@LopSided_ so that timer will be set only for the player who executed the command? I thought that if i do it like that it will be set for all players since it's server side O.o If it's set just for the player who uses the command I've got some edits to do on my scripts :)

Goddamn. Remind me not to post stuff when I'm half asleep.

local spinTimer = {}

function spincoin(player, cmd, ...)
	if not isTimer(spinTimer[player]) then
		spinTimer[player] = setTimer(function()
			outputChatBox("[Spin Coin]: Your spin is ready! Do /spin to test your luck", player)
			spinTimer[player] = nil
		end, 600000, 1)
		
		local text = table.concat({...}, " ")
		if not ...  then
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFYour Spin is Ready use #2BFF00/Spin [money]#FFFFFFto Test your luck", player, 255, 255, 255, true)
		return end
			if tonumber(text) < 1 then
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFuse /Spin ( 1 - "..max_spin.." )", player, 255, 255, 255, true)
		return end
		if tonumber(text) > max_spin then 
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFSorry, you cannot Spin Money more than #FF000010000 "..max_spin.."!", player, 255, 255, 255, true)
			outputChatBox(tonumber(text), player, 255, 255, 255, true)
		return end
		if getPlayerMoney(player) < tonumber(text) then
			outputChatBox("#2BFF00[Spin Coin]: #FFFFFFSorry, You don´t have enough money!", player, 255, 255, 255, true)
			return	
		else
			coin = math.random(1, 2)
			if coin == 1 then 
				outputChatBox("#2BFF00[Spin Coin]: #FF0000"..getPlayerName(player).." #ffffffhas spinned the coin and won #2BFF00+"..tonumber(text).."$ !", player, 255, 255, 255, true)
				givePlayerMoney(player, tonumber(text))
			elseif coin == 2 then
				outputChatBox("#2BFF00[Spin Coin]: #FF0000"..getPlayerName(player).." #ffffffhas spinned the coin and lost #FF0000-"..tonumber(text).."$ !", player, 255, 255, 255, true)
				takePlayerMoney(player, tonumber(text))
			end	
		end    	
	else
		outputChatBox("You already used /spin in the past 10 minutes!", player)
	end
end
addCommandHandler("spin", spincoin)

 

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