Guest User

Ranking por Baiano - GTS Torcidas

a guest
Dec 24th, 2012
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 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. {
  60. if (IsPlayerConnected(i) && !IsPlayerNPC(i))
  61. {
  62. PlayerScore[n][Score] = PlayerDados[i][pMatou];
  63. PlayerScore[n][Id] = i;
  64. n++;
  65. }
  66. }
  67. GetPlayerHighestScores(PlayerScore, 0, n);
  68. for (new i = 10; i > 0; i--)
  69. if (PlayerScore[i][Id] == PlayerScore[i - 1][Id]) PlayerScore[i][Id] = 999;
  70. for (new i = 0; i < 10; i++)
  71. {
  72. if (PlayerScore[i][Id] == 999) format(Rmsg, sizeof(Rmsg), "{FFFF00}%s %i - Ninguém.\n", Rmsg, i + 1);
  73. else
  74. {
  75. new BaianoGTS[MAX_PLAYER_NAME];
  76. GetPlayerName(PlayerScore[i][Id], BaianoGTS, sizeof(BaianoGTS));
  77. format(Rmsg, sizeof(Rmsg), "{FFFF00}%s %i - %s | [Matou %i]\n", Rmsg, i + 1, BaianoGTS, PlayerScore[i][Score]);
  78. }
  79. }
  80. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "{FF0000}Ranking", Rmsg, "Ok", "");
  81. return 1;
  82. }
  83.  
  84. stock GetPlayerHighestScores(array[][Ranking], left, right)
  85. {
  86. new tempLeft = left, tempRight = right, pivot = array[(left + right) / 2][Score], tempVar;
  87. while(tempLeft <= tempRight)
  88. {
  89. while(array[tempLeft][Score] > pivot) tempLeft++;
  90. while(array[tempRight][Score] < pivot) tempRight--;
  91. if(tempLeft <= tempRight)
  92. {
  93. tempVar = array[tempLeft][Score], array[tempLeft][Score] = array[tempRight][Score], array[tempRight][Score] = tempVar;
  94. tempVar = array[tempLeft][Id], array[tempLeft][Id] = array[tempRight][Id], array[tempRight][Id] = tempVar;
  95. tempLeft++, tempRight--;
  96. }
  97. }
  98. if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
  99. if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
  100. }
Advertisement
Add Comment
Please, Sign In to add comment