#include <a_samp>
new Hour, Minute, timestring[6];//The time converted into a string for the textdraw.
new Text:timetext;//The textdraw
new Ztimer;//Timer ID.
public OnFilterScriptInit()
{
Hour = 12;
Minute = 00;
Ztimer = SetTimer("timeupdate",1000,true);
////////////////////////////////////////////////////////////////////////////////
timetext = TextDrawCreate(547.000000, 23.000000, "00:00");
TextDrawBackgroundColor(timetext, 255);
TextDrawFont(timetext, 3);
TextDrawLetterSize(timetext, 0.599999, 2.100000);
TextDrawColor(timetext, -1);
TextDrawSetOutline(timetext, 1);
TextDrawSetProportional(timetext, 1);
////////////////////////////////////////////////////////////////////////////////
print("\n--------------------------------------");
print(" FzTime by Fusez successfully loaded!");
print(" Time (1 real minute = 1 second ingame)");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
TextDrawDestroy(timetext);
KillTimer(Ztimer);
return 1;
}
forward timeupdate();
public timeupdate()
{
Minute += 01;
if(Minute == 60 && Hour < 24) Hour += 01, Minute = 00;
if(Hour == 24 && Minute == 00) Hour = 00, Minute = 00;
format(timestring, sizeof(timestring), "%02d:%02d", Hour, Minute);
TextDrawSetString(timetext,timestring);
TextDrawShowForAll(timetext);
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i,Hour,Minute);
}
}
Minute += 1;
if(Hour == 24 && Minute == 00) Hour = 00, Minute = 00;
if(Hour == 24 && Minute == 00) Hour = 00, Minute = 00;
format(timestring, sizeof(timestring), "%02d:%02d", Hour, Minute);
TextDrawSetString(timetext,timestring);
TextDrawShowForAll(timetext);
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i,Hour,Minute);
}
pawn Code:
The 3 first lines adds a 0 infront of Minutes Or hours; If any or both of them are less than 10 (2 characters) Otherwise it will look like "2:54" instead of "02:54". The last line checks if both Minutes and Hours are greater than 9 (2 characters each) If this is the case, no 0 is added infront of any of them. Example: 20:43 ----- |
format(timestring, sizeof(timestring), "%02d:%02d", Hour, Minute);