Clock system
#1

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?
Reply
#2

Please wait! Guessing your code is in progress...
Reply
#3

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

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

Because seconds' text is smaller.
Reply
#6

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

Thx, but the same.
Reply
#8

Quote:
Originally Posted by kamiliuxliuxliux
Посмотреть сообщение
Thx, but the same.
What do you get? i don't see any problems in it!
Reply
#9

I said, that because of server delay my timer don't repeat by 1000 miliseconds, it does it by about ~1050 miliseconds.
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)