Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Tormentor667

Countdown Script?

Recommended Posts

Hi, another Question from me :)

I want to create a Countdown Script, that counts to zero (00:00) from 5 Minutes (05:00). For this I would like to use the following countdown HUDMSG command:

script 111 (void)
{
hudmessage (s:"Timer:\n, s:"05:00"; HUDMSG_PLAIN, 2, CR_WHITE, 1.0, 0.0, 1.0);
delay (35);
hudmessage (s:"Timer:\n, s:"04:59"; HUDMSG_PLAIN, 2, CR_WHITE, 1.0, 0.0, 1.0);
delay (35);
[...]
}

This Scipt would show a countdown number in the top-left screencorner and every second, it would refresh! The problem about it: I don't want to finish this script by writing down about 300 "hudmessages" with the 0x:xx changed every step. Is there a better way to realise this?! (plz gimme the complete script then!)

Share this post


Link to post

try something like this.

script 111 (int counttime) {
	int i;
	int mins, secs;
	str minfill, secfill;
	for (i = counttime; i >= 0; i--) {
		mins = i / 60;
		secs = i % 60;

		if (mins >= 10)
			minfill = "";
		else
			minfill = "0";
	
		if (secs >= 10)
			secfill = "";
		else
			secfill = "0";

		hudmessage(s:"Timer:\n", s:minfill, d:mins, s:":", s:secfill, d:secs; HUDMSG_PLAIN, 2, CR_WHITE, 1.0, 0.0, 1.0);
		delay(35);
	}
}
just give it the number of seconds to countdown (in your case it would be 300) as its argument and it should work. i haven't tested it btw.

Share this post


Link to post

AFAIK, there's no built in timer function. What I do is print a message every 10 seconds which shows the time:


printbold(s:"2:00");
delay(350);
printbold(s:"1:50");
delay(350);


and so on until 10 seconds, then I count down every second. (replace printbold with hudmessage in your case)

My timed sections are usually around 2 minutes or less, but I definitely recommend using this method for a 5 minute timer. (saves a lot of script space)

Share this post


Link to post

There actually is an built in timer functions, it's simply called timer() and returns the level time in tics (i.e. you have to divide by 35 to get the seconds). I don't think it's really useful in this case, since schepe's script will do the job very well.

Share this post


Link to post

Thx for the help and now I have an additional question about this script. How can I add some commands, that will be executed, if the counters minute+second indicator is for example 02:33 or else?! Because I want the timerscipt to teleport enemies in my arena every few seconds :)

Share this post


Link to post

Just make the mins and secs vars map global and have a self-restarting script that looks for those vars. Something like

script 123 (void)
{
 if (mins == 2 && secs == 33) { // does ACS actually allow &&? I can't remember, heh
    // do some shit here
 }

 delay(1);
 restart;
}

Share this post


Link to post

Let's see if this works:

At the very top of the script, add this to each map:

world int 1: Minutes; // Can be any name
world int 2: Seconds; // Same here
Now add this:
script 1 open // Add this script to the first map only
{
    Minutes = 4;
    Seconds = 60; // 5 minutes total
}

script 2 (void) // Add this to all maps
{
    Seconds -= 1;
    if(Seconds < 10)
    {
        printbold(d:Minutes,s:":0",d:Seconds,s:" remaining");
    }
    else
    {
        printbold(d:Minutes,s:":",d:Seconds,s:" remaining");
    }
    if(Seconds == 0)
    {
        Minutes -= 1;
        Seconds = 60;
    }
    if((Minutes == 0) && (Seconds == 0))
    {
        ACS_Execute(10, 2, 0, 0, 0); // Script 10
on map 2. If you're on another map, then the
script will run when you get to map 2.
    }
    delay(35); // equal to 1 second
    restart;
}

Share this post


Link to post

Thx for the script Ichor but ACS tells me, that there is a missing semicolon after "world" :(

Do I need a new version of acs? And where can i get it?

Share this post


Link to post

Only one problem about it:

When the counter starts @ 4 Minutes and 60 Seconds and counts down to 4 Minutes and 10 Seconds, it looks like this:

Timer: 4:059 (4:010)

and if there are only single numbers to count, from 4 Minutes and 9 seconds on, it looks like this:

Timer: 4:9 (4:8, 4:7)

Looks a bit ugly I think! Is there also a possibility to put the text in the lower or upper left corner? Could you also do this?

Share this post


Link to post
Tormentor667 said:

Only one problem about it:

When the counter starts @ 4 Minutes and 60 Seconds and counts down to 4 Minutes and 10 Seconds, it looks like this:

Timer: 4:059 (4:010)

and if there are only single numbers to count, from 4 Minutes and 9 seconds on, it looks like this:

Timer: 4:9 (4:8, 4:7)

Looks a bit ugly I think! Is there also a possibility to put the text in the lower or upper left corner? Could you also do this?


Simple replace the line

if(Seconds > 10)
with
if(Seconds < 10)
Just a little typo.

Share this post


Link to post

There, it's fixed.

One little mistake can cause a whole lot of chaos, especially if it doesn't look like one, and I've had more than my share of blunders, heheh.

Share this post


Link to post

Just one little question *g* : Could you replace the printbold command with hudmessage and change everything in a way, that the message is placed in the upper left corner?!

Share this post


Link to post

Well, I don't know most ZDoom specific script commands, since I work with Hexen.

Still, you could try replacing the 'printbold' part with just 'print' and see what happens.

Share this post


Link to post
Tormentor667 said:

Just one little question *g* : Could you replace the printbold command with hudmessage and change everything in a way, that the message is placed in the upper left corner?!


Yes. (but I don't use it, so I don't know what the exact commands are)

Share this post


Link to post

Personally I prefer just seconds as an argument. Here's another way to do the clock that makes it look PRETTY. Originally this routine was passed a time and a script to execute. I took it out earlier, but it's easy to figure out how to do this. Now let's see if the post comes out ok? [Sorry, you can figure out the spacing - mods can fix:)]


#include "zcommon.acs"

#define SECOND1 35 // 1 second

//=======================================+
// script 1 OPEN startup MESSAGES
//========================================

Script 1 OPEN
{

acs_execute(250,100); // start the countdown timer

}

//=======================================
// A timer Clock for up to 59 minutes 59 seconds
//========================================

str numbers[60] =
{"00","01","02","03","04","05","06","07","08","09",
"10","11","12","13","14","15","16","17","18","19",
"20","21","22","23","24","25","26","27","28","29",
"30","31","32","33","34","35","36","37","38","39",
"40","41","42","43","44","45","46","47","48","49",
"50","51","52","53","54","55","56","57","58","59"};

//=======================================
// script for showing the clock
//=======================================

script 250 (int timedelay)
{
int timeleft;
int minutes;
int seconds;

timeleft = timedelay;

while (timeleft)
{
minutes = timeleft/60;
seconds = timeleft%60;

hudmessage (
s:numbers[minutes],s: ":",s:numbers[seconds];

HUDMSG_PLAIN, // message type
0, // message id
CR_BLUE, // message color
0.45, // x-coordinate
0.6, // y-coordinate
1.0); // hold time (in seconds)

delay(SECOND1);

timeleft--;
}
}

/////// end ///////////////////

Oops, posted the more complicated one first

Share this post


Link to post

@Deep - Thx, but the previous one works fine. My only question is how I can change the printbold into hudmessage so I can put the counter somewhere else :(

Share this post


Link to post
Tormentor667 said:

@Deep - Thx, but the previous one works fine. My only question is how I can change the printbold into hudmessage so I can put the counter somewhere else :(

I don't understand. Just change printbold to a hudmessage. String formatting is identical. Just add the coordinate, etc. stuff.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×