PLL only tells you when a player left the track/race - not why.
If you want to know the difference between a wrong route/forced spectate and shift+S, you will need to use MSO messages afaik.
If all you need to know is that a player has entered spectate and don't care why, then just use PLL.
if (Msg.EndsWith(" : took the wrong route")) { if (Connections[GetConnIdx(MSO.UCID)].UniqueID == 0) { string Message = Msg; Message.Replace(" : took the wrong route", ""); for (int i = 0; i < Connections.Count; i++) { if (Connections[i].PlayerName == Message) {
// You got the player that took wrong route // Do some stuff.
I spotted a couple of small issues with your code. Firstly there is an easier way to check for system messages, and secondly strings in .NET are immutable, so string.Replace() does not affect the original.
// Check if was a system message. if (MSO.UserType == Enums.MSO_UserType.MSO_SYSTEM && MSO.Msg.EndsWith(" : took the wrong route")) { // Strings in .NET are immutable. string message = MSO.Msg.Replace(" : took the wrong route", "");
for (int i = 0; i < Connections.Count; i++) { if (Connections[i].PlayerName == message) {
// You got the player that took wrong route // Do some stuff.
// Exit from loop early return; } } }
I would probably have written it like this:
if (MSO.UserType == Enums.MSO_UserType.MSO_SYSTEM) { var index = MSO.Msg.IndexOf(" : took the wrong route"); if (index > -1) { var playername = MSO.Msg.Substring(0, index); var connection = Connections.Single(c => c.PlayerName == playername);