ULX

Author Topic: Countdown  (Read 4884 times)

0 Members and 1 Guest are viewing this topic.

Offline iBurnPuppies

  • Newbie
  • *
  • Posts: 27
  • Karma: 2
Countdown
« on: August 11, 2009, 11:19:13 AM »
Citrus has a nice little countdown feature where you give it text, what time to countdown from, and if you want, it runs a command once it ends. ULX should get this. What it could be is that you type something like, !countdown "This is a test of the countdown!" 60 "ulx map gm_construct". In the top right corner, you see the text of the countdown, and below it, how much time is left, in this case 60 minutes, and then the command that's going to be run once the countdown ends.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Countdown
« Reply #1 on: August 11, 2009, 06:35:23 PM »
Other than perhaps someone writing a 3rd party release for ULib, I don't see this being added to ULX.
It might be a fun feature, but it's not a requirement to administer a server.
Conna, as we know him, tried making Citrus so much more than an admin mod.
But then again, ULib is so much more than ULX..so, meh.
ULib, and the admin mod ULX that runs on ULib, is only meant to be an admin mod.

As for your example of changing a map... there is a release in our Releases section that does that.
http://forums.ulyssesmod.net/index.php/topic,688.0.html
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iBurnPuppies

  • Newbie
  • *
  • Posts: 27
  • Karma: 2
Re: Countdown
« Reply #2 on: August 12, 2009, 01:21:14 AM »
I understand. I forget that ULX is meant to be a simple tool to make administrating a server easier, not a way to cram in random features. Thanks for listening to my suggestion though, I appreciate it.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Countdown
« Reply #3 on: August 12, 2009, 03:03:57 PM »
Your welcome.
We do occasionally throw in ideas that aren't really required to administer a server.
I mean, really, does administrating a server really require a 'maul' command?
No, but it sure does make a fun punishment, right?
Never be afraid of making suggestions.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Countdown
« Reply #4 on: August 13, 2009, 02:52:11 PM »
I mean, really, does administrating a server really require a 'maul' command?
No, but it sure does make a fun punishment, right?

Or maybe Megiddo just really wanted to do something in lua with NPCs. ;)
Experiencing God's grace one day at a time.

Offline benbrooks

  • Newbie
  • *
  • Posts: 28
  • Karma: 2
Re: Countdown
« Reply #5 on: September 06, 2009, 04:14:49 AM »
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.

Code: [Select]
//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)

Offline iBurnPuppies

  • Newbie
  • *
  • Posts: 27
  • Karma: 2
Re: Countdown
« Reply #6 on: September 12, 2009, 10:24:21 PM »
It looks great, though I don't know how to install it. How do I install it?

Offline [WCA]AIDS

  • Jr. Member
  • **
  • Posts: 58
  • Karma: 7
    • PlanetWCA Forums
Re: Countdown
« Reply #7 on: September 13, 2009, 12:54:00 AM »
Copy and paste all of the code into notepad.
Save the file as <whateveryouwant>.lua
Place the file in your server's lua\autorun\server directory
restart your server or in rcon run 'lua_openscript lua\autorun\server\<whatevernameyouchose>.lua'

For example,
I will save the script as countdown.lua
lua_openscript lua\autorun\server\countdown.lua
tada, you can now !countdown.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Countdown
« Reply #8 on: September 13, 2009, 04:40:15 AM »
Ben, did you write that?
If not, do you know Toneo?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline benbrooks

  • Newbie
  • *
  • Posts: 28
  • Karma: 2
Re: Countdown
« Reply #9 on: September 13, 2009, 10:58:02 AM »
I know Toneo :)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Countdown
« Reply #10 on: September 13, 2009, 12:43:57 PM »
Ok. Pass some words to him for me?
He could optimize the code much better if he were to use as little for/pairs loops as possible.
The Tick function would be better with only one.
Similiar to
For => pairs
if <chat indicator> then <blah>
if <center indicator> then <blah>
end
Rather than having two for pairs loops.

Though this script is small and it probably doesn't hurt much, larger scripts if he ever makes them, for pairs are actually pretty process costly.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming