Guest User

Top5

a guest
Jan 26th, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. new
  4.     Text: text_Top5[2]
  5. ;
  6.  
  7. enum rankingEnum
  8. {
  9.     player_Score,
  10.     player_ID
  11. }
  12.  
  13. public OnFilterScriptInit()
  14. {  
  15.     text_Top5[0] = TextDrawCreate(79.000000, 135.000000, "Top 5");
  16.     TextDrawAlignment(text_Top5[0], 2);
  17.     TextDrawBackgroundColor(text_Top5[0], 255);
  18.     TextDrawFont(text_Top5[0], 1);
  19.     TextDrawLetterSize(text_Top5[0], 0.280000, 1.499999);
  20.     TextDrawColor(text_Top5[0], -1);
  21.     TextDrawSetOutline(text_Top5[0], 0);
  22.     TextDrawSetProportional(text_Top5[0], 1);
  23.     TextDrawSetShadow(text_Top5[0], 0);
  24.    
  25.     text_Top5[1] = TextDrawCreate(16.000000, 135.000000, " ");
  26.     TextDrawBackgroundColor(text_Top5[1], 255);
  27.     TextDrawFont(text_Top5[1], 1);
  28.     TextDrawLetterSize(text_Top5[1], 0.200000, 0.999999);
  29.     TextDrawColor(text_Top5[1], -1);
  30.     TextDrawSetOutline(text_Top5[1], 0);
  31.     TextDrawSetProportional(text_Top5[1], 1);
  32.     TextDrawSetShadow(text_Top5[1], 0);
  33.     TextDrawUseBox(text_Top5[1], 1);
  34.     TextDrawBoxColor(text_Top5[1], 150);
  35.     TextDrawTextSize(text_Top5[1], 143.000000, 20.000000);
  36.     return 1;
  37. }
  38.  
  39. public OnFilterScriptExit()
  40. {
  41.     TextDrawDestroy(text_Top5[0]);
  42.     TextDrawDestroy(text_Top5[1]);
  43.     return 1;
  44. }
  45.  
  46. stock GetPlayerHighestScores(array[][rankingEnum], left, right)
  47. {
  48.     new
  49.         tempLeft = left,
  50.         tempRight = right,
  51.         pivot = array[(left + right) / 2][player_Score],
  52.         tempVar
  53.     ;
  54.     while(tempLeft <= tempRight)
  55.     {
  56.         while(array[tempLeft][player_Score] > pivot) tempLeft++;
  57.         while(array[tempRight][player_Score] < pivot) tempRight--;
  58.        
  59.         if(tempLeft <= tempRight)
  60.         {
  61.             tempVar = array[tempLeft][player_Score], array[tempLeft][player_Score] = array[tempRight][player_Score], array[tempRight][player_Score] = tempVar;
  62.             tempVar = array[tempLeft][player_ID], array[tempLeft][player_ID] = array[tempRight][player_ID], array[tempRight][player_ID] = tempVar;
  63.             tempLeft++, tempRight--;
  64.         }
  65.     }
  66.     if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
  67.     if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
  68. }
  69.  
  70. public OnPlayerCommandText(playerid, cmdtext[])
  71. {
  72.     if(!strcmp(cmdtext, "/top5", true))
  73.     {
  74.         new
  75.             playerScores[MAX_PLAYERS][rankingEnum],
  76.             index
  77.         ;
  78.         for(new i; i != MAX_PLAYERS; ++i)
  79.         {
  80.             if(IsPlayerConnected(i) && !IsPlayerNPC(i))
  81.             {
  82.                 playerScores[index][player_Score] = GetPlayerScore(i);
  83.                 playerScores[index++][player_ID] = i;
  84.             }
  85.         }
  86.         GetPlayerHighestScores(playerScores, 0, index);
  87.        
  88.         new
  89.             score_Text[256] = "~n~",
  90.             player_Name[20]
  91.         ;
  92.         for(new i; i < 5; ++i)
  93.         {          
  94.             if(i < index)
  95.             {
  96.                 GetPlayerName(playerScores[i][player_ID], player_Name, sizeof(player_Name));
  97.                 format(score_Text, sizeof(score_Text), "%s~n~~b~%d. ~w~%s - ~r~%d", score_Text, i + 1, player_Name, playerScores[i][player_Score]);        
  98.             }
  99.             else
  100.                 format(score_Text, sizeof(score_Text), "%s~n~~b~%d. ~r~N/A", score_Text, i + 1);
  101.         }
  102.         TextDrawSetString(text_Top5[1], score_Text);
  103.         TextDrawShowForPlayer(playerid, text_Top5[0]);
  104.         TextDrawShowForPlayer(playerid, text_Top5[1]);
  105.         return 1;
  106.     }
  107.     return 0;
  108. }
Add Comment
Please, Sign In to add comment