Kucin666

Top 5

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