Guest User

Ranking por Baiano - GTS Torcidas

a guest
Dec 23rd, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. /*
  2. ================================================================================
  3.  
  4. - Sistema de Ranking por Mortes -
  5. Criado por: Baiano
  6. Agradecimentos para: Zeex pelo zcmd.
  7.  
  8. Se for usar o código não retire os créditos! :)
  9.  
  10. ================================================================================
  11. */
  12.  
  13. #include <a_samp>
  14. #include <zcmd>
  15.  
  16. enum Ranking
  17. {
  18. Score, Id
  19. }
  20.  
  21. enum pDados
  22. {
  23. pMatou
  24. }
  25.  
  26. new PlayerScore[MAX_PLAYERS][Ranking];
  27. new PlayerDados[MAX_PLAYERS][pDados];
  28.  
  29. public OnFilterScriptInit()
  30. {
  31. print("\n----------------------------------");
  32. print(" Sistema de Ranking Carregado ");
  33. print(" Feito por BaiaNo. ");
  34. print("----------------------------------\n");
  35. return 1;
  36. }
  37.  
  38. public OnFilterScriptExit()
  39. {
  40. print("\n----------------------------------");
  41. print(" Sistema de Ranking Descarregado ");
  42. print(" Feito por BaiaNo. ");
  43. print("----------------------------------\n");
  44. return 1;
  45. }
  46.  
  47. public OnPlayerRequestClass(playerid, classid)
  48. {
  49. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  50. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  51. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  52. return 1;
  53. }
  54.  
  55. CMD:ranking(playerid)
  56. {
  57. new n = 0, Rmsg[1000];
  58. for (new i = 0; i < MAX_PLAYERS; i++) {
  59. if (IsPlayerConnected(i) && !IsPlayerNPC(i))
  60. {
  61. PlayerScore[n][Score] = PlayerDados[i][pMatou];
  62. PlayerScore[n][Id] = i;
  63. n++;
  64. }
  65. }
  66. GetPlayerHighestScores(PlayerScore, 0, n);
  67. for (new i = 10; i > 0; i--)
  68. if (PlayerScore[i][Id] == PlayerScore[i - 1][Id]) PlayerScore[i][Id] = 999;
  69. for (new i = 0; i < 10; i++) {
  70. if (PlayerScore[i][Id] == 999) format(Rmsg, sizeof(Rmsg), "{FFFF00}%s %i - Ninguém.\n", Rmsg, i + 1);
  71. else {
  72. new BaianoGTS[MAX_PLAYER_NAME];
  73. GetPlayerName(PlayerScore[i][Id], BaianoGTS, sizeof(BaianoGTS));
  74. format(Rmsg, sizeof(Rmsg), "{FFFF00}%s %i - %s | [Matou %i]\n", Rmsg, i + 1, BaianoGTS, PlayerScore[i][Score]);
  75. }
  76. }
  77. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "{FF0000}Ranking", Rmsg, "Ok", "");
  78. return 1;
  79. }
  80.  
  81. stock GetPlayerHighestScores(array[][Ranking], left, right)
  82. {
  83. new tempLeft = left, tempRight = right, pivot = array[(left + right) / 2][Score], tempVar;
  84. while(tempLeft <= tempRight) {
  85. while(array[tempLeft][Score] > pivot) tempLeft++;
  86. while(array[tempRight][Score] < pivot) tempRight--;
  87. if(tempLeft <= tempRight) {
  88. tempVar = array[tempLeft][Score], array[tempLeft][Score] = array[tempRight][Score], array[tempRight][Score] = tempVar;
  89. tempVar = array[tempLeft][Id], array[tempLeft][Id] = array[tempRight][Id], array[tempRight][Id] = tempVar;
  90. tempLeft++, tempRight--;
  91. }
  92. }
  93. if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
  94. if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment