Advertisement
Kartik_Sharma

Untitled

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