AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Rank sorting (https://forums.alliedmods.net/showthread.php?t=51469)

Deviance 02-18-2007 12:59

Rank sorting
 
I've been thinking one this for a long time now, and i am really clueless...

Let's make an example:
Code:
1 = 2 2 = 50 3 = 22 4 = 150 5 = 39 6 = 88 7 = 46

Let's say that i want the players whit the highest numbers on the top, so it's like:
Code:
4 = 150 6 = 88 2 = 50 7 = 46 5 = 39 3 = 22 1 = 2
(It has to be same ID number, like id->score)
How would i do like that? :)

P34nut 02-18-2007 13:19

Re: Rank sorting
 
http://www.amxmodx.org/funcwiki.php?go=func&id=1115

Deviance 02-18-2007 13:29

Re: Rank sorting
 
Quote:

Originally Posted by P34nut (Post 442093)

It's done by ID numbers, and i need alot more then that i already know that command :|

XxAvalanchexX 02-18-2007 13:54

Re: Rank sorting
 
This is how GunGame does it.

Code:
 public get_sorted_players()  {     new i, count;     static sort[33][2], maxPlayers;     if(!maxPlayers) maxPlayers = get_maxplayers();     for(i=1;i<=maxPlayers;i++)     {         sort[count][0] = i;         sort[count][1] = score[i];         count++;     }     SortCustom2D(sort,count,"stats_custom_compare");  }  // our custom sorting function (check second dimension for score)  public stats_custom_compare(elem1[],elem2[])  {     if(elem1[1] > elem2[1]) return -1;     else if(elem1[1] < elem2[1]) return 1;     return 0;  }

Assuming that "score" is the variable that you want to sort by. When it's done, sort[0][0] = highest scoring player's id, sort[0][1] = highest scoring player's score; sort[1][0] = second highest scoring player's id, sort[1][1] = second highest scoring player's score; etcetera.


All times are GMT -4. The time now is 00:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.