I would like to retrieve a listing of all players AND ais currently active in the game. I don't need spectators but if they are included, whateves..
Anyway, what do I query for this? It seems that AIs count as the PLAYER who added them and not their own entity.
best way to retrieve player and ai list?
Moderator: Moderators
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: best way to retrieve player and ai list?
Are you in synced or unsynced?
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: best way to retrieve player and ai list?
In unsycned I'm not sure if there is anything that does it cleanly, because afaik all you have there is GetPlayerRoster and that tells you nothing about AIs 
In synced it's better, because you have GetPlayerList, GetTeamList, etc. GetTeamInfo can tell you if that team is an AI team, but I've no idea what it returns if a player and an AI are on the same team (which is not so bad, since this is actual Team and not AllyTeam).
GetPlayerInfo doesn't seem to be able to tell you if its an AI or not, which I think might mean I haven't answered your question - is this what you meant with "AIs count as the PLAYER who added them and not their own entity"?

In synced it's better, because you have GetPlayerList, GetTeamList, etc. GetTeamInfo can tell you if that team is an AI team, but I've no idea what it returns if a player and an AI are on the same team (which is not so bad, since this is actual Team and not AllyTeam).
GetPlayerInfo doesn't seem to be able to tell you if its an AI or not, which I think might mean I haven't answered your question - is this what you meant with "AIs count as the PLAYER who added them and not their own entity"?
- Funkencool
- Posts: 542
- Joined: 02 Dec 2011, 22:31
Re: best way to retrieve player and ai list?
Code: Select all
local teams = Spring.GetTeamList()
for i=0, (#teams-1) do
local _,teamLeader,isDead,isAI = Spring.GetTeamInfo(teamID)
local playerName, isActive, isSpec = Spring.GetPlayerInfo(teamLeader)
if isAI then
local _,botID,_,shortName = Spring.GetAIInfo(teamID)
playerName = shortName .."-" .. botID .. ""
end
end
Re: best way to retrieve player and ai list?
Yes, Spring.GetTeamInfo (teamID) only returns one playerID. There seems to be no Spring. function that takes a teamID and returns a table of playerIDs.Funkencool wrote:I'm not sure how it would handle teams with more than one player (as in sharing a commander etc..). I think it would just ignore one.
Of course other way around it would work, use Spring.GetPlayerList to get all playerIDs, then Spring.GetPlayerInfo to get their teamID.