You may usually see a little digital count-down clock when you play on a VC-MP server which runs a timed gamemode, for example CTF, A/D or racing timelaps. Making such a count-down clock is relatively easy but it requires a bit of thinking. Just because I had nothing better to do, I decided to write a short tutorial on how to do it. This works, by the way.
// This isn't really useful as a stand-alone script; I'm just trying to get the idea of countdown announces across.
// Note, .Stop(); is the equivalent of pausing a round in an A/D gamemode, it does not reset the seconds and/or minutes. I've made a command dedicated to that, called "reset".
// First we'll declare a few global variables for this snippet.
minutes <- 0; // This will be your minute counter.
seconds <- 0; // This will be your second counter.
isTimerRunning <- false; // This will decide when to run the announce timer and when not to.
// Now to loading stuff.
function onScriptLoad()
{
try
{
// Reset all values.
minutes = 0;
seconds = 0;
if( isTimerRunning ) isTimerRunning = false;
announceTimer <- NewTimer( "announcer", 1000, 0 ); // The timer itself.
announceTimer.Stop();
print( "Loaded." );
}
catch( error ) print( "onScriptLoad error: " + error );
}
// A few needed functions.
function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}
function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
tokenized = split(string, separator),
text = "";
if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}
// Command stuff.
function onPlayerCommand( player, command, text )
{
if( command == "minlimit" )
{
if( !text ) PrivMessage( "/c minlimit <newMinuteValue> or 'current' to get the current value.", player );
else if( text.tolower() == "current" )
PrivMessage( "The current starting minute is set to " + minutes + ".", player );
else if( IsNum( text ) )
{
local newMin = GetTok( text, " ", 1 );
if( !IsNum( newMin ) ) PrivMessage( "The new minute value has to be an integer.", player );
else
{
minutes = newMin.tointeger();
PrivMessage( "Minute value updated to " + minutes + ".", player );
}
}
}
else if( command == "announcer" )
{
if( !text ) PrivMessage( "/c announcer on/off", player );
else
{
if( text.tolower() == "on" )
{
if( isTimerRunning ) PrivMessage( "There's an announcer already running.", player );
else
{
isTimerRunning = true;
PrivMessage( "Starting the timer...", player );
announceTimer.Start();
}
}
else if( text.tolower() == "off" )
{
if( !isTimerRunning ) PrivMessage( "There is no announcer to stop to begin with.", player );
else
{
isTimerRunning = false;
PrivMessage( "Stopping the timer...", player );
announceTimer.Stop();
}
}
}
}
else if( command == "reset" )
{
if( !text ) PrivMessage( "/c reset min/sec", player );
else
{
if( text.tolower() == "min" )
{
minutes = 0;
PrivMessage( "Minutes reset.", player );
}
else if( text.tolower() == "sec" )
{
seconds = 0;
PrivMessage( "Seconds reset.", player );
}
}
}
}
// The announcer himself.
function announcer()
{
seconds--;
if( seconds < 0 )
{
seconds = 59;
minutes--;
if( minutes == 0 )
{
Message( "Timer stopped." );
seconds = 0;
announceTimer.Stop();
}
}
if( seconds < 10 ) AnnounceAll( "~y~" + minutes + ":0" + seconds, 1 );
else AnnounceAll( "~y~" + minutes + ":" + seconds, 1 );
}
This is a command-based mechanism but it should be relatively easy for people with medium-sized+ brains to implement this any other way. (That's why I didn't post this on the VC:MP forum
)