Hello have problem with sorting player by kills and deahts
![Click image for larger version.
Name: Untitled.png
Views: 27
Size: 1.9 KB
ID: 1601](https://killtube.org/attachment.php?attachmentid=1601&d=1557748023&thumb=1)
https://killtube.org/showthread.php?...est-player-map
PHP Code:
PlayerList(page)
{
if(page == 1)
{
self.playerlist_page = 1;
self.selected_player = -1;
self.player_Stats_page_1 = [];
self.player_Stats_page_1[0] = [];
self.player_Stats_page_1[1] = [];
self.player_Stats_page_1[2] = [];
self.player_Stats_page_1[3] = [];
self.player_Stats_page_1[4] = [];
self.player_Stats_page_1[5] = [];
self.player_Stats_page_1[6] = [];
self.player_Stats_page_1[7] = [];
self.player_Stats_page_1[8] = [];
self.player_Stats_page_1[9] = [];
self.player_Stats_page_1[10] = [];
self.player_Stats_page_1[11] = [];
self.player_Stats_page_1[12] = [];
self.player_Stats_page_1[13] = [];
self.player_Stats_page_1[15] = [];
player_num = 0;
players = getEntArray("player", "classname");
array = [];
for (i = 0; i < 16; i++)
{
player = players[ i ];
if (! isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
continue;
if(i == 17)
break;
array[ array.size ] = players[ i ];
}
array = sortPlayerList(array);
for (i = 0; i < self.player_Stats_page_1.size; i++)
{
if (isDefined(array[ i ])) {
self.player_Stats_page_1[ i ]["player"] = array[ i ];
self.player_Stats_page_1[ i ]["name"] = array[ i ].name;
self.player_Stats_page_1[ i ]["kills"] = array[ i ].score;
self.player_Stats_page_1[ i ]["deaths"] = array[ i ].deaths;
}
}
}
str_names = "";
str_kills = "";
str_deaths = "";
for (i = 0; i < self.player_Stats_page_1.size; i++)
{
if(isDefined(self.player_Stats_page_1[ i ]["name"])) {
str_names = str_names+""+self.player_Stats_page_1[ i ]["name"]+"\n";
str_kills = str_kills+""+self.player_Stats_page_1[ i ]["kills"]+"\n";
str_deaths = str_deaths+""+self.player_Stats_page_1[ i ]["deaths"]+"\n";
}
}
self setclientcvar("s_players", str_names);
self setclientcvar("s_players_k", str_kills);
self setclientcvar("s_players_d", str_deaths);
}
sortPlayerList(array)
{
str = array;
for (i = 0; i < str.size - 1; i++)
{
for (j = i + 1; j < str.size; j++)
{
if (str[ i ].score < str[ j ].score)
{
var = str[ i ];
str[ i ] = str[ j ];
str[ j ] = var;
}
}
}
return str;
}