Clock 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: Clock system (
/showthread.php?tid=532316)
Clock system -
kamiliuxliuxliux - 17.08.2014
I've just created clock system (hour : min : sec). Well, under OnGameModeInit I start a timer for 1 sec and repeating and blah blah blah... Everything works fine, but only one problem sucks. Let's say, this is seconds counting: 05,06,07,08,09,10,12,13,14,15,17... 1 second is missing and I know it's because of server delay. Anyway is there any way to prevent this?
Re: Clock system -
Juvanii - 17.08.2014
Please wait! Guessing your code is in progress...
Re: Clock system -
kamiliuxliuxliux - 17.08.2014
Nope.
pawn Код:
SetTimer("Time",1000,true);
public Time()
{
new h,m,s;
gettime(h,m,s);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(pInfo[i][clock] == 1)
{
new hm[20],sc[10];
format(hm,10,"%02i:%02i",h,m);
format(sc,10,":%02i",s);
PlayerTextDrawSetString(i, clock[i],hm);
PlayerTextDrawSetString(i, clock_sec[i],sc);
}
}
return 1;
}
Re: Clock system -
Juvanii - 17.08.2014
Why don't you use it like:
pawn Код:
public Time()
{
new h,m,s;
gettime(h,m,s);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(pInfo[i][clock] == 1)
{
new string[50];
format(string,sizeof(string),"%02i:%02i:%02i",h,m,s);
TextDrawSetString(clock[i],string);
TextDrawShowForPlayer(playerid, clock[i]);
}
}
return 1;
}
Re: Clock system -
kamiliuxliuxliux - 17.08.2014
Because seconds' text is smaller.
Re: Clock system -
Juvanii - 17.08.2014
pawn Код:
public Time()
{
new h,m,s;
gettime(h,m,s);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(pInfo[i][clock] == 1)
{
new string[50];
format(string,sizeof(string),"%02i:%02i",h,m);
TextDrawSetString(clock[i],string);
TextDrawShowForPlayer(playerid, clock[i]);
format(string,sizeof(string),":%02i",s);
TextDrawSetString(clock_sec[i],string);
TextDrawShowForPlayer(clock_sec[i],string);
}
}
return 1;
}
Re: Clock system -
kamiliuxliuxliux - 17.08.2014
Thx, but the same.
Re: Clock system -
Juvanii - 17.08.2014
Quote:
Originally Posted by kamiliuxliuxliux
Thx, but the same.
|
What do you get? i don't see any problems in it!
Re: Clock system -
kamiliuxliuxliux - 17.08.2014
I said, that because of server delay my timer don't repeat by 1000 miliseconds, it does it by about ~1050 miliseconds.
Re: Clock system -
Threshold - 17.08.2014
That's normal and you won't get it any better. Another thing you can do to make sure nothing is skipped is the following:
pawn Код:
public OnGameModeInit()
{
SetTimer("Time", 1000, false);
return 1;
}
forward Time();
public Time()
{
new h, m, s;
gettime(h, m, s);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(!pInfo[i][clock]) continue;
new fstr[6];
format(fstr, sizeof(fstr), "%02i:%02i", h, m);
PlayerTextDrawSetString(i, clock[i], fstr);
format(fstr, sizeof(fstr), ":%02i", s);
PlayerTextDrawSetString(i, clock_sec[i], fstr);
}
SetTimer("Time", 1000, false);
return 1;
}
I would also recommend using y_timers.