I do believe there is one mistake in the code.
Player swap is wrong imo. Let me show you what I mean:
// A player joins the race. If PLID already exists, then player leaves pit.
private void NPL_PlayerJoinsRace(Packets.IS_NPL NPL)
{
bool LeavesPits = AddToPlayersList(NPL); // Update Players[] list
// Your code here
}
// Car was taken over by an other player
private void TOC_PlayerCarTakeOver(Packets.IS_TOC TOC)
{
Players[GetPlyIdx(TOC.OldUCID)].UniqueID = TOC.NewUCID; // Update Players[] list
Players[GetPlyIdx(TOC.OldUCID)].PlayerID = TOC.PLID; // Update Players[] list
// Your code here
}
Players[GetPlyIdx(NEED.PLID.NOT.UCID)]
// A player joins the race. If PLID already exists, then player leaves pit.
private void NPL_PlayerJoinsRace(Packets.IS_NPL NPL)
{
bool LeavesPits = AddToPlayersList(NPL); // Update Players[] list
//And tiny addon
Connections[GetConnIdx(NPL.UCID)].PLID = NPL.PLID;
// Your code here
}
// Car was taken over by an other player
private void TOC_PlayerCarTakeOver(Packets.IS_TOC TOC)
{
try
{
Players[GetPlyIdx(Connections[GetConnIdx(TOC.OldUCID)].PLID)].UniqueID = TOC.NewUCID; // Update Players[] list
Players[GetPlyIdx(Connections[GetConnIdx(TOC.OldUCID)].PLID)].PlayerID = TOC.PLID; // Update Players[] list
//And another tiny addon
Connections[GetConnIdx(TOC.OldUCID)].PLID = TOC.PLID; // Update Connections[] list
// Your code here
}
catch (Exception EX)
{
//If you want to catch exception info do it here... If not -> Remove try and catch codes. Easy ;)
}
}
Of course to make this work you have to add byte(I have added is as an int idk why) PLID in clsConnection and I will leave this easy job to you.