possible ? convert seconds to minutes ?
#1

is there a function , to turn seconds into minutes and seconds ? lik if you have 321 seconds, to turn them into ,
5.35 , 5 minutes ad 35 seconds .. so can anyone tell me how to start it off? just head me to the right direction ..
Reply
#2

Let's do some math, shall we?

How many seconds in a minute? 60

How many seconds in 5 minutes and 30 seconds? Well... 5*60 = 300 + 30 = 330.

So now you can instead use 330 seconds, rather then needing to to make a bunch of pointless code.
Reply
#3

pawn Code:
TimeConvert(time) {
    new minutes;
    new seconds;
    new string[128];
    if(time > 59){
        minutes = floatround(time/60);
        seconds = floatround(time - minutes*60);
        if(seconds>9)format(string,sizeof(string),"%d:%d",minutes,seconds);
        else format(string,sizeof(string),"%d:0%d",minutes,seconds);
    }
    else{
        seconds = floatround(time);
        if(seconds>9)format(string,sizeof(string),"0:%d",seconds);
        else format(string,sizeof(string),"0:0%d",seconds);
    }
    return string;
}
example
pawn Code:
format(string, sizeof(string), "~w~Jail Time:~g~~h~%s", TimeConvert(PlayerInfo[i][PrisonTime]));
                TextDrawSetString(JailTimeText[i],string);
Reply
#4

Well, i know, but i want the players to see the mins and hte seconds instead of looking at some seconds.. for going out of jail...
Reply
#5

Did you mean so when you output a string instead of seconds, you will get the actual value?
Reply
#6

i already posted it..
Reply
#7

alright, it works fine
Reply
#8

Yes but you don't need

pawn Code:
if(seconds>9) format(string,sizeof(string),"%d:%d",minutes,seconds);
else format(string,sizeof(string),"%d:0%d",minutes,seconds);
this. It does exactly the same thing and faster.

pawn Code:
format(string,sizeof(string),"%d:%02d",minutes,seconds);
Reply
#9

Code:
22/11/2010
16/03/2012
argh.. i had that topic in my favorites, in order to bump it tomorrow ><
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)