Timer and stopwatch

Have questions about CoD/UO mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
BatterY
CJ Worshipper
CJ Worshipper
Posts: 238
Joined: January 29th, 2010, 10:27 pm

Timer and stopwatch

Post by BatterY » September 29th, 2010, 2:24 pm

I would like to create a stopwatch on side of the screen when trigger A is triggered and delete it when you hit trigger B or time is up (60 secs). Another script would be needed on measuring the time. When you hit trigger A, it starts measuring time, when you hit B, it stops the time and prints it, or while measuring, it shows it.

A picture is worth a thousand words:
trigger.png
I don't have any experience in creating hud elements and that's why I need help.
You do not have the required permissions to view the files attached to this post.

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Timer and stopwatch

Post by Rezil » September 29th, 2010, 2:53 pm

Code: Select all

main()
{
	precachestring(&":");
	precachestring(&" ");

	thread start();
	thread simple_stopwatch();
	thread stopwatch_end();
	
	level.time_interrupted = false;


}

start()
{	
	for(;;)
	{
		p = getentarray("player", "classname");
		for(i=0;i<p.size;i++) 
		{
			if ((!isdefined(p[i].reset)) && (isalive(p[i])))
			{
				p[i].reset = true;
				p[i].triggered_timer = false;
				p[i] thread watchUserTime();
			}
		}
		wait 0.25;
	}
}

simple_stopwatch()
{
	t = getent("START_TRIGGER","targetname"); //Change!

	while(1)
	{
		t waittill("trigger", user);
		level.time_interrupted = false;
		if(!user.triggered_timer)
		{
			level.time_interrupted = false;
			user.triggered_timer = true;
			if((!isdefined(user.secondwatch)) && (!isdefined(user.minutewatch)))
			{
				user thread make_secondswatch();
				user thread make_minuteswatch();
				user thread dots_inbetween();
			}
		}
		else user iprintlnbold("You already triggered the timer!"); wait 2;
	}
}

make_secondswatch()
{
	self.secondwatch = newclienthudelem(self);
	self.secondwatch.x = 322; //max 650
	self.secondwatch.y = 450; //max 475
	self.secondwatch.alignX = "left";
	self.secondwatch.alignY = "bottom";
	self.secondwatch.font = "default";
	self.secondwatch.fontScale = 2;   
	self.secondwatch.archived = false;
	self.secondwatch.color = (1, 1, 1);
	for(;;)
	{
		secondtime = 0;
		secondtime = secondtime * 10;
		seconds = 0;
		for(i=seconds;i<=599;i++)
		{
			if(level.time_interrupted) 
			{
				seconds = 0;
				break;
			}
			self.secondtime = i / 10;
			self.secondwatch setValue(self.secondtime);
			wait 0.1;
		}
		wait 0.05;
	}
}

make_minuteswatch()
{
	self.minutewatch = newclienthudelem(self);
	self.minutewatch.x = 311; //max 650
	self.minutewatch.y = 450; //max 475
	self.minutewatch.alignX = "right";
	self.minutewatch.alignY = "bottom";
	self.minutewatch.font = "default";
	self.minutewatch.fontScale = 2;   
	self.minutewatch.archived = false;
	self.minutewatch.color = (1, 1, 1);
	self.minutetime = 0;
	minutes = 0; //And no I don't know why I used this instead of just putting i=0;
	for(i=minutes;i>=0;i++)
	{
		if(level.time_interrupted) 
		{
			minutes = 0;
			break;
		}
		self.minutewatch setValue(self.minutetime);
		if(self.secondtime == 599/10) self.minutetime++;
		wait 0.1;
	}
}

dots_inbetween()
{
	self.dots = newclienthudelem(self);
	self.dots.x = 318; //max 650
	self.dots.y = 450; //max 475
	self.dots.alignX = "right";
	self.dots.alignY = "bottom";
	self.dots.font = "default";
	self.dots.fontScale = 2;   
	self.dots.archived = false;
	self.dots.color = (1, 1, 1);
	for(;;)
	{
		if(level.time_interrupted) break;
		self.dots.label = &":";
		wait 0.7;
		self.dots.label = &" ";
		wait 0.7;
	}
}

watchUserTime()
{
	for(;;)
	{
		if(self.triggered_timer) //if user has triggered timer he must have secondtime and minutetime values
		{
			if((self.minutetime==1) && (!level.time_interrupted)) //60 seconds are up!
			{
				self iprintlnbold("You weren't fast enough!");
				level.time_interrupted = true;
				self.triggered_timer = false;
				self.secondtime = 0;
				self.minutetime = 0;
				self.minutewatch destroy();
				self.secondwatch destroy();
				self.dots destroy();
				wait 0.05;
			}
		}
		wait 0.05;
	}
}

stopwatch_end()
{
	t = getent("END_TRIGGER","targetname"); //Change!

	while(1)
	{
		t waittill("trigger", user);
		if(user.triggered_timer)
		{
			user.triggered_timer = false;
			level.time_interrupted = true;
			user iprintlnbold("You finished in " +user.secondtime+ " seconds and " +user.minutetime, " minutes."); //minutes added if you want more minutes other than 1(see watchUserTime())
			user.secondtime = 0;
			user.minutetime = 0;
			user.minutewatch destroy();
			user.secondwatch destroy();
			user.dots destroy();
			wait 0.05;
		}
		else user iprintlnbold("You didn't trigger the timer so it can't end here!"); wait 2;
	}
}
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Timer and stopwatch

Post by Rezil » September 29th, 2010, 4:11 pm

See post above.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Pedsdude
Site Admin
Site Admin
Posts: 15908
Joined: October 15th, 2004, 7:18 pm
Location: UK

Re: Timer and stopwatch

Post by Pedsdude » September 29th, 2010, 4:35 pm

Rezil @ win.
Image
Image

BatterY
CJ Worshipper
CJ Worshipper
Posts: 238
Joined: January 29th, 2010, 10:27 pm

Re: Timer and stopwatch

Post by BatterY » September 29th, 2010, 6:12 pm

128909531505186973.jpg
You do not have the required permissions to view the files attached to this post.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Timer and stopwatch

Post by Drofder2004 » September 29th, 2010, 7:34 pm

Code: Select all

    level.watch = newHudElem();
    level.watch.x = 0;
    level.watch.y = 0;
    level.watch.alignx = "center";
    level.watch.aligny = "middle";
    level.watch.horzAlign = "center";
    level.watch.vertAlign = "middle";
    level.watch setClock( 60, 60, "hudStopwatch", 64, 64 );
Easy clock.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
MORGOTH
CJ Newbie
CJ Newbie
Posts: 82
Joined: July 30th, 2009, 4:41 pm

Re: Timer and stopwatch

Post by MORGOTH » September 30th, 2010, 12:34 am

why can't you add a thing like this in cjmod for cod4 that makes the timer start by pressing a button and end by pressing it another time... would be cool for custom jumping maps ^^

User avatar
Hoogie
Core Staff
Core Staff
Posts: 3974
Joined: September 2nd, 2008, 10:22 am
Location: Holland

Re: Timer and stopwatch

Post by Hoogie » September 30th, 2010, 1:44 pm

MORGOTH wrote:why can't you add a thing like this in cjmod for cod4 that makes the timer start by pressing a button and end by pressing it another time... would be cool for custom jumping maps ^^
Good idea!
Would be even more awesome to save records on the server but i guess you need a whole database to do that :P

But the timer to use personally would be nice :D
-=[[CoDJumper.com Movies]]=-
[[Ambush]] || [[Backlot]] || [[Bloc]] || [[Bog]] || [[Broadcast]] || [[Chinatown]] || [[Countdown]]
[[Crash]] || [[Creek]] || [[Crossfire]] || [[District]] || [[Downpour]] || [[Killhouse]] || [[Overgrown]]
[[Pipeline]] || [[Shipment & Wetwork]] || [[Showdown]] || [[Strike]] || [[Vacant]]


A woman can fake an orgasm, but a man can fake an entire relationship

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Timer and stopwatch

Post by Rezil » September 30th, 2010, 2:59 pm

The script works. Just save it into your map .gsc, make a start trigger and an end trigger, rename the parts in the script accordingly and be sure to give credit('with help from codjumper' should do fine. :P).
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

BatterY
CJ Worshipper
CJ Worshipper
Posts: 238
Joined: January 29th, 2010, 10:27 pm

Re: Timer and stopwatch

Post by BatterY » September 30th, 2010, 3:04 pm

Rezil wrote:The script works. Just save it into your map .gsc, make a start trigger and an end trigger, rename the parts in the script accordingly and be sure to give credit('with help from codjumper' should do fine. :P).
Will do.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests