How do I count the time? [SERVER]
#1

Well, I think everyone already seen a counting time on a server, at least once. When a race is over, or a time between messages (avoid flood). The question is: How do I count this time? Like Showing the seconds left until the certain period is over. On Gamerx, there's a house buyable, which shows: Time left to buy 26 minutes. And the time counts, and changes
Reply
#2

Easy, use some variables to count mins&time.
Reply
#3

You could use getTickCount ( ) too.
Reply
#4

Quote:
Originally Posted by [FU]Victious
Посмотреть сообщение
Easy, use some variables to count mins&time.
Give me a example please. Most of counting times I've seen were like: 5.67 seconds
Код:
Player %s ended the race in %d.00 seconds
Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
You could use getTickCount ( ) too.
I tried with a SetTimer together, and didn't count =S
Reply
#5

GetTickCount. no doubt. it doesnt need a timer, and its only 2 or 3 commands to calculate the precise time in MS. no timer will do that more precise.
Код:
new TimeOld=GetTickCount();
//your huge code
new TimeNew=GetTickCount()-TimeOld;
Reply
#6

Dude, I just made a command:
pawn Код:
dcmd_range(playerid, params[])
{
   #pragma unused params
   PlayerRange(playerid);
   SendClientMessage(playerid, azul, "Time is counting from now...");
   SetTimer("toxic", 5000, false);
   TimeOld = GetTickCount();
   return 1;
}

And a callback
pawn Код:
public toxic(playerid)
{
   new string[128];
   TimeNew=GetTickCount()-TimeOld
   format(string,sizeof(string),"The time were ran into: %f",TimeNew-TimeOld);
   return SendClientMessage(playerid, color, string);
}
I tried this using a timer as "example", and showed 0.0000.. and on %d, 5761 (another example). Just give me a example of how to count this time, with a timer, and how to kill this time of keep counting =X
Reply
#7

pawn Код:
forward Round();
public Round()
{
    if(GameSeconds || GameMinutes)
    {
        GameSeconds--;
        if(GameSeconds <= -1)
        {
            GameMinutes--;
            GameSeconds=59;
        }
        new TimeString[14];
        format(TimeString,sizeof(TimeString),"%02d:%02d",GameMinutes,GameSeconds);
        TextDrawSetString(rclock,TimeString);
        if(GameMinutes == 0 && GameSeconds == 0)
        {
            for(new i; i < MAX_PLAYERS; i++)
            {
                GameTextForAll("~r~Round Ended!",5000,3);
                TogglePlayerControllable(i,0);
                SH = SetTimer("ShowHonours",1000,true);
                KillTimer(rcount);
            }
        }
    }
    return 1;
}
Set the timer to 1second, delete the unnecessary stuff, it was from my GM. :P
Reply
#8

You could use something like this:
Example of usage
pawn Код:
stock GetSecondsBetweenAction(action) // By [03]Garsino
{
    return floatround(floatdiv((GetTickCount() - action), 1000), floatround_tozero);
}
Reply
#9

Use

pawn Код:
stock TimeConvert(seconds)
{
    new tmp[16];
    new minutes = floatround(seconds/60);
    seconds -= minutes*60;
    format(tmp, sizeof(tmp), "%d:%02d", minutes, seconds);
    return tmp;
}
For counting times..
Reply
#10

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
You could use something like this:
Example of usage
pawn Код:
stock GetSecondsBetweenAction(action) // By [03]Garsino
{
    return floatround(floatdiv((GetTickCount() - action), 1000), floatround_tozero);
}
Thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)