best way to retrieve player and ai list?

best way to retrieve player and ai list?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

best way to retrieve player and ai list?

Post by smoth »

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.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: best way to retrieve player and ai list?

Post by Silentwings »

Are you in synced or unsynced?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: best way to retrieve player and ai list?

Post by smoth »

Both
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: best way to retrieve player and ai list?

Post by Silentwings »

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"?
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: best way to retrieve player and ai list?

Post by Funkencool »

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
This is what I use, but 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: best way to retrieve player and ai list?

Post by knorke »

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.
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.
Of course other way around it would work, use Spring.GetPlayerList to get all playerIDs, then Spring.GetPlayerInfo to get their teamID.
Post Reply

Return to “Lua Scripts”