This countdown will start by typing in !countdown [seconds] and it will finish with a chat notification and a gunshot. It's quite customizable but not sure if this is what you want.
//Countdown script by Toneo
//:D
local AdminOnly = false //Who can start countdowns? Only admins can stop countdowns.
local EchoConsole = false //Echo into the console? (10,9,8,7,6,5,4,3,2,1,Endofcountdown etc)
local EchoChat = false //Echo into the chat?
local EchoCenter = true //Echo into middle of the screen?
local GunShot = true //Play a gunshot when the countdown is up?
local secondsRemaining = 0 //Don't edit this. It doesn't make any difference if you do :3
local function StartCountDown(ply,cmd,args)
if (AdminOnly) && !ply:IsAdmin() then return end
if !args[1] then Msg("Hey! Countdowns need a time! :(\n") end
//Protection against negative numbers (not sure what happens if we use them but ima blocking them)
if (tonumber(args[1])<=0) then
Msg("You can't have that delay!")
end
local function Tick()
if EchoConsole then MsgAll(secondsRemaining.."\n") end
if EchoCenter then
for k, v in ipairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,secondsRemaining)
end
end
if EchoChat then
for k,v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,secondsRemaining)
end
end
secondsRemaining = secondsRemaining - 1
end
local function End()
for k,v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"The countdown has ended.")
v:PrintMessage(HUD_PRINTCENTER,"The countdown has ended.")
end
if GunShot then
for k, v in ipairs(player.GetAll()) do
v:ConCommand("play weapons/357/357_fire2.wav")
end
end
end
secondsRemaining = tonumber(args[1])
timer.Create("CookieCountdown",tonumber(args[1])+2,1,End) //I dunno why I have to add 2 but if I don't it goes.. 60 59 58 ..etcetc.. 5 4 3 The Countdown has ended 2 1
timer.Create("CookieCountdownTICK",1,tonumber(args[1]),Tick)
for k,v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"Timer has been created by "..ply:Nick().." with a delay of "..tonumber(args[1])..".")
end
end
concommand.Add("countdown_start",StartCountDown)
local function CancelCountdown(ply,cmd,args)
if ply:IsAdmin() then
timer.Remove("CookieCountdown")
timer.Remove("CookieCountdownTICK")
for k,v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"The timer has been cancelled by "..ply:Nick().."!")
end
else
ply:PrintMessage(HUD_PRINTTALK,"You are not an admin!")
end
end
concommand.Add("countdown_cancel",CancelCountdown)
local function CountChatHook(ply,text)
local sep = string.Explode(" ",text)
if sep[1] == "!countdown" then
if !sep[2] then ply:PrintMessage(HUD_PRINTTALK,"You need to type the delay!") end
ply:ConCommand("countdown_start "..sep[2]) //Do it
return "" //Don't say anything :)
end
if sep[1] == "!cancelcountdown" then
ply:ConCommand("countdown_cancel") //Do it
return ""
end
//We are NOT returning at the end (otherwise we will override ALL OTHER CHAT COMMANDS)
end
hook.Add("PlayerSay","CountDownChat",CountChatHook)