How Do I Get Number Of Alive Players In A Specific Team?

I know how to get the total number of players, but how would I get the number Of alive players In a specific team?

Since player.Alive() is a boolean, I’m not sure how to do this.

v:Alive

But how can I return the number of alive players in a specific team?

I can’t simply do #v:Alive() or #player.Alive() like I can do for #player.GetAll()

for k,v in pairs ( player.GetAll() ) do
if v:Alive and v:Team() == “TEAM_RED” then
print(v)
end

just a concept, pretty sure it doesn’t work

You could have two teams instead. One for alive people one for dead people. Set their team in PlayerDeath and just do #team.GetPlayers(whatever your dead team is)

Just fucking around here, but could you do something like
[LUA]
aliveplayers = 0
table.foreach( team.GetPlayers( teamname ), function( k, v )
if v:Alive() then aliveplayers = aliveplayers+1
print(aliveplayers)
end
end )[/LUA]

?

Thanks mate, worked!

This one is better though.

[lua]
local teamIndex = 0;

local i = 0;

for k, v in pairs( team.GetPlayers( teamIndex ) ) do
if( IsValid( v ) and v:Alive() ) then
i = i + 1;
end
end

print( string.format( "%s alive players in %s
", tostring( i ), team.GetName( teamIndex ) ) );
[/lua]