Requesting a timer

Discuss all aspects related to modding Zandronum here.
Post Reply
Mr.Man
Forum Regular
Posts: 657
Joined: Thu May 09, 2013 7:25 pm

Requesting a timer

#1

Post by Mr.Man » Sun Jan 26, 2014 12:36 am

I am looking for a script that allows to have a 2 minute timer, including milli seconds.

I need it to fit into another script, which is also possible to have results after its done.

Preferably this:

Collapsion in: – preferably this text above it
2:00.00 – preferably this many numbers

in BIGFONT, on y-scale 0.2, on the middle

If anybody has one, or the code, i would be really gratefull, i'm looking for this for a while now.

EDIT: the timer is only used once per time you play, so it doesnt need a restart or anything.
Last edited by Mr.Man on Sun Jan 26, 2014 7:46 am, edited 1 time in total.

Klofkac
Forum Regular
Posts: 481
Joined: Sat Jun 09, 2012 1:31 pm
Location: Ask Grandvoid servers

RE: Requesting a timer

#2

Post by Klofkac » Mon Jan 27, 2014 10:13 am

Not tested, written on machine without zan and ACC compiler. There may be errors.

Code: Select all

function void DrawMessage( int minutes, int seconds, int milliseconds )
{
    SetFont("BigFont");
    HudMessageBold(    s: "Collapsion in:\n",
            s: prefix( minutes, false ), d: minutes, s:":",
            s: prefix( seconds, false ), d: seconds, s:".",
            s: prefix( milliseconds, true), d: milliseconds;
            HUDMSG_PLAIN,
            1, //change ID if you need to
            CR_yellow, //change colour if you need to
            1.5, 0.2, 0);
}

function str prefix( int number, bool milli)
{
    if ( milli ) // if milliseconds, then make it for 3 digits
    {
        if ( number <= 9 ) return "00";
        if ( number <= 99 ) return "0";
    } else if ( number <= 9 ) return "0"; // otherwise make it be 2 digits
    return "";
}

script 1337 (void) //change 1337 to your number
{
    int minutes, seconds, remtics, milliseconds;
    for(int tics = 35 * 60 * 2; tics >= 0; tics --) // counter
    {
        minutes = ( tics / 35 ) / 60;
        seconds = ( tics / 35 ) % 60;
        remtics = tics % 35;
        if ( !remtics ) milliseconds = 0; // DIVISION BY ZERO MUST BE AVOIDED AT ANY COSTS
        else milliseconds = (100000 / ( 3500 / remtics ));
        DrawMessage( minutes, seconds, milliseconds );
        delay( 1 );
    }
}
Just follow some comments and you are okay. I assume you will add it to existing script so I didn't write #INCLUDE. You should do so.
Last edited by Klofkac on Mon Jan 27, 2014 10:36 am, edited 1 time in total.
𝕂𝕝𝕠𝕗𝕜𝕒𝕔

User avatar
ibm5155
Addicted to Zandronum
Posts: 1641
Joined: Tue Jun 05, 2012 9:32 pm
Location: Somewhere, over the rainbow

RE: Requesting a timer

#3

Post by ibm5155 » Mon Jan 27, 2014 12:22 pm

String function o.o i never knew this one :O
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!

<this post is proof of "Decline">

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

RE: Requesting a timer

#4

Post by Watermelon » Mon Jan 27, 2014 1:05 pm

ibm5155 wrote: String function o.o i never knew this one :O
That's because strings are indices so you can make functions that return thanks to StrParam
Last edited by Watermelon on Mon Jan 27, 2014 1:05 pm, edited 1 time in total.

Mr.Man
Forum Regular
Posts: 657
Joined: Thu May 09, 2013 7:25 pm

RE: Requesting a timer

#5

Post by Mr.Man » Mon Jan 27, 2014 4:13 pm

That is awesome klofkac, but i have a change of mind (which is probably real dickerish)

I actually want it to support different amounts of time, because it seems allot more efficient, also for a mod i'm making.

EDIT: i might be able to do this myself do.

I just change script 1337 (void) to (int tics) and remove the tics info, dont i?
Last edited by Mr.Man on Mon Jan 27, 2014 4:22 pm, edited 1 time in total.

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

RE: Requesting a timer

#6

Post by Watermelon » Mon Jan 27, 2014 4:37 pm

It'd probably be better if you did

(int ticAmount)


then in the for loop, change

for (int tics = ...)
to
for (int tics = ticAmount; ...)

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

RE: Requesting a timer

#7

Post by Vincent(PDP) » Thu Feb 20, 2014 10:25 am

Mr.Man wrote: That is awesome klofkac, but i have a change of mind (which is probably real dickerish)

I actually want it to support different amounts of time, because it seems allot more efficient, also for a mod i'm making.

EDIT: i might be able to do this myself do.

I just change script 1337 (void) to (int tics) and remove the tics info, dont i?
Already made you a timer Mr.Man .-.
Why can't you trust the scripts i create? :L
You can change the delay too.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Mr.Man
Forum Regular
Posts: 657
Joined: Thu May 09, 2013 7:25 pm

RE: Requesting a timer

#8

Post by Mr.Man » Thu Feb 20, 2014 2:55 pm

Probably because this thread is almost a month old and i made this before you gave it. Look at the date.

User avatar
ibm5155
Addicted to Zandronum
Posts: 1641
Joined: Tue Jun 05, 2012 9:32 pm
Location: Somewhere, over the rainbow

RE: Requesting a timer

#9

Post by ibm5155 » Thu Feb 20, 2014 2:57 pm

Watermelon wrote:
ibm5155 wrote: String function o.o i never knew this one :O
That's because strings are indices so you can make functions that return thanks to StrParam
so it's the same as a pointer xD, hmm, doesn't int do the same thing?
like int i="test";
print(s:i,s:" ",d:i);
it would show the string and the pointer right?
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!

<this post is proof of "Decline">

Post Reply