Clock. - 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: Clock. (
/showthread.php?tid=353331)
Clock. -
iGetty - 22.06.2012
Hello there, I have a clock that I use and I seem to have a bit of a problem.
When the hour is below 10 and the minutes and seconds are below 10, it shows like this:
1:2:8
I want it to show like this:
01:02:08
It's not major, but it's just to make the display nicer looking.
Here is my current code:
pawn Код:
public ClockUpdate()
{
for(new x = 0; x < MAX_PLAYERS; x++)
{
if(Logged[x] == 1)
{
new string[12];
Second++;
format(string, sizeof(string), "%i:%i:%i", Hour, Minute, Second);
if(Hour < 10)
{
format(string, sizeof(string), "0%i:%i:%i", Hour, Minute, Second);
}
if(Minute < 10)
{
format(string, sizeof(string), "%i:0%i:%i", Hour, Minute, Second);
}
if(Second < 10)
{
format(string, sizeof(string), "%i:%i:0%i", Hour, Minute, Second);
}
if(Second == 60)
{
if(Minute == 59)
{
if(Hour == 23)
{
Hour = 0;
Minute = 0;
Second = 0;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(Player[i][Faction] == 0)
{
SendClientMessage(i, ORANGE, "Your check is ready to be picked up. Please head to the Job Center to get it.");
}
else
{
SendClientMessage(i, ORANGE, "Your check is ready to be picked up. Please head to your headquarters to get it.");
}
}
}
format(string, sizeof(string), "0%i:0%i:0%i", Hour, Minute, Second);
}
else
{
Hour ++;
Minute = 0;
Second = 0;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(Player[i][Faction] == 0)
{
SendClientMessage(i, ORANGE, "Your check is ready to be picked up. Please head to the Job Center to get it.");
}
else
{
SendClientMessage(i, ORANGE, "Your check is ready to be picked up. Please head to your headquarters to get it.");
}
}
}
format(string, sizeof(string), "%i:0%i:0%i", Hour, Minute, Second);
}
}
else
{
Minute ++;
Second = 0;
format(string, sizeof(string), "%i:%i:0%i", Hour, Minute, Second);
}
}
TextDrawSetString(Clock, string);
SetWorldTime(Hour);
}
}
return 1;
}
Thank you guys!
Re: Clock. -
Joe Staff - 22.06.2012
Format has a function designed for this.
pawn Код:
format(timestr,sizeof timestr,"Current Time: %02i:%02i", hours, minutes);
The '0' is used to replace the gap of '2' decimal places with 0s.
Re: Clock. -
iGetty - 22.06.2012
So just replace all of that code with that?
Re: Clock. -
Joe Staff - 22.06.2012
pretty much
Re: Clock. -
iGetty - 22.06.2012
Thanks Joe!
Reputation has been added for you