Advertisement
GammixSAMP

playerstats.inc - By Gammix

May 12th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. /*
  2. Stats Include (playerstats.inc)
  3. * Gives online player's stats, very easy code but useful (atleast to me)
  4.  
  5. Author: (creator)
  6. * Gammix
  7.  
  8. (c) Copyright 2015
  9. * This file is provided as is (no warranties).
  10. */
  11.  
  12. /*
  13. FUNCTIONS:
  14. native GetPlayerKills(playerid);
  15. native GetPlayerDeaths(playerid);
  16. native GetPlayerSpree(playerid);
  17. native GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds);
  18. native GetPlayerHeadshots(playerid);
  19. native GetPlayerWeaponShots(playerid);
  20. native GetPlayerWeaponHits(playerid);
  21.  
  22. CALLBACKS:
  23. public OnPlayerHeadshot(playerid, issuerid, weaponid)
  24. */
  25.  
  26. enum PlayerEnum
  27. {
  28. P_KILLS,
  29. P_DEATHS,
  30. P_SPREE,
  31. P_HEADSHOTS,
  32. P_SHOTS,
  33. P_HITS
  34. }
  35. static gPlayer[MAX_PLAYERS][PlayerEnum];
  36.  
  37. public OnPlayerSpawn(playerid)
  38. {
  39. gPlayer[playerid][P_SPREE] = 0;
  40.  
  41. #if defined STATS_OnPlayerSpawn
  42. return STATS_OnPlayerSpawn(playerid);
  43. #else
  44. return 1;
  45. #endif
  46. }
  47. #if defined _ALS_OnPlayerSpawn
  48. #undef OnPlayerSpawn
  49. #else
  50. #define _ALS_OnPlayerSpawn
  51. #endif
  52. #define OnPlayerSpawn STATS_OnPlayerSpawn
  53. #if defined STATS_OnPlayerSpawn
  54. forward STATS_OnPlayerSpawn(playerid);
  55. #endif
  56.  
  57. public OnPlayerDeath(playerid, killerid, reason)
  58. {
  59. gPlayer[playerid][P_DEATHS] += 1;
  60. gPlayer[playerid][P_SPREE] = 0;
  61.  
  62. if(killerid != INVALID_PLAYER_ID)
  63. {
  64. gPlayer[killerid][P_KILLS] += 1;
  65. gPlayer[killerid][P_SPREE] += 1;
  66. }
  67.  
  68. #if defined STATS_OnPlayerDeath
  69. return STATS_OnPlayerDeath(playerid, killerid, reason);
  70. #else
  71. return 1;
  72. #endif
  73. }
  74. #if defined _ALS_OnPlayerDeath
  75. #undef OnPlayerDeath
  76. #else
  77. #define _ALS_OnPlayerDeath
  78. #endif
  79. #define OnPlayerDeath STATS_OnPlayerDeath
  80. #if defined STATS_OnPlayerDeath
  81. forward STATS_OnPlayerDeath(playerid, killerid, reason);
  82. #endif
  83.  
  84. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  85. {
  86. //headshot system
  87. if( (GetPlayerTeam(playerid) == NO_TEAM && GetPlayerTeam(issuerid) == NO_TEAM) ||
  88. GetPlayerTeam(issuerid) != GetPlayerTeam(playerid))
  89. {
  90. if(bodypart == 9)
  91. {
  92. if(CallLocalFunction("OnPlayerHeadshot", "iii", playerid, issuerid, weaponid))
  93. {
  94. gPlayer[issuerid][P_HEADSHOTS] += 1;
  95. }
  96. }
  97. }
  98. else gPlayer[issuerid][P_HITS] += 1;
  99.  
  100. #if defined STATS_OnPlayerTakeDamage
  101. return STATS_OnPlayerTakeDamage(playerid, issuerid, amount, weaponid, bodypart);
  102. #else
  103. return 1;
  104. #endif
  105. }
  106. #if defined _ALS_OnPlayerTakeDamage
  107. #undef OnPlayerTakeDamage
  108. #else
  109. #define _ALS_OnPlayerTakeDamage
  110. #endif
  111. #define OnPlayerTakeDamage STATS_OnPlayerTakeDamage
  112. #if defined STATS_OnPlayerTakeDamage
  113. forward STATS_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart);
  114. #endif
  115.  
  116. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  117. {
  118. if(weaponid != 0)
  119. {
  120. gPlayer[playerid][P_SHOTS] += 1;
  121. }
  122.  
  123. #if defined STATS_OnPlayerWeaponShot
  124. return STATS_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, fX, fY, fZ);
  125. #else
  126. return 1;
  127. #endif
  128. }
  129. #if defined _ALS_OnPlayerWeaponShot
  130. #undef OnPlayerWeaponShot
  131. #else
  132. #define _ALS_OnPlayerWeaponShot
  133. #endif
  134. #define OnPlayerWeaponShot STATS_OnPlayerWeaponShot
  135. #if defined STATS_OnPlayerWeaponShot
  136. forward STATS_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  137. #endif
  138.  
  139. stock GetPlayerKills(playerid)
  140. {
  141. return gPlayer[playerid][P_KILLS];
  142. }
  143.  
  144. stock GetPlayerDeaths(playerid)
  145. {
  146. return gPlayer[playerid][P_DEATHS];
  147. }
  148.  
  149. stock GetPlayerSpree(playerid)
  150. {
  151. return gPlayer[playerid][P_SPREE];
  152. }
  153.  
  154. stock GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds)
  155. {
  156. new connected_time = NetStats_GetConnectedTime(playerid);
  157. seconds = (connected_time / 1000) % 60;
  158. minutes = (connected_time / (1000 * 60)) % 60;
  159. hours = (connected_time / (1000 * 60 * 60));
  160. return true;
  161. }
  162.  
  163. stock GetPlayerHeadshots(playerid)
  164. {
  165. return gPlayer[playerid][P_HEADSHOTS];
  166. }
  167.  
  168. stock GetPlayerWeaponShots(playerid)
  169. {
  170. return gPlayer[playerid][P_SHOTS];
  171. }
  172.  
  173. stock GetPlayerWeaponHits(playerid)
  174. {
  175. return gPlayer[playerid][P_HITS];
  176. }
  177.  
  178. forward OnPlayerHeadshot(playerid, issuerid, weaponid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement