[Help]Printing/Getting lap time. -
Ronaldo_raul™ - 12.07.2012
Hello, I have a little DD map and I want to make a lap timing system so when a player finishes the DD map and pickup a particular pickup the time he took to reach that point will be printed or maybe be just send as a client message. I can't get this done. I have no idea upon this. Can someone help me ?
Thanks in advance.
NOTE: Please just don't copy paste any code. Explain it please. I really want to understand this mechanism.
Regards,
Ronaldo_raul
Re: [Help]Printing/Getting lap time. -
clarencecuzz - 12.07.2012
There is one, but it's only accurate to the second.
pawn Код:
#include <a_samp> //Main include for all SAMP functions
new Time[MAX_PLAYERS]; //We will use this to save our time
new Count[MAX_PLAYERS]; //Use this so we can kill the timer when we want.
public OnPlayerConnect(playerid)
{
Time[playerid] = 0; //Makes sure the player joins with 0 seconds to their name.
return 1;
}
//Put your "PLAYER STARTS RACE" code here
{
Count[playerid] = SetTimerEx("Timer", 200, true, "i", playerid); //Start the timer (Script starts counting time)
}
forward Timer(playerid); //Make sure you introduce the timer
public Timer(playerid) //Start defining what the timer will do.
{
Time[playerid] + 0.2 //Will add 0.2 seconds to the timer every 20 milliseconds.
return 1; //Stop the code from continuing.
}
//Put your "PLAYER FINISHES RACE" here
{
KillTimer(Count[playerid]);
new string[256];
new PlayersName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayersName, MAX_PLAYER_NAME);
format(string, sizeof(string), "%s has finished the lap in %.2f seconds!", PlayersName, Time[playerid]); //%.2f shows a number to 2 decimal places.
SendClientMessageToAll(0x00FF00AA, string);
return 1;
}
NOTE: NOT TESTED!!
Re: [Help]Printing/Getting lap time. -
Ronaldo_raul™ - 13.07.2012
pawn Код:
(21767) : warning 215: expression has no effect
Line 21767 is
Re: [Help]Printing/Getting lap time. -
Roko_foko - 13.07.2012
Quote:
Originally Posted by Ronaldo_raul™
pawn Код:
(21767) : warning 215: expression has no effect
Line 21767 is
|
Re: [Help]Printing/Getting lap time. -
Ronaldo_raul™ - 13.07.2012
Quote:
Originally Posted by clarencecuzz
There is one, but it's only accurate to the second.
pawn Код:
#include <a_samp> //Main include for all SAMP functions new Time[MAX_PLAYERS]; //We will use this to save our time new Count[MAX_PLAYERS]; //Use this so we can kill the timer when we want.
public OnPlayerConnect(playerid) { Time[playerid] = 0; //Makes sure the player joins with 0 seconds to their name. return 1; }
//Put your "PLAYER STARTS RACE" code here { Count[playerid] = SetTimerEx("Timer", 200, true, "i", playerid); //Start the timer (Script starts counting time) }
forward Timer(playerid); //Make sure you introduce the timer public Timer(playerid) //Start defining what the timer will do. { Time[playerid] + 0.2 //Will add 0.2 seconds to the timer every 20 milliseconds. return 1; //Stop the code from continuing. }
//Put your "PLAYER FINISHES RACE" here { KillTimer(Count[playerid]); new string[256]; new PlayersName[MAX_PLAYER_NAME]; GetPlayerName(playerid, PlayersName, MAX_PLAYER_NAME); format(string, sizeof(string), "%s has finished the lap in %.2f seconds!", PlayersName, Time[playerid]); //%.2f shows a number to 2 decimal places. SendClientMessageToAll(0x00FF00AA, string); return 1; }
NOTE: NOT TESTED!!
|
Woaw, Thanks but this doesn't works.
Quote:
Originally Posted by Roko_foko
|
Thank you. Help ?
Re: [Help]Printing/Getting lap time. -
Ronaldo_raul™ - 14.07.2012
Bump.
Anyone ?
Re: [Help]Printing/Getting lap time. -
leonardo1434 - 14.07.2012
Just made it quickly.
pawn Код:
CMD:startlap(playerid,params[])
{
SetPVarInt(playerid,"lap",gettime()); //setting a var and stocking his value.
return 1;
}
CMD:finishlap(playerid,params[])
{
static string[50];
SetPVarInt(playerid,"totalseconds",gettime() - GetPVarInt(playerid,"lap")); // setting the var second + getting the actul time - var lap which is the time that started the lap.
SetPVarInt(playerid,"seconds",GetPVarInt(playerid,"totalseconds")% 60);// setting the var seconds
SetPVarInt(playerid,"minutes",(GetPVarInt(playerid,"totalseconds") - GetPVarInt(playerid,"seconds"))/60);//setting the var minutes, which is the total of seconds - seconds.
format(string,50,"You have finished in %i minutes and %i seconds",GetPVarInt(playerid,"minutes"),GetPVarInt(playerid,"seconds")); // formating the string
SendClientMessage(playerid,-1,string);//sending to the playerid.
return 1;
}
Re: [Help]Printing/Getting lap time. -
Ronaldo_raul™ - 15.07.2012
Quote:
Originally Posted by leonardo1434
Just made it quickly.
pawn Код:
CMD:startlap(playerid,params[]) { SetPVarInt(playerid,"lap",gettime()); //setting a var and stocking his value. return 1; } CMD:finishlap(playerid,params[]) { static string[50]; SetPVarInt(playerid,"totalseconds",gettime() - GetPVarInt(playerid,"lap")); // setting the var second + getting the actul time - var lap which is the time that started the lap. SetPVarInt(playerid,"seconds",GetPVarInt(playerid,"totalseconds")% 60);// setting the var seconds SetPVarInt(playerid,"minutes",(GetPVarInt(playerid,"totalseconds") - GetPVarInt(playerid,"seconds"))/60);//setting the var minutes, which is the total of seconds - seconds. format(string,50,"You have finished in %i minutes and %i seconds",GetPVarInt(playerid,"minutes"),GetPVarInt(playerid,"seconds")); // formating the string SendClientMessage(playerid,-1,string);//sending to the playerid. return 1; }
|
PVars!
Thanks gentlemen, that worked and I learned how this works
Thank you once again.
+reps for ya all.
Re: [Help]Printing/Getting lap time. -
Niko_boy - 15.07.2012
Time[playerid] + 0.2
this will not work as you created it as a variable / integer thought it should be a float
so instead of
pawn Код:
new Time[MAX_PLAYERS]; //We will use this to save our time
use
pawn Код:
new Float:Time[MAX_PLAYERS]; //We will use this to save our time !! better :)
EDIT: now seen Leonardo's Code which is good one using no timer
Re: [Help]Printing/Getting lap time. -
Ronaldo_raul™ - 15.07.2012
Quote:
Originally Posted by Niko_boy
Time[playerid] + 0.2
this will not work as you created it as a variable / integer thought it should be a float
so instead of
pawn Код:
new Time[MAX_PLAYERS]; //We will use this to save our time
use
pawn Код:
new Float:Time[MAX_PLAYERS]; //We will use this to save our time !! better :)
EDIT: now seen Leonardo's Code which is good one using no timer
|
LoL