Author Topic: Countdown?  (Read 5943 times)

0 Members and 1 Guest are viewing this topic.

Offline lyoko

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Countdown?
« on: January 12, 2008, 03:46:02 AM »
hey. i need countdown script. like
ulx countdown 9 1
from 9 to 1
its because i want to make some races on my server.
thanks :)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Countdown?
« Reply #1 on: January 12, 2008, 04:42:01 AM »
give me a few minutes =)

Lyoko dfg

  • Guest
Re: Countdown?
« Reply #2 on: January 12, 2008, 04:50:17 AM »
hey and i want size. i don't want that the countdown will be inside the chat.
ulx countdown 9 1 size
text size.
Sorry for my english  :-X

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Countdown?
« Reply #3 on: January 12, 2008, 04:58:11 AM »
I am just going to put it in the CSAy field. so it will display in the center of the screen

I dont know enough derma nor do I wish to spend the time to make custom text sizes. I'm almost done too.. 5 more minutes..

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Countdown?
« Reply #4 on: January 12, 2008, 05:13:34 AM »
Here you go..

Code: [Select]
if SERVER then
local toptime = 0

function CountDown(ply, text, public)
local args = string.Explode(" ", text)

if args[1] == "!countdown" then
if ply:IsAdmin() then
toptime = args[2]
timer.Create("CountDownTimer", 1, 0, CountDownTimer)
ULib.tsay(nil, ply:GetName().. " has started a countdown timer!", true)
else
ULib.tsay(ply, "Sorry, only admins can use this feature", true)
end
return ""
elseif args[1] == "!stopcountdown" then
timer.Destroy("CountDownTimer")
ULib.csay(nil, "Countdown has been halted!")
ULib.tsay(nil, "Countdown has been halted!", true)
end
end
hook.Add( "PlayerSay", "CDChatHook", CountDown )


function CountDownTimer()
if tonumber(toptime) >= 1 then
ULib.csay(nil, tostring(toptime).. " seconds remaining")
toptime = toptime - 1
else
timer.Destroy("CountDownTimer")
ULib.csay(nil, "Countdown has ended!")
ULib.tsay(nil, "Countdown has ended!", true)
end
end

end

Take this code, and stick it in a file called CountDown.lua and put it in your Garrysmod/lua/autorun folder


the commands are..

!countdown <seconds>
and
!stopcountdown

This will display a countdown in the center of the screen of every user on the server until it is halted or until it reaches 0.

EDIT: This is obviously not a feature rich as you would like Im sure, but ULX will never add something like this because it is not necessary as an admin tool, and the goal of ULX is for simplicity. If this is not to your needs, i'm sorry. However I will probably throw it on my server for kicks =)
« Last Edit: January 12, 2008, 08:16:28 AM by JamminR »

Offline lyoko

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Countdown?
« Reply #5 on: January 12, 2008, 05:19:55 AM »
thanks you very much :) ;D :D

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Countdown?
« Reply #6 on: January 12, 2008, 07:10:48 AM »
Very nice zakap, but can I suggest that if you're using ULib already anyways, use ULib.addSayCommand... http://ulyssesmod.net/docs/files/lua/ULib/server/concommand-lua.html#addSayCommand :)
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Countdown?
« Reply #7 on: January 12, 2008, 01:28:26 PM »
very nice, I had no idea this function existed. This may prove to be most useful.