Advertisement
GammixSAMP

playerlabels.pwn - By Gammix

May 8th, 2015
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 KB | None | 0 0
  1. //-------------------------------------------------
  2. //
  3. // Player Labels (/pl) filterscript; Now allow players to view other player statics from 3D labels
  4. // Just relevant to /dl (default cmd by SAMP)
  5. //
  6. // Gammix 2015
  7. // Thanks Incognito for streamer plugin
  8. // Thanks Zeex for zcmd include
  9. //
  10. //-------------------------------------------------
  11.  
  12. #define FILTERSCRIPT//
  13.  
  14. //-------------------------------------------------
  15.  
  16. #include <a_samp>
  17. #include <streamer>
  18. #include <zcmd>
  19.  
  20. //-------------------------------------------------
  21.  
  22. //labels configuration
  23. #define LABEL_COLOR 0x20B2AAFF//light sea green
  24. #define LABEL_DRAW_DISTANCE 40.0
  25. #define LABEL_STREAM_DISTANCE 100.0
  26. #define LABEL_STRING_SIZE 256
  27.  
  28. //-------------------------------------------------
  29.  
  30. enum PlayerLabelEnum
  31. {
  32. bool:E_LABEL_TOGGLED,
  33. Text3D:E_3D_TEXT_LABEL[MAX_PLAYERS],
  34. Float:E_POS[3],
  35. E_WEAPON,
  36. Float:E_HEALTH,
  37. Float:E_ARMOUR,
  38. E_MONEY,
  39. E_SCORE,
  40. E_PING
  41. }
  42. new gPlayerLabel[MAX_PLAYERS][PlayerLabelEnum];
  43.  
  44. //-------------------------------------------------
  45.  
  46. stock GetWeaponNameEx(weaponid, weapon[], len = sizeof(weapon))
  47. {
  48. switch(weaponid)
  49. {
  50. case 0: return strcat(weapon, "Fist", len);
  51. case 18: return strcat(weapon, "Molotov Cocktail", len);
  52. case 44: return strcat(weapon, "Night Vision Goggles", len);
  53. case 45: return strcat(weapon, "Thermal Goggles", len);
  54. default: return GetWeaponName(weaponid, weapon, len);
  55. }
  56. return false;
  57. }
  58.  
  59. SetLabelString(string[], playerid, extraid, len = sizeof(string))
  60. {
  61. new Float:player_hp;
  62. GetPlayerHealth(extraid, player_hp);
  63.  
  64. new Float:player_ar;
  65. GetPlayerArmour(extraid, player_ar);
  66.  
  67. new Float:player_distance;
  68. player_distance = GetPlayerDistanceFromPoint(playerid, gPlayerLabel[extraid][E_POS][0], gPlayerLabel[extraid][E_POS][1], gPlayerLabel[extraid][E_POS][2]);
  69.  
  70. new player_weapon[32];
  71. GetWeaponNameEx(GetPlayerWeapon(extraid), player_weapon, sizeof(player_weapon));
  72.  
  73. new Float:player_angle;
  74. GetPlayerFacingAngle(playerid, player_angle);
  75.  
  76. format( string,//puttins the values into the string
  77. len,
  78. "[id: %i, health: %0.2f, armour: %0.2f, ping: %i]\n\
  79. skin: %i, team: %i, money: $%i, score: %i\n\
  80. distance: %0.2f\n\
  81. weapon: %s (%i), ammo: %i\n\
  82. interior: %i, world: %i\n\
  83. pos: %0.4f, %0.4f, %0.4f, %0.4f",
  84. playerid, player_hp, player_ar, GetPlayerPing(extraid),
  85. GetPlayerSkin(extraid), GetPlayerTeam(extraid), GetPlayerMoney(extraid), GetPlayerScore(extraid),
  86. player_distance,
  87. player_weapon, GetPlayerWeapon(extraid), GetPlayerAmmo(extraid),
  88. GetPlayerInterior(extraid), GetPlayerVirtualWorld(extraid),
  89. gPlayerLabel[extraid][E_POS][0], gPlayerLabel[extraid][E_POS][1], gPlayerLabel[extraid][E_POS][2], player_angle
  90. );
  91. }
  92.  
  93. UpdatePlayersLabels(ofplayerid)
  94. {
  95. new string[LABEL_STRING_SIZE];
  96. for(new i; i < MAX_PLAYERS; i++)
  97. {
  98. if(IsPlayerConnected(i))
  99. {
  100. if(gPlayerLabel[i][E_LABEL_TOGGLED])
  101. {
  102. if(i != ofplayerid)
  103. {
  104. SetLabelString(string, i, ofplayerid, sizeof(string));
  105. UpdateDynamic3DTextLabelText(gPlayerLabel[i][E_3D_TEXT_LABEL][ofplayerid], LABEL_COLOR, string);
  106. }
  107. }
  108. }
  109. }
  110. }
  111.  
  112. //-------------------------------------------------
  113.  
  114. public OnPlayerConnect(playerid)
  115. {
  116. gPlayerLabel[playerid][E_LABEL_TOGGLED] = false;
  117. gPlayerLabel[playerid][E_WEAPON] = 0;
  118. gPlayerLabel[playerid][E_HEALTH] = 0.0;
  119. gPlayerLabel[playerid][E_ARMOUR] = 0.0;
  120. GetPlayerPos(playerid, gPlayerLabel[playerid][E_POS][0], gPlayerLabel[playerid][E_POS][1], gPlayerLabel[playerid][E_POS][2]);
  121.  
  122. new string[LABEL_STRING_SIZE];
  123. for(new i; i < MAX_PLAYERS; i++)
  124. {
  125. if(IsPlayerConnected(i))
  126. {
  127. if(i != playerid)
  128. {
  129. SetLabelString(string, playerid, i, sizeof(string));
  130. gPlayerLabel[i][E_3D_TEXT_LABEL][playerid] = CreateDynamic3DTextLabel(string, LABEL_COLOR, 0.0, 0.0, 0.0, LABEL_DRAW_DISTANCE, i, _, 0, _, _, playerid, LABEL_STREAM_DISTANCE);
  131. }
  132. }
  133. }
  134. return 1;
  135. }
  136.  
  137. //-------------------------------------------------
  138.  
  139. public OnPlayerDisconnect(playerid, reason)
  140. {
  141. for(new i; i < MAX_PLAYERS; i++)//destroy the labels if any
  142. {
  143. if(IsValidDynamic3DTextLabel(gPlayerLabel[playerid][E_3D_TEXT_LABEL][i]))
  144. {
  145. DestroyDynamic3DTextLabel(gPlayerLabel[playerid][E_3D_TEXT_LABEL][i]);
  146. }
  147. }
  148.  
  149. for(new i; i < MAX_PLAYERS; i++)
  150. {
  151. if(IsPlayerConnected(i))
  152. {
  153. if(gPlayerLabel[i][E_LABEL_TOGGLED])
  154. {
  155. if(i != playerid)
  156. {
  157. DestroyDynamic3DTextLabel(gPlayerLabel[i][E_3D_TEXT_LABEL][playerid]);
  158. }
  159. }
  160. }
  161. }
  162. return 1;
  163. }
  164.  
  165. //-------------------------------------------------
  166.  
  167. public OnPlayerSpawn(playerid)
  168. {
  169. GetPlayerPos(playerid, gPlayerLabel[playerid][E_POS][0], gPlayerLabel[playerid][E_POS][1], gPlayerLabel[playerid][E_POS][2]);
  170. gPlayerLabel[playerid][E_WEAPON] = GetPlayerWeapon(playerid);
  171. GetPlayerHealth(playerid, gPlayerLabel[playerid][E_HEALTH]);
  172. GetPlayerArmour(playerid, gPlayerLabel[playerid][E_ARMOUR]);
  173. gPlayerLabel[playerid][E_MONEY] = GetPlayerMoney(playerid);
  174. gPlayerLabel[playerid][E_SCORE] = GetPlayerScore(playerid);
  175. gPlayerLabel[playerid][E_PING] = GetPlayerPing(playerid);
  176.  
  177. UpdatePlayersLabels(playerid);
  178. return 1;
  179. }
  180.  
  181. //-------------------------------------------------
  182.  
  183. public OnPlayerUpdate(playerid)
  184. {
  185. new Float:player_hp;
  186. GetPlayerHealth(playerid, player_hp);
  187.  
  188. new Float:player_ar;
  189. GetPlayerArmour(playerid, player_ar);
  190.  
  191. new Float:new_player_pos[3];
  192. GetPlayerPos(playerid, new_player_pos[0], new_player_pos[1], new_player_pos[2]);
  193.  
  194. if( new_player_pos[0] != gPlayerLabel[playerid][E_POS][0] ||
  195. new_player_pos[1] != gPlayerLabel[playerid][E_POS][1] ||
  196. new_player_pos[2] != gPlayerLabel[playerid][E_POS][2] ||// OnPlayerPosUpdate
  197. gPlayerLabel[playerid][E_WEAPON] != GetPlayerWeapon(playerid) ||// OnPlayerswitchWeapon
  198. gPlayerLabel[playerid][E_HEALTH] != player_hp ||//OnPlayerHealthChange
  199. gPlayerLabel[playerid][E_ARMOUR] != player_ar ||//OnPlayerArmourChange
  200. gPlayerLabel[playerid][E_MONEY] != GetPlayerMoney(playerid) ||//OnPlayerMoneyChange
  201. gPlayerLabel[playerid][E_SCORE] != GetPlayerScore(playerid) ||//OnPlayerScoreChange
  202. gPlayerLabel[playerid][E_PING] != GetPlayerPing(playerid))//OnPlayerPingChange
  203. {
  204. //update player data to new one !
  205. GetPlayerPos(playerid, gPlayerLabel[playerid][E_POS][0], gPlayerLabel[playerid][E_POS][1], gPlayerLabel[playerid][E_POS][2]);
  206. gPlayerLabel[playerid][E_WEAPON] = GetPlayerWeapon(playerid);
  207. GetPlayerHealth(playerid, gPlayerLabel[playerid][E_HEALTH]);
  208. GetPlayerArmour(playerid, gPlayerLabel[playerid][E_ARMOUR]);
  209. gPlayerLabel[playerid][E_MONEY] = GetPlayerMoney(playerid);
  210. gPlayerLabel[playerid][E_SCORE] = GetPlayerScore(playerid);
  211. gPlayerLabel[playerid][E_PING] = GetPlayerPing(playerid);
  212.  
  213. UpdatePlayersLabels(playerid);
  214. }
  215. return 1;
  216. }
  217.  
  218. //-------------------------------------------------
  219.  
  220. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  221. {
  222. UpdatePlayersLabels(playerid);
  223. return 1;
  224. }
  225.  
  226. //-------------------------------------------------
  227.  
  228. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  229. {
  230. UpdatePlayersLabels(playerid);
  231. return 1;
  232. }
  233.  
  234. //-------------------------------------------------
  235.  
  236. CMD:pl(playerid)
  237. {
  238. if(! gPlayerLabel[playerid][E_LABEL_TOGGLED])//enable labels
  239. {
  240. new string[LABEL_STRING_SIZE];
  241. for(new i; i < MAX_PLAYERS; i++)
  242. {
  243. if(IsPlayerConnected(i))
  244. {
  245. if(i != playerid)
  246. {
  247. SetLabelString(string, playerid, i, sizeof(string));
  248. gPlayerLabel[playerid][E_3D_TEXT_LABEL][i] = CreateDynamic3DTextLabel(string, LABEL_COLOR, 0.0, 0.0, 0.0, LABEL_DRAW_DISTANCE, i, _, _, _, _, playerid, LABEL_STREAM_DISTANCE);
  249. }
  250. }
  251. }
  252. }
  253. else//disable labels
  254. {
  255. for(new i; i < MAX_PLAYERS; i++)
  256. {
  257. if(IsValidDynamic3DTextLabel(gPlayerLabel[playerid][E_3D_TEXT_LABEL][i]))
  258. {
  259. DestroyDynamic3DTextLabel(gPlayerLabel[playerid][E_3D_TEXT_LABEL][i]);
  260. }
  261. }
  262. }
  263. gPlayerLabel[playerid][E_LABEL_TOGGLED] = ! gPlayerLabel[playerid][E_LABEL_TOGGLED];
  264. return 1;
  265. }
  266.  
  267. //-------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement