Timer and stopwatch
Moderator: Core Staff
Timer and stopwatch
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:
I don't have any experience in creating hud elements and that's why I need help.
A picture is worth a thousand words:
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.
-
- 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
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.
[...]
#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.
-
- 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
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.
[...]
#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.
Re: Timer and stopwatch
You do not have the required permissions to view the files attached to this post.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Timer and stopwatch
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 );
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
Re: Timer and stopwatch
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 ^^
Re: Timer and stopwatch
Good idea!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 ^^
Would be even more awesome to save records on the server but i guess you need a whole database to do that
But the timer to use personally would be nice
-=[[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
[[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
-
- 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
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. ).
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.
[...]
#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.
Re: Timer and stopwatch
Will do.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. ).
Who is online
Users browsing this forum: No registered users and 1 guest