PDA

View Full Version : Calculating Race Times


Heiko1
25th February 2009, 19:42
Code to read out Best Lap time
=============================




Step by Step:



1. Fill in the private void:

RES_RaceOrQualifyingResult(Packets.IS_RES RES)
{

}
2. Add position "finder".
Till up to ResultNum == 31.

RES_RaceOrQualifyingResult(Packets.IS_RES RES)
{
if (RES.ResultNum == 0) // 0=1, 1=2 .....
{

}
}3. Add some code to display the Informations.
You must remove ButtonID to the ID.
RES_RaceOrQualifyingResult(Packets.IS_RES RES)
{
if (RES.ResultNum == 0) // 0=1, 1=2 .....
{
//Convert ms to Minutes:Seconds:Milliseconds
TimeSpan bestLap = TimeSpan.FromMilliseconds(RES.BTime);
string bestLapStr = string.Format("{0}:{1:00}.{2:000}", bestLap.Minutes, bestLap.Seconds, bestLap.Milliseconds);

//Buttons to display the Informations.
InSim.Send_BTN_CreateButton("^7*", Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_LEFT, 4, 5, 25, 10, 37, 255, 1, false);
InSim.Send_BTN_CreateButton(RES.PName, Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_LEFT, 4, 20, 25, 15, 38, 255, 1, false);
InSim.Send_BTN_CreateButton("^7"+bestLapStr, Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_LEFT, 4, 10, 25, 40, 40, 255, 1, false);
}
} 4. Fill in into your InSim Application.

*WARNING*

* = Needs to be removed to each result number.
THIS IS JUST A PICE OF THE WHOLE CODE! BE HAPPY IF IT WORKS WHEN YOU "COPY|PASTE" IT OTHERWISE TRY TO GET IT WORKING


Thanks to:

DarkTimes = Remember me on TimeSpan method.
Dougie-Lampkin = Gave me Tipps.
Marco1 = Seting up a Server and tested code stuff.



Support at:
- [MSN] Marco-0510@hotmail.de
- [ICQ] 355863550
- [PN] Private Message
- [E-Mail] marco0510@web.de

DarkTimes
25th February 2009, 19:59
To get the milliseconds, use the modulus operator.

string milliseconds = (RES.BTime % 1000).ToString().PadLeft(2, '0');

dougie-lampkin
25th February 2009, 22:03
You could also use the TimeSpan method to convert MS into Days, Hours, Minutes, Seconds, Milliseconds. No examples to hand unfortunately,but it's well documented on t'internets :)

DarkTimes
25th February 2009, 22:04
TimeSpan bestLap = TimeSpan.FromMilliseconds(RES.BTime);

dougie-lampkin
25th February 2009, 22:05
Thanks DarkTimes :shy:

DarkTimes
26th February 2009, 12:08
The easiest way is just to use the System.TimeSpan (http://msdn.microsoft.com/en-us/library/system.timespan.aspx) class.
TimeSpan bestLap = TimeSpan.FromMilliseconds(RES.BTime);
string bestLapStr = string.Format("{0}:{1:00}.{2:000}", bestLap.Minutes, bestLap.Seconds, bestLap.Milliseconds);