Advertisement
Kartik_Sharma

Top Players

Jul 21st, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.35 KB | None | 0 0
  1. #define ORDER_ASC 0
  2. #define ORDER_DES 1
  3.  
  4. new Float:t_Backup_Data[MAX_PLAYERS];
  5. new bool:t_IsDataEntered = false;
  6. new t_id[MAX_PLAYERS];
  7.  
  8. stock t_FeedInfo(playerid,Float:info)
  9. {
  10.     t_Backup_Data[playerid] = info;
  11.     t_id[playerid] = playerid;
  12.     t_IsDataEntered = true;
  13.     return 1;
  14. }
  15.  
  16. stock t_GetRank(playerid,order)
  17. {
  18.     if(t_IsDataEntered == false)
  19.     {
  20.         printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
  21.         return -1;
  22.     }
  23.     if(playerid==INVALID_PLAYER_ID || (!IsPlayerConnected(playerid)))
  24.     {
  25.         printf("TOP_PLAYER [ERROR] : Invalid ID || Player not connected\nAborting process.");
  26.         return -1;
  27.     }
  28.  
  29.     if(order>1 || order < 0)
  30.     {
  31.         printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
  32.         return -1;
  33.     }
  34.     else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
  35.     {
  36.         new Float:data[MAX_PLAYERS];
  37.         new id[MAX_PLAYERS];
  38.         for(new i=0;i<MAX_PLAYERS;++i)
  39.         {
  40.             if(!IsPlayerConnected(i)) continue;
  41.             data[i] = t_Backup_Data[i];
  42.             id[i] = t_id[i];
  43.  
  44.         }
  45.  
  46.         for(new i=0;i<MAX_PLAYERS;++i)
  47.         {
  48.             if(!IsPlayerConnected(i)) continue;
  49.             for(new j=i;j<MAX_PLAYERS;++j)
  50.             {
  51.                 if(!IsPlayerConnected(j)) continue;
  52.                 if(data[j]<data[i])
  53.                 {
  54.                     new Float:temp = data[i];
  55.                     data[i] = data[j];
  56.                     data[j] = temp;
  57.  
  58.                     new temp1 = id[i];
  59.                     id[i] = id[j];
  60.                     id[j] = temp1;
  61.  
  62.  
  63.                 }
  64.             }
  65.         }
  66.        
  67.         new r;
  68.         for(new i=0;i<MAX_PLAYERS;++i)
  69.         {
  70.             if(!IsPlayerConnected(i)) continue;
  71.             if(id[i] == playerid)
  72.             {
  73.                 r = i+1;
  74.                 break;
  75.             }
  76.         }
  77.         return r;
  78.     }
  79.  
  80.     else if(order == ORDER_DES)//Descending order 5,4,3,2,1
  81.     {
  82.         new Float:data[MAX_PLAYERS];
  83.         new id[MAX_PLAYERS];
  84.         for(new i=0;i<MAX_PLAYERS;++i)
  85.         {
  86.             if(!IsPlayerConnected(i)) continue;
  87.             data[i] = t_Backup_Data[i];
  88.             id[i] = t_id[i];
  89.  
  90.         }
  91.  
  92.         for(new i=0;i<MAX_PLAYERS;++i)
  93.         {
  94.             if(!IsPlayerConnected(i)) continue;
  95.             for(new j=i;j<MAX_PLAYERS;++j)
  96.             {
  97.                 if(!IsPlayerConnected(j)) continue;
  98.                 if(data[j]>data[i])
  99.                 {
  100.                     new Float:temp = data[i];
  101.                     data[i] = data[j];
  102.                     data[j] = temp;
  103.  
  104.                     new temp1 = id[i];
  105.                     id[i] = id[j];
  106.                     id[j] = temp1;
  107.  
  108.                 }
  109.             }
  110.         }
  111.         new r;
  112.         for(new i=0;i<MAX_PLAYERS;++i)
  113.         {
  114.             if(!IsPlayerConnected(i)) continue;
  115.             if(id[i] == playerid)
  116.             {
  117.                 r = i+1;
  118.                 break;
  119.             }
  120.         }
  121.         return r;
  122.     }
  123.     return  0;
  124. }
  125. stock t_GetPlayer(rank,order)
  126. {
  127.     if(t_IsDataEntered == false)
  128.     {
  129.         printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
  130.         return -1;
  131.     }
  132.     if(rank<1)
  133.     {
  134.         printf("TOP_PLAYER [ERROR] : Rank can not be less than 1.\nAborting process.");
  135.         return -1;
  136.     }
  137.  
  138.     if(order>1 || order < 0)
  139.     {
  140.         printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
  141.         return -1;
  142.     }
  143.     else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
  144.     {
  145.         new Float:data[MAX_PLAYERS];
  146.         new id[MAX_PLAYERS];
  147.         for(new i=0;i<MAX_PLAYERS;++i)
  148.         {
  149.             if(!IsPlayerConnected(i)) continue;
  150.             data[i] = t_Backup_Data[i];
  151.             id[i] = t_id[i];
  152.  
  153.  
  154.         }
  155.  
  156.         for(new i=0;i<MAX_PLAYERS;++i)
  157.         {
  158.             if(!IsPlayerConnected(i)) continue;
  159.             for(new j=i;j<MAX_PLAYERS;++j)
  160.             {
  161.                 if(!IsPlayerConnected(j)) continue;
  162.                 if(data[j]<data[i])
  163.                 {
  164.                     new Float:temp = data[i];
  165.                     data[i] = data[j];
  166.                     data[j] = temp;
  167.  
  168.                     new temp1 = id[i];
  169.                     id[i] = id[j];
  170.                     id[j] = temp1;
  171.                    
  172.                    
  173.                 }
  174.             }
  175.         }
  176.         return id[rank-1];
  177.     }
  178.  
  179.     else if(order == ORDER_DES)//Descending order 5,4,3,2,1
  180.     {
  181.         new Float:data[MAX_PLAYERS];
  182.         new id[MAX_PLAYERS];
  183.         for(new i=0;i<MAX_PLAYERS;++i)
  184.         {
  185.             if(!IsPlayerConnected(i)) continue;
  186.             data[i] = t_Backup_Data[i];
  187.             id[i] = t_id[i];
  188.  
  189.        
  190.         }
  191.  
  192.         for(new i=0;i<MAX_PLAYERS;++i)
  193.         {
  194.             if(!IsPlayerConnected(i)) continue;
  195.             for(new j=i;j<MAX_PLAYERS;++j)
  196.             {
  197.                 if(!IsPlayerConnected(j)) continue;
  198.                 if(data[j]>data[i])
  199.                 {
  200.                     new Float:temp = data[i];
  201.                     data[i] = data[j];
  202.                     data[j] = temp;
  203.  
  204.                     new temp1 = id[i];
  205.                     id[i] = id[j];
  206.                     id[j] = temp1;
  207.  
  208.                 }
  209.             }
  210.         }
  211.         return id[rank-1];
  212.     }
  213.     return  0;
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement