Whats the time Mr. Wolf?
Created By: Marius
eMail: lordshoel@yahoo.com
Difficulty Scale: Easy

In this tutorial well add a Mission Timer to Quake. There is two variations of this timer. The first is simply straight forward as the actual time of the mission. The second is a countdown timer, this can be used for Power-ups or Deathmatch games. The first timer will be used in single player games. The second timer will be used in Deathmatch games.

So lets get started shall we....

Step 1

Create a new qc file called Timer.qc once you have created this new file up it up in your favourite text editing program. Now onced open paste the following code into Timer.qc. This is the longest step.

//Mission Timer A
void() MissionTimerA =
	local string a;
	a = ftos (time);
	specialprint (self,"\n\n\n\n\n\n\n\n\n\n\n\nTime Elapsed: ",a,"--","","","","");

//Mission Timer B
void() MissionTimerB =
	local float timelimit;
	local string a;

	timelimit = cvar("timelimit") * 60;
	if (!timelimit) return;
	timelimit = timelimit - time;
	a = ftos (timelimit);
	specialprint (self,"\n\n\n\n\n\n\n\n\n\n\n\nTime Remaining: ",a,"--","","","","");
Well that wasn't too hard. The above is our two functions for our Timers. Now save and open up Progs.src. In Progs.src add Timer.qc above Client.qc.

Step 2

Did you notice anything out of the norm in the above step? If you didn't it was the line

specialprint (self,"\n\n\n\n\n\n\n\n\n\n\n\n--",a,"--","","","","");

This prints our timer. The problem is it does not exist within quake yet. So lets add it.

Open upe Defs.qc, scroll to the very end and add the following lines:

//Specialprint function. Prints up to 7 strings together.
void(entity client, string s, string s, string s, string s, string s, string s, string s) specialprint = #73;
Now save and continue to the last step.

Step 3

So far with have created two function and special function but nothing uses the timer functions yet. We'll have to 'make it so...'. Ok open up Client.qc and find the PlayerPostThink function. Found it yet? When you have scroll to the very bottom and paste this small chunk of code:

	//The Timer comes into play... 
	if (deathmatch || coop) MissionTimerB();	//Countdown
	else MissionTimerA();				//Mission Timer
Well that should be it for the code side of it.

Step 4

Save and Compile. And there you go, a mission timer in single player games and a countdown timer in multiplayer games. It was pretty simple wasn't it. Till next time have fun and happy gaming.

BTW Give credit to both Merl1n and The Lieutenant. Their code was used as a basis for this tutorial so if you use this in anyway give them credit as they deserve it!