Page 1 of 1

Requesting a timer

Posted: Sun Jan 26, 2014 12:36 am
by Mr.Man
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.

RE: Requesting a timer

Posted: Mon Jan 27, 2014 10:13 am
by Klofkac
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.

RE: Requesting a timer

Posted: Mon Jan 27, 2014 12:22 pm
by ibm5155
String function o.o i never knew this one :O

RE: Requesting a timer

Posted: Mon Jan 27, 2014 1:05 pm
by Watermelon
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

RE: Requesting a timer

Posted: Mon Jan 27, 2014 4:13 pm
by Mr.Man
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?

RE: Requesting a timer

Posted: Mon Jan 27, 2014 4:37 pm
by Watermelon
It'd probably be better if you did

(int ticAmount)


then in the for loop, change

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

RE: Requesting a timer

Posted: Thu Feb 20, 2014 10:25 am
by Vincent(PDP)
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.

RE: Requesting a timer

Posted: Thu Feb 20, 2014 2:55 pm
by Mr.Man
Probably because this thread is almost a month old and i made this before you gave it. Look at the date.

RE: Requesting a timer

Posted: Thu Feb 20, 2014 2:57 pm
by ibm5155
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?