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.
This commit is contained in:
Oliver Brakmann
2016-08-11 20:13:10 +02:00
parent 92199d1dfd
commit f6f81e84df

View File

@@ -39,18 +39,25 @@ namespace OpenRA.Mods.Common.Scripting
get get
{ {
Game.Debug("The property `PlayerProperties.Race` is deprecated! Use `PlayerProperties.Faction` instead!"); 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.")] [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.")] [Desc("The player's spawnpoint ID.")]
public int Spawn { get { return Player.SpawnPoint; } } public int Spawn { get { return Player.SpawnPoint; } }
[Desc("The player's team ID.")] [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.")] [Desc("Returns true if the player is a bot.")]
public bool IsBot { get { return Player.IsBot; } } public bool IsBot { get { return Player.IsBot; } }