SA-MP Forums Archive
Creating a proper time system - 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: Creating a proper time system (/showthread.php?tid=376564)



Creating a proper time system - 2KY - 10.09.2012

I've created a functioning time system, problem is, when it's say.. 7:04 PM, it will read: "7:4 PM", how would I add that other 0 into my current system?

pawn Код:
public UpdateTime ( )
{
    new
        str [ 24 ];

    TimeMin ++;
    if( TimeMin == 60 )
    {
        TimeHour ++;
        TimeMin = 00;
        if( strcmp( TimeSuffix, "A.M", false ) == 0 )
        {
            SetWorldTime( TimeHour );
        }
        else if( strcmp( TimeSuffix, "P.M", false ) == 0 )
        {
            SetWorldTime( TimeHour + 10 );
        }
    }

    if( TimeHour > 12 && strcmp( TimeSuffix, "A.M", false ) == 0 )
    {
        TimeHour = 1, TimeMin = 00;
        TimeSuffix = "P.M";
    }
    else if( TimeHour > 12 && strcmp( TimeSuffix, "P.M", false ) == 0 )
    {
        TimeHour = 1, TimeMin = 00;
        TimeSuffix = "A.M";
    }
   
    format( str, 24, "%d:%d %s", TimeHour, TimeMin, TimeSuffix );
    TextDrawSetString( TimeTag, str );
   
    for( new u; u < MAX_PLAYERS; u ++ )
    {
        if( plLoggedIn [ u ] == true )
        {
            TextDrawHideForPlayer( u, TimeTag );
            TextDrawShowForPlayer( u, TimeTag );
        }
    }
    return true;
}



Re: Creating a proper time system - Roko_foko - 10.09.2012

format( str, 24, "%d:%d %s", TimeHour, TimeMin, TimeSuffix );
to
format( str, 24, "%02d:%02d %s", TimeHour, TimeMin, TimeSuffix );
Hope I helped


Re: Creating a proper time system - 2KY - 10.09.2012

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
format( str, 24, "%d:%d %s", TimeHour, TimeMin, TimeSuffix );
to
format( str, 24, "%02d:%02d %s", TimeHour, TimeMin, TimeSuffix );
Hope I helped
Easy and quick, thanks!