[Help]Printing/Getting lap time.
#1

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
Reply
#2

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!!
Reply
#3

pawn Код:
(21767) : warning 215: expression has no effect
Line 21767 is
pawn Код:
Time[playerid]+0.2 ;
Reply
#4

Quote:
Originally Posted by Ronaldo_raul™
Посмотреть сообщение
pawn Код:
(21767) : warning 215: expression has no effect
Line 21767 is
pawn Код:
Time[playerid]+0.2 ;
pawn Код:
Time[playerid]+=0.2 ;
Reply
#5

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
Посмотреть сообщение
pawn Код:
Time[playerid]+=0.2 ;
Thank you. Help ?
Reply
#6

Bump.
Anyone ?
Reply
#7

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;
}
Reply
#8

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.
Reply
#9

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
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)