How to make a stop watch?

Author Topic: How to make a stop watch?  (Read 4493 times)

I'm in a bit of a pickle;

I wish to have a function that counts in time.
Halp plz.

I'm in a bit of a pickle;

I wish to have a function that counts in time.
Halp plz.


Code: [Select]
function servercmdStopWatch(%client){
if(!%client.stopwatch){
%client.stopwatch=schedule(1000,0,stopcount,%client);
}else{
messageclient(%client,'',%client.watchtime SPC "seconds");
cancel(%client.stopwatch);
%client.watchtime=0;
}
}
function stopcount(%client){
%client.watchtime++;
%client.stopwatch=schedule(1000,0,stopcount,%client);
}

Should work. Put in a .cs and drop in add-ons folder.
Say /stopwatch to begin, /stopwatch again to stop.


Yea, Stopwatch is the 1 second loop, and watchtime is the amount of seconds that have passed.

I'd use bottom print or center print to avoid chat spam.

I'd use bottom print or center print to avoid chat spam.
It doesnt show up every second or something-- it only tells you the time after you say /stopwatch again to stop it. 1 message isn't bad, I would think. Now if it flashed a message every so or so seconds...

I didnt actuly want a stop watch, i wanted the var for somthing much more important

%startTime = $sim::time;

later..

%endTime = $sim::time - %startTime;

^ In seconds and miliseconds

"I'm in a bit of a pickle." should be the official first line of every Coding Help post.  Help me to make it so.

It's now a unofficial rule?

It's now a unofficial rule?
Why are you in a bit of a pickle?


"I'm in a bit of a pickle." should be the official first line of every Coding Help post.  Help me to make it so.
I second that.

Code: [Select]
function ServerCmdStopWatch(%client)
{
if(!%client.isStopWatchOn)
{
%client.isStopWatchOn = 1;
%client.timeStarted = getSimTime();
MessageClient(%client,"","\c2Stop Watch started");
}
else
{
%client.isStopWatchOn = 0;
%time = getSimTime() - %client.timeStarted;
%time = getTimeString(%time / 1000);
MessageClient(%client,"","\c2Time: \c6"@ %time);
}
}
Tested for perfection  :cookieMonster:

If you don't like the string that gettimestring gives you, you can just make your own.  Same with the font colors...

And if it isn't obvious enough how it works, just type /stopwatch once to start the time and then type it again to stop the watch and display the time

Example Output: 1:15.356  -- which would translate to 1 minute 15 seconds and 356 milliseconds
« Last Edit: February 04, 2008, 07:22:16 PM by Irk89 »

IIRC, Badspot said to nest.

Code: [Select]
function serverCmdstopWatch(%client)
{
if(!%client.isStopWatchOn)
{
%client.stopWatch = true;
%client.timeStarted = getSimTime();

messageClient(%client, '', "\c2Stop Watch started");

return;
}

%client.stopWatch = false;

messageClient(%client, '', "\c2Time: \c6" @ getTimeString(getSimTime() - %client.timeStarted / 1000));
}
« Last Edit: February 05, 2008, 06:14:25 PM by Wattson »