AXV09

Player Info Stats in TextDraw re-created

Dec 14th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.71 KB | None | 0 0
  1. /*
  2. * Pasek Informacyjny w TXD
  3. *
  4. * author: Lukasbank (edited by AXV)
  5. * version: 1.0.1
  6. *
  7. * All rights reserved.
  8. * ----------------------------------- */
  9.  
  10. #include <a_samp>
  11.  
  12. // makrodefinicje
  13. #if MAX_PLAYERS == 500
  14. #undef MAX_PLAYERS
  15. #define MAX_PLAYERS (500) // ilosc slotow
  16. #endif
  17.  
  18. #define FS_NAME "Update stats"
  19. #define FS_VERSION "1.0.1"
  20. #define UPDATE_STATS_INTERVAL (1000)
  21. #define MAX_TD (12)
  22. #define foreach(%1) for (new %1 = 0; %1 <= handlePlayers; %1++) if (IsPlayerConnected(%1))
  23.  
  24. // zmienne
  25. enum (+= 1) {
  26.  
  27. Text:TD_BOX = 0,
  28. Text:TD_ONLINEPLAYERS1,
  29. Text:TD_ONLINEPLAYERS2,
  30. Text:TD_NICKWITHID1,
  31. Text:TD_NICKWITHID2,
  32. Text:TD_PING1,
  33. Text:TD_PING2,
  34. Text:TD_TIMEGAME1,
  35. Text:TD_TIMEGAME2,
  36. Text:TD_SCORE1,
  37. Text:TD_SCORE2
  38. };
  39.  
  40. new
  41. Text:pTXD[MAX_PLAYERS][MAX_TD],
  42. playerSession[MAX_PLAYERS],
  43. tickCountPlayers,
  44. handlePlayers
  45. ;
  46.  
  47. // funkcje publiczne
  48. public OnFilterScriptInit() {
  49.  
  50. printf("%s, %s by Lukasbank edited by AXV loaded", FS_NAME, FS_VERSION);
  51. for (new i = 0; i < MAX_PLAYERS; i++) {
  52.  
  53. pTXD[i][TD_ONLINEPLAYERS1] = TextDrawCreate(526.000000, 415.000000, "~b~~h~Graczy");
  54. TextDrawBackgroundColor(pTXD[i][TD_ONLINEPLAYERS1], 16);
  55. TextDrawFont(pTXD[i][TD_ONLINEPLAYERS1], 1);
  56. TextDrawLetterSize(pTXD[i][TD_ONLINEPLAYERS1], 0.319999, 1.000000);
  57. TextDrawColor(pTXD[i][TD_ONLINEPLAYERS1], -1);
  58. TextDrawSetOutline(pTXD[i][TD_ONLINEPLAYERS1], 1);
  59. TextDrawSetProportional(pTXD[i][TD_ONLINEPLAYERS1], 1);
  60.  
  61. pTXD[i][TD_NICKWITHID1]= TextDrawCreate(149.000000, 415.000000, "~b~~y~Nick");
  62. TextDrawBackgroundColor(pTXD[i][TD_NICKWITHID1], 16);
  63. TextDrawFont(pTXD[i][TD_NICKWITHID1], 1);
  64. TextDrawLetterSize(pTXD[i][TD_NICKWITHID1], 0.319999, 1.000000);
  65. TextDrawColor(pTXD[i][TD_NICKWITHID1], -1);
  66. TextDrawSetOutline(pTXD[i][TD_NICKWITHID1], 1);
  67. TextDrawSetProportional(pTXD[i][TD_NICKWITHID1], 1);
  68.  
  69. pTXD[i][TD_PING1] = TextDrawCreate(275.000000, 415.000000, "~b~~h~Ping");
  70. TextDrawBackgroundColor(pTXD[i][TD_PING1], 16);
  71. TextDrawFont(pTXD[i][TD_PING1], 1);
  72. TextDrawLetterSize(pTXD[i][TD_PING1], 0.319999, 1.000000);
  73. TextDrawColor(pTXD[i][TD_PING1], -1);
  74. TextDrawSetOutline(pTXD[i][TD_PING1], 1);
  75. TextDrawSetProportional(pTXD[i][TD_PING1], 1);
  76.  
  77. pTXD[i][TD_TIMEGAME1] = TextDrawCreate(340.000000, 415.000000, "~b~~h~Czas gry");
  78. TextDrawBackgroundColor(pTXD[i][TD_TIMEGAME1], 16);
  79. TextDrawFont(pTXD[i][TD_TIMEGAME1], 1);
  80. TextDrawLetterSize(pTXD[i][TD_TIMEGAME1], 0.319999, 1.000000);
  81. TextDrawColor(pTXD[i][TD_TIMEGAME1], -1);
  82. TextDrawSetOutline(pTXD[i][TD_TIMEGAME1], 1);
  83. TextDrawSetProportional(pTXD[i][TD_TIMEGAME1], 1);
  84.  
  85. pTXD[i][TD_SCORE1] = TextDrawCreate(428.000000, 415.000000, "~b~~h~Drift points");
  86. TextDrawBackgroundColor(pTXD[i][TD_SCORE1], 16);
  87. TextDrawFont(pTXD[i][TD_SCORE1], 1);
  88. TextDrawLetterSize(pTXD[i][TD_SCORE1], 0.319999, 1.000000);
  89. TextDrawColor(pTXD[i][TD_SCORE1], -1);
  90. TextDrawSetOutline(pTXD[i][TD_SCORE1], 1);
  91. TextDrawSetProportional(pTXD[i][TD_SCORE1], 1);
  92.  
  93. pTXD[i][TD_BOX] = TextDrawCreate(78.000000, 332.000000, "-");
  94. TextDrawBackgroundColor(pTXD[i][TD_BOX], 37);
  95. TextDrawFont(pTXD[i][TD_BOX], 1);
  96. TextDrawLetterSize(pTXD[i][TD_BOX], 40.899971, 17.900001);
  97. TextDrawColor(pTXD[i][TD_BOX], 21);
  98. TextDrawSetOutline(pTXD[i][TD_BOX], 0);
  99. TextDrawSetProportional(pTXD[i][TD_BOX], 1);
  100. TextDrawSetShadow(pTXD[i][TD_BOX], 1);
  101.  
  102. pTXD[i][TD_NICKWITHID2] = TextDrawCreate(150.000000, 430.000000, "_");
  103. TextDrawBackgroundColor(pTXD[i][TD_NICKWITHID2], 16);
  104. TextDrawFont(pTXD[i][TD_NICKWITHID2], 1);
  105. TextDrawLetterSize(pTXD[i][TD_NICKWITHID2], 0.300000, 1.200000);
  106. TextDrawColor(pTXD[i][TD_NICKWITHID2], -1);
  107. TextDrawSetOutline(pTXD[i][TD_NICKWITHID2], 1);
  108. TextDrawSetProportional(pTXD[i][TD_NICKWITHID2], 1);
  109.  
  110. pTXD[i][TD_PING2] = TextDrawCreate(290.000000, 430.000000, "_");
  111. TextDrawBackgroundColor(pTXD[i][TD_PING2], 16);
  112. TextDrawFont(pTXD[i][TD_PING2], 1);
  113. TextDrawLetterSize(pTXD[i][TD_PING2], 0.300000, 1.200000);
  114. TextDrawColor(pTXD[i][TD_PING2], -1);
  115. TextDrawSetOutline(pTXD[i][TD_PING2], 1);
  116. TextDrawSetProportional(pTXD[i][TD_PING2], 1);
  117.  
  118. pTXD[i][TD_TIMEGAME2] = TextDrawCreate(350.000000, 430.000000, "_");
  119. TextDrawBackgroundColor(pTXD[i][TD_TIMEGAME2], 16);
  120. TextDrawFont(pTXD[i][TD_TIMEGAME2], 1);
  121. TextDrawLetterSize(pTXD[i][TD_TIMEGAME2], 0.300000, 1.200000);
  122. TextDrawColor(pTXD[i][TD_TIMEGAME2], -1);
  123. TextDrawSetOutline(pTXD[i][TD_TIMEGAME2], 1);
  124. TextDrawSetProportional(pTXD[i][TD_TIMEGAME2], 1);
  125.  
  126. pTXD[i][TD_SCORE2] = TextDrawCreate(448.000000, 430.000000, "_");
  127. TextDrawBackgroundColor(pTXD[i][TD_SCORE2], 16);
  128. TextDrawFont(pTXD[i][TD_SCORE2], 1);
  129. TextDrawLetterSize(pTXD[i][TD_SCORE2], 0.300000, 1.200000);
  130. TextDrawColor(pTXD[i][TD_SCORE2], -1);
  131. TextDrawSetOutline(pTXD[i][TD_SCORE2], 1);
  132. TextDrawSetProportional(pTXD[i][TD_SCORE2], 1);
  133.  
  134. pTXD[i][TD_ONLINEPLAYERS2] = TextDrawCreate(531.000000, 430.000000, "_");
  135. TextDrawBackgroundColor(pTXD[i][TD_ONLINEPLAYERS2], 16);
  136. TextDrawFont(pTXD[i][TD_ONLINEPLAYERS2], 1);
  137. TextDrawLetterSize(pTXD[i][TD_ONLINEPLAYERS2], 0.300000, 1.200000);
  138. TextDrawColor(pTXD[i][TD_ONLINEPLAYERS2], -1);
  139. TextDrawSetOutline(pTXD[i][TD_ONLINEPLAYERS2], 1);
  140. TextDrawSetProportional(pTXD[i][TD_ONLINEPLAYERS2], 1);
  141. }
  142.  
  143. SetTimer("updatePlayerStats", UPDATE_STATS_INTERVAL, true);
  144. return 1;
  145. }
  146.  
  147. public OnFilterScriptExit() {
  148.  
  149. foreach(playerid)
  150. for (new i = 0; i < MAX_TD; i++)
  151. TextDrawHideForPlayer(playerid, pTXD[playerid][i]);
  152.  
  153. printf("%s, %s by Lukasbank edited by AXV unloaded", FS_NAME, FS_VERSION);
  154. return 1;
  155. }
  156.  
  157. public OnPlayerConnect(playerid) {
  158.  
  159. playerSession[playerid] = GetTickCount();
  160.  
  161. if (handlePlayers < playerid)
  162. handlePlayers = playerid;
  163. }
  164.  
  165. public OnPlayerDisconnect(playerid, reason) {
  166.  
  167. for (new i = handlePlayers; i >= 0; i--) {
  168. if ((IsPlayerConnected(i) && i != playerid) || (i == 0)) {
  169. handlePlayers = i;
  170. break;
  171. }
  172. }
  173. }
  174.  
  175. public OnPlayerSpawn(playerid) {
  176.  
  177. for (new i = 0; i < MAX_TD; i++)
  178. TextDrawShowForPlayer(playerid, pTXD[playerid][i]);
  179. }
  180.  
  181. public OnPlayerDeath(playerid, killerid, reason) {
  182.  
  183. for (new i = 0; i < MAX_TD; i++)
  184. TextDrawHideForPlayer(playerid, pTXD[playerid][i]);
  185. }
  186.  
  187. forward updateStats();
  188. public updateStats() {
  189.  
  190. new sec = GetTickCount()/ 1000;
  191.  
  192. if ((sec - tickCountPlayers) >= 8) { // zeby dane liczace graczy nie wywolywaly sie zbyt szybko
  193.  
  194. new buffer[10];
  195. format(buffer, sizeof(buffer), "%i~y~|~w~%i", countPlayers(), GetMaxPlayers());
  196.  
  197. foreach(i) {
  198. TextDrawSetString(pTXD[i][TD_ONLINEPLAYERS2], buffer);
  199. }
  200.  
  201. printf("wykonano");
  202. tickCountPlayers = sec;
  203. }
  204. }
  205.  
  206. forward updatePlayerStats();
  207. public updatePlayerStats() {
  208.  
  209. static
  210. buffer[64],
  211. psession = 0
  212. ;
  213.  
  214. foreach(i) {
  215.  
  216. psession = 0, buffer[0] = 0;
  217.  
  218. format(buffer, sizeof(buffer), "~b~~h~~h~%s~w~ (~y~%i~w~)", getPlayerName(i), i);
  219. TextDrawSetString(pTXD[i][TD_NICKWITHID2], buffer);
  220.  
  221. psession = ((GetTickCount() - playerSession[i])/ 1000)/ 60;
  222. format(buffer, 15, "%02ih%02im", psession/ 60, psession% 60);
  223. TextDrawSetString(pTXD[i][TD_TIMEGAME2],buffer);
  224.  
  225. format(buffer, sizeof(buffer), "%ims", GetPlayerPing(i));
  226. TextDrawSetString(pTXD[i][TD_PING2], buffer);
  227.  
  228. format(buffer, sizeof(buffer), "%i", GetPlayerScore(i));
  229. TextDrawSetString(pTXD[i][TD_SCORE2], buffer);
  230. }
  231.  
  232. updateStats();
  233. }
  234.  
  235. countPlayers() {
  236.  
  237. new players = 0;
  238. for (new i = 0; i <= handlePlayers; i++)
  239. if (IsPlayerConnected(i))
  240. players++;
  241.  
  242. return players;
  243. }
  244.  
  245. getPlayerName(playerid) {
  246.  
  247. static
  248. _@Name[MAX_PLAYER_NAME]
  249. ;
  250.  
  251. _@Name[0] = 0; // dla bezpieczenstwa
  252. GetPlayerName(playerid, _@Name, MAX_PLAYER_NAME);
  253. return _@Name;
  254. }
Advertisement
Add Comment
Please, Sign In to add comment