SA-MP Forums Archive
Time - Hour and minute - 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: Time - Hour and minute (/showthread.php?tid=653589)



Time - Hour and minute - KamilPolska - 07.05.2018

Will anyone help me fix the error?
The hour is showing up 15:08, 15:09, 15:, 15:11.
"15:10" did not show up. only "15:"

Код:
new Minute;                            
new Hour;                                      

public OnGameModeInit() 
{
    Minute= 0;
    Hour= 5;
    SetTimer("TimeU",100,true);
    return 1; 
} 

forward TimeU();
public TimeU()
{
    new string[7];                             
    Minute+=1;                                      
    if(Minute==60) {                                
        Minute=00;
        Hour+=1;                                  
    }
    if(Hour==24) {
        Minute=00;
        Hour=0;
    }
    if(Minute<10) {                                 
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
    if(Minute>10) {
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
    if(Hour<10) {
                                                  
        format(string,sizeof(string),"0%d:%02d",Hour,Minute);
    }
    for(new i; i<MAX_PLAYERS; i++) {              
        if(IsPlayerConnected(i)) {              
            SetPlayerTime(i,Hour,Minute);           
        }
    }
    TextDrawSetString(TimeTD,string);
    return 1;
}



Re: Time - Hour and minute - NaS - 08.05.2018

Код:
if(Minute<10) {                                 
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
    if(Minute>10) {
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
You are first checking if minute is smaller than ten, then checking if it is greater than ten. Ten however is exactly ten, so it will not be considered (it isn't greater nor lower).

So you will need to include ten into the later check (change it to "Minute >= 10").

Or just use:

Код:
format(string,sizeof(string),"%02d:%02d",Hour,Minute);



Re: Time - Hour and minute - TaiRinsuru - 08.05.2018

Also its 1000, not 100
pawn Код:
SetTimer("TimeU",1000,true);