Sorting teams on the scoreboard

How would I go about doing that? Currently, the sandbox scoreboard sorts the player row based on who has the most kills, but I’d like to have them sorted randomly, but in teams.

Currently it’s like this:

[lua]
function PANEL:HigherOrLower( row )

if ( !self.Player:IsValid() || self.Player:Team() == TEAM_CONNECTING ) then return false end
if ( !row.Player:IsValid() || row.Player:Team() == TEAM_CONNECTING ) then return true end

if ( self.Player:Frags() == row.Player:Frags() ) then

	return self.Player:Deaths() < row.Player:Deaths()

end

return self.Player:Frags() > row.Player:Frags()

end
[/lua]

So, could anyone help me make a scoreboard where it sorts the players based on their teams?

Aww, I’ve got the same problem.

If someone knew how to fix it so it sorts it by teams instead of the current, it’d be appreciated.

Well, sorting is pretty simple. There’s the ‘table.sort’ function…

[lua]
local function sort_callback( a, b )

return( a:Team( ) > b:Team( ) );

end

local players = player.GetAll( );
table.sort( players, sort_callback );
[/lua]

I have no idea whether or not this will work but:

[lua]
function PANEL:HigherOrLower( row )

if ( !self.Player:IsValid() || self.Player:Team() == TEAM_CONNECTING ) then return false end
if ( !row.Player:IsValid() || row.Player:Team() == TEAM_CONNECTING ) then return true end

table.SortByMember(row , Player:Team() , function(a , b) return b > a end)

end
[/lua]

Nevec’s code is better and more likely to work.