Converting seconds into Days/Hours/Minutes
#8

Hi

This public function work ... you can paste it "anywhere" in your script.

The Function:
pawn Код:
forward Sec2DayMinSec(InputSec, OutputString[], OutputStringLen);
public Sec2DayMinSec(InputSec, OutputString[], OutputStringLen)
{
    new
      Days,
      Hours,
      Mins,
      Secs;
     
    Days = floatround((InputSec / 86400), floatround_floor); // get Days
    Secs = (InputSec - (Days * 86400));// remove days from total seconds
    Hours = floatround((Secs / 3600), floatround_floor); // get Hours
    Secs = (Secs - (Hours * 3600)); // remove Hours from secs
    Mins = floatround((Secs / 60), floatround_floor);// get Mins
    Secs = (Secs - (Mins * 60));// remove Mins from secs, whats left is seconds

    format(OutputString, OutputStringLen,
        "%i days %i hours %i minutes and %i seconds",
      Days, Hours, Mins, Secs);
    return 1;
}
I tested the function using this in OnGameModeInit and/or OnFilterScriptInit
pawn Код:
new TestString[128];// string to store the output (128 is my fav number for that)
    Sec2DayMinSec(120, TestString, sizeof(TestString));// gettin the string for 120 seconds
    print(TestString);// printing the string
    Sec2DayMinSec(120654789, TestString, sizeof(TestString));// gettin the string for 120654789 seconds
    print(TestString);// printing...
Good Luck !
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)