Another way is to loop with tables, which I consider just slightly better than regular loops. With regular loops, even if you only had 10 users, the loop would still have to query up to the end (GetMaxPlayers()) whereas a table loop would only query the users that it has in it's table. Less waste, more fresh air!
// Table
players <- {};
// Give the player a slot in the table
function onPlayerJoin( player )
{
players.rawset( player.ID, player );
}
// Empty the slot after they leave
function onPlayerPart( player, reason )
{
if( players.rawin( player.ID ) ) players.rawdelete( player.ID );
}
// Here's the loop
function cheesyNamedLoop()
{
foreach( p in players ) // We select every entry (i.e. player) who has been entered
{
if( p.Team == your_team_here )
{
// Do stuff here
}
}
}