stopwatch [ Please need help! ]
#1

I have a command which starts a stop watch, and checkpoint which stops it. When he stops to a chat writes time. There was a huge need to make so that seconds and milliseconds were considered and removed (that is instead of 20 seconds => 20.16 sec / 20.04 sec / 20.65 sec). Prompt, it is possible such to realize?

PLS HELP!!!! Sorry for my english..

Код:
forward test(playerid);
new timer;
new count = 0;
forward Countdown2(playerid);
new countdown2[MAX_PLAYERS];
Код:
public OnFilterScriptInit()
{
SetTimer("Countdown2",1000,1);
return 1;
}
Код:
if (strcmp("/start", cmdtext, true, 10) == 0)
{
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)return SendClientMessage(playerid, 0xFF0000AA,"[INFO]: Вы должны быть в машине");
new Float: X, Float:Y, Float: Z;
GetPlayerPos(playerid, X, Y, Z);
countdown2[playerid]=6;
for(new i=0;i<MAX_PLAYERS;i++)
if(IsPlayerInRangeOfPoint(i,15.0,X,Y,Z))
{
if(GetPlayerState(i) != PLAYER_STATE_ONFOOT && countdown2[i]==-1)countdown2[i]=6;
}
return 1;
}
Код:
public OnPlayerEnterRaceCheckpoint(playerid)
{
DisablePlayerRaceCheckpoint(playerid);
new str[128];
format(str,sizeof(str),"Время прохождения: %d сек ",count);
SendClientMessage(playerid, 0xFFFFFF, str);}
KillTimer(timer);
return 0;
}
Код:
public test(playerid)
{
    count++;
	count1++; //Use ++ for counting forwards, and -- for counting the seconds backwards
    return 1;
}
Код:
public Countdown2()
{
	for(new i=0;i<MAX_PLAYERS;i++)
	if(IsPlayerConnected(i))
	{
			if(countdown2[i]>0)
			{
				countdown2[i]-=1;
				new str[6];
				format(str,6,"...%d",countdown2[i]);
				GameTextForPlayer(i,str,950,4);
				PlayerPlaySound(i,1056,0.0,0.0,0.0);
				if(countdown2[i]<4)TogglePlayerControllable(i,0);
			}
			if(countdown2[i]==0)
			{
			    TogglePlayerControllable(i,1);
				GameTextForPlayer(i,"~r~GO GO GO",500,4);
				PlayerPlaySound(i,1057,0.0,0.0,0.0);
				SetPlayerRaceCheckpoint(i,1,-431.5638,1409.8419,32.1069,0,0,0,5.0);
				timer = SetTimerEx("test", 1000, 1, "d",i);} 
				countdown2[i]=-1;
			}
	}
}
Reply
#2

Please help
Reply
#3

You can create a new variable at the top of the script for each player which stores the tickcount at the moment the player starts racing:
pawn Код:
new StartTick[MAX_PLAYERS];
Then when the countdown is done, and the GoGoGo-text is showing you store the tickcount:
pawn Код:
StartTick[i] = GetTickCount();
When the player reaches the checkpoint you create a new temporarily variable and get the current tick count, then calculate the minutes/seconds/milliseconds:

pawn Код:
//OnPlayerEnterRaceCheckpoint
new RaceTime = (GetTickCount() - StartTick[playerid]);
new str[128];
format(str, 128, "You finished in %02d:%02d.%03d", RaceTime/60000, (RaceTime%60000)/1000, (RaceTime%1000));
SendClientMessage(playerid, -1, str);
You don't need that timer (test(playerid))
Reply
#4

Quote:
Originally Posted by Schneider
Посмотреть сообщение
You can create a new variable at the top of the script for each player which stores the tickcount at the moment the player starts racing:
pawn Код:
new StartTick[MAX_PLAYERS];
Then when the countdown is done, and the GoGoGo-text is showing you store the tickcount:
pawn Код:
StartTick[i] = GetTickCount();
When the player reaches the checkpoint you create a new temporarily variable and get the current tick count, then calculate the minutes/seconds/milliseconds:

pawn Код:
//OnPlayerEnterRaceCheckpoint
new RaceTime = (GetTickCount() - StartTick[playerid]);
new str[128];
format(str, 128, "You finished in %02d:%02d.%03d", RaceTime/60000, (RaceTime%60000)/1000, (RaceTime%1000));
SendClientMessage(playerid, -1, str);
You don't need that timer (test(playerid))
You are god!! Thx u!!! it working!! THXX!!!!!!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)