From f6f81e84df4c05eefec612c1858a991fdff64544 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 11 Aug 2016 20:13:10 +0200 Subject: [PATCH] Fix Lua API returning wrong player info The Lua API would return wrong information on player fields such as the team or faction when it was changed in the lobby. It referenced fields on the PlayerReference, which are pretty much read-only and don't get changed by the lobby. --- .../Scripting/Properties/PlayerProperties.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs index f2601e8286..bbe7812119 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs @@ -39,18 +39,25 @@ namespace OpenRA.Mods.Common.Scripting get { Game.Debug("The property `PlayerProperties.Race` is deprecated! Use `PlayerProperties.Faction` instead!"); - return Player.PlayerReference.Faction; + return Player.Faction.InternalName; } } [Desc("The player's faction.")] - public string Faction { get { return Player.PlayerReference.Faction; } } + public string Faction { get { return Player.Faction.InternalName; } } [Desc("The player's spawnpoint ID.")] public int Spawn { get { return Player.SpawnPoint; } } [Desc("The player's team ID.")] - public int Team { get { return Player.PlayerReference.Team; } } + public int Team + { + get + { + var c = Player.World.LobbyInfo.Clients[Player.ClientIndex]; + return c != null ? c.Team : 0; + } + } [Desc("Returns true if the player is a bot.")] public bool IsBot { get { return Player.IsBot; } }