Creating a proper time system
#1

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;
}
Reply
#2

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

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)