SA-MP Forums Archive
possible ? convert seconds to minutes ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: possible ? convert seconds to minutes ? (/showthread.php?tid=192514)



possible ? convert seconds to minutes ? - Rocky Balboa - 22.11.2010

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 ..


Re: possible ? convert seconds to minutes ? - Scenario - 22.11.2010

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.


Re: possible ? convert seconds to minutes ? - The_Gangstas - 22.11.2010

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);



Re: possible ? convert seconds to minutes ? - Rocky Balboa - 22.11.2010

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...


Re: possible ? convert seconds to minutes ? - Scenario - 22.11.2010

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


Re: possible ? convert seconds to minutes ? - The_Gangstas - 22.11.2010

i already posted it..


Re: possible ? convert seconds to minutes ? - Rocky Balboa - 22.11.2010

alright, it works fine


Re: possible ? convert seconds to minutes ? - emre.aydin - 16.03.2012

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);



Re: possible ? convert seconds to minutes ? - Babul - 16.03.2012

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