Race Timer..
#1

Hi,

So eventually i want to make a Top Times system however im trying to get the timer to work first.

here is my script

TOP
Код:
 new GameTime[MAX_PLAYERS];
Under the GO timer (Working)
Код:
public go(playerid)
{
       for (new i = 0; i != MAX_PLAYERS; ++i)
       {
        GameTime[i]=tickcount();
        }
       return 1;
}
Then at the end of the race track

Код:
GameTime[playerid]=GetTickCount();

		    new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
	    	    GetPlayerName(playerid, name, sizeof(name));
	  	    format(string,sizeof(string), "%s Has Reached The End [Time: %s ]",name, GameTime);
	  	    SendClientMessage(playerid, -1, string);
Now the problem i have is the message comes up like

"Little Has Reached The End [Time]:Aa♀-♥6○5♦5•W"

It says the name okay but the Time just comes up as random symbols every time... I have not a clue what i am doing wrong i simply want it to come up with the time it took to complete the map.

Any help appreciated!
Reply
#2

At the end of the race track you need to get the current unix timestamp and subtract with the old one:
pawn Код:
GameTime[playerid] = GetTickCount() - GameTime[playerid];

new string[60];
GetPlayerName(playerid, string, 21);
format(string, sizeof (string), "%s Has Reached The End [Time: %s ]", string, ConvertRaceTime(GameTime[playerid]));
SendClientMessageToAll(-1, string); // to everyone or limit it to the races only. The message only to the player who just finished is kind of pointless.
pawn Код:
stock ConvertRaceTime(milliseconds)
{
    new
        result[10],
        minutes,
        seconds;

    minutes = milliseconds / 60000;
    seconds = ((milliseconds /1000 ) % 60);
    milliseconds = milliseconds % 1000;

    format(result, sizeof (result), "%i:%02i.%03i", minutes, seconds, milliseconds);
    return result;
}
The time will be minutes:seconds.milliseconds (an example: 1:51.468).

About the top times, you can save the unix timestamp and with SQL will be very easy to select them order by ASC.
Reply
#3

Works, thanks for sorting out my script aswell

Thanks so much ) Repped
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)