From 9b5d0a3ddf41e686439dcda1edfe11eee51c3b07 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Thu, 5 Jan 2017 16:19:56 +0100 Subject: Initial --- DTPlayers.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 DTPlayers.c (limited to 'DTPlayers.c') diff --git a/DTPlayers.c b/DTPlayers.c new file mode 100644 index 0000000..ab75aef --- /dev/null +++ b/DTPlayers.c @@ -0,0 +1,82 @@ +/*-- Helper functions for iterating through all players and teams --*/ +#strict 2 + +static const Player_Number = 0; +static const Player_ID = 0 + 1; +static const Player_Name = 0 + 1 + 1; +static const Player_TaggedName = 0 + 1 + 1 + 1; +static const Player_Color = 0 + 1 + 1 + 1 + 1; +static const Player_Team = 0 + 1 + 1 + 1 + 1 + 1; +static const Player_Type = 0 + 1 + 1 + 1 + 1 + 1 + 1; + +global func GetPlayers(int team, bool exclude) +{ + var ret = []; + for(var plr, plrTeam, i = 0; (i < GetPlayerCount()) && ((plrTeam = GetPlayerTeam(plr = GetPlayerByIndex(i))) || true); ++i) + { + if(!team || (team == plrTeam) != exclude) + { + var plrInfo = []; + plrInfo[Player_Number] = plr; + plrInfo[Player_ID] = GetPlayerID(plr); + plrInfo[Player_Name] = GetPlayerName(plr); + plrInfo[Player_TaggedName] = GetTaggedPlayerName(plr); + plrInfo[Player_Color] = GetPlrColorDw(plr); + plrInfo[Player_Team] = GetPlayerTeam(plr); + plrInfo[Player_Type] = GetPlayerType(plr); + ret[GetLength(ret)] = plrInfo; + } + } + + return ret; +} + +global func GetPlayerNumbers(int team, bool exclude) +{ + var ret = []; + for(var plr, i = 0; (i < GetPlayerCount()) && ((plr = GetPlayerByIndex(i)) || true); ++i) + { + if(!team || (team == GetPlayerTeam(plr)) != exclude) + { + ret[GetLength(ret)] = plr; + } + } + return ret; +} + +global func GetTaggedTeamName(int team) +{ + return Format("%s", GetTeamColor(team), GetTeamName(team)); +} + +static const Team_ID = 0; +static const Team_Name = 0 + 1; +static const Team_TaggedName = 0 + 1 + 1; +static const Team_Color = 0 + 1 + 1 + 1; +static const Team_Players = 0 + 1 + 1 + 1 + 1; + +global func GetTeams() +{ + var ret = []; + for(var team, i = 0; (i < GetTeamCount()) && ((team = GetTeamByIndex(i)) || true); ++i) + { + var teamInfo = []; + teamInfo[Team_ID] = team; + teamInfo[Team_Name] = GetTeamName(team); + teamInfo[Team_TaggedName] = GetTaggedTeamName(); + teamInfo[Team_Color] = GetTeamColor(team); + teamInfo[Team_Players] = GetPlayers(team); + ret[GetLength(ret)] = teamInfo; + } + return ret; +} + +global func GetTeamIDs() +{ + var ret = []; + for(var team, i = 0; (i < GetTeamCount()) && ((team = GetTeamByIndex(i)) || true); ++i) + { + ret[GetLength(ret)] = team;; + } + return ret; +} -- cgit v1.2.3-54-g00ecf