The online racing simulator
Need help with creating a List
(5 posts, started )
Need help with creating a List
Hello guys, this is my first post

Im using The newest LFS_External version and C#.

My problem is:

I want to create a userlist like

1. Stefan | 55Pts.
2. ABC | 25Pts.
3. TEST | 22Pts.
4....
But i dont know how.....

What ive got:

Ive got the code to find out the best LapTime from all racers on the server.
Ok, I think i can make the same with Points on Server/Database.
In this code ive got only the BestTime on the server, but how to "calculate" now the 2nd BestTime

Heres the code for BestTime in the server/ of the race.
private void RES_RaceOrQualifyingResult(Packets.IS_RES RES)
{
byte UCID = Players[GetPlyIdx(RES.PLID)].UniqueID;

TimeSpan bestLap = TimeSpan.FromMilliseconds(RES.TTime);
string bestLapStr = string.Format("{0}:{1:000}.{2:00}", bestLap.Minutes, bestLap.Seconds, bestLap.Milliseconds);
if (RES.TTime <= BestLapTime)
{
BestTime = bestLapStr;//for BestTime Button
BestLapTime = Convert.ToInt32(RES.TTime); // for checking the best time
BestDriver = RES.UName;
}

InSim.Send_BTN_CreateButton("^0Best Lap Time: ^2" + BestTime, Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_LIGHT, 7, 62, 0, 69, 1, 255, 1, false);
}

The other stuff like the problem with points will be sloved if i know how to get 2nd BestTime 3th BestTime 4th BestTime 5....

I hope you can help me with that problem

Cheers Stefan Renk
I would add the IS_RES packets to a list and then sort them by the TTime.

private List<Packets.IS_RES> results = new List<Packets.IS_RES>();

private void RES_RaceOrQualifyingResult(Packets.IS_RES RES)
{
// Add packet to the list.
results.Add(RES);
}

Then to sort it you can do this.

private void SortResults()
{
// Sort results by TTime.
results.Sort(CompareResultsByTime);
}

private int CompareResultsByTime(Packets.IS_RES a, Packets.IS_RES b)
{
return a.TTime.CompareTo(b.TTime);
}

Now you have a list in order of the best time than you can loop through.

foreach (Packets.IS_RES result in results)
{
if (result.ResultNum == 0)
{
// Winner etc..
}
}

Thanks alot.

it works
Just a nitpick, you can omit the "new Comparison<Packets.IS_RES>"
private void SortResults()
{
// Sort results by TTime.
results.Sort(CompareResults);
}

I also like to give the comparison methods more descriptive names, like "ByTime" for example, to make the code more readable.
okey thanks alot again!
ur the best

Need help with creating a List
(5 posts, started )
FGED GREDG RDFGDR GSFDG