Converting Seconds to M, S
#1

So basically i am creating a gamemode which has a roundtime.
I've set a variable which holds the game, once it reached one, It will end the game.
Now the problem is the timeround var is in milesecond form, The thing i am trying to do is to convert it to Minutes and Seconds, timeround is 1000*60*20 which is 20 minutes, once you divided it to 1000 it will return 1200.

Is it possible to convert mileseconds / seconds to Minutes and Seconds?

EDIT: Another problem, it doesn't update the textdraw, it is stuck on it's last textdraw update.

pawn Код:
// The way how i set my timer.
SetTimer("Heartbeat", 1000, true);

public Heartbeat()
{
    new string[128];
    timeround --;
    new seconds = timeround / 1000;

    format(string, sizeof(string), "Remaining Time: ~r~%d", seconds);
    TextDrawSetString(Textdraw0, string);
    return 1;
}
Reply
#2

For a given integer representing a number of seconds:
  • The number of minutes is given by (numberOfSeconds / 60)
  • The number of remaining seconds is given by (numberOfSeconds % 60)
Your code isn't working because for some reason you've chosen to store "timeround" as a number of milliseconds, but you are only decrementing it by one millisecond every time the timer is called - ie. as the code is currently written, it will take 1,000 seconds for the textdraw to change.

Either change
Код:
timeround--;
to
Код:
timeround = timeround - 1000;
or define "timeround" in seconds rather than milliseconds, which seems far more sensible.

Код:
new timeround = 60*20;
SetTimer("Heartbeat", 1000, true);

public Heartbeat()
{
    new string[128];
    timeround --;

    format(string, sizeof(string), "Remaining Time: ~r~%d:%d", timeround / 60, timeround % 60);
    TextDrawSetString(Textdraw0, string);
    return 1;
}
Reply
#3

Thanks brother, works, didn't know about that, kinda dumb, cheers.
Reply
#4

or you could use CTime plugin
Reply
#5

also you can use this function
you can convert Second to H , M and S !

pawn Код:
stock Sec2HMS(secs, &hours, &minutes, &seconds)
{
  if (secs < 0) return false;
  minutes = secs / 60;
  seconds = secs % 60;
  hours = minutes / 60;
  minutes = minutes % 60;
  return 1;
}

e.g.

new sec = BlaBla /*Your Seconds*/;
new H,M,S,str[28];
Sec2HMS(sec,H,M,S);
format(str,sizeof(str),"%d:%d:%d",H,M,S);
....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)