Race Timer.. - 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: Race Timer.. (
/showthread.php?tid=508373)
Race Timer.. -
KingyKings - 21.04.2014
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!
Re: Race Timer.. -
Konstantinos - 21.04.2014
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.
Re: Race Timer.. -
KingyKings - 21.04.2014
Works, thanks for sorting out my script aswell
Thanks so much
) Repped