Advertisement
Guest User

Player Progress

a guest
Dec 30th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. /**
  2. * Progress Bar 1.3.1.0
  3. * Copyright 2007-2010 Infernus' Group,
  4. * Flávio Toribio ([email protected])
  5. *
  6. * Updated by Southclaw for use with the PlayerTextDraws of 0.3e
  7. *
  8. */
  9.  
  10. #if defined _playerprogress_included
  11. #endinput
  12. #endif
  13.  
  14. #if !defined _samp_included
  15. #tryinclude <a_samp>
  16. #if !defined _samp_included
  17. #error could not locate a_samp.inc file, please check your server includes
  18. #endif
  19. #endif
  20.  
  21. #define _playerprogress_included
  22. #define _playerprogress_version 0x1310
  23.  
  24. #define MAX_PLAYER_BARS (10)
  25. #define INVALID_PLAYER_BAR_VALUE (Float:0xFFFFFFFF)
  26. #define INVALID_PLAYER_BAR_ID (PlayerBar:-1)
  27. #define pb_percent(%1,%2,%3,%4) ((%1 - 6.0) + ((((%1 + 6.0 + %2 - 2.0) - %1) / %3) * %4))
  28. //pb_percent(x, width, max, value)
  29.  
  30. /* Pawno/Infernus Pawn Editor function list
  31. native PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  32. native DestroyPlayerProgressBar(playerid, PlayerBar:barid);
  33. native ShowPlayerProgressBar(playerid, PlayerBar:barid);
  34. native HidePlayerProgressBar(playerid, PlayerBar:barid);
  35. native SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value);
  36. native Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  37. native SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max);
  38. native SetPlayerProgressBarColor(playerid, PlayerBar:barid, color);
  39. native UpdatePlayerProgressBar(playerid, PlayerBar:barid);
  40. */
  41.  
  42. forward PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  43. forward Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  44.  
  45. enum E_BAR_DATA
  46. {
  47. Float: pbar_x,
  48. Float: pbar_y,
  49. Float: pbar_w,
  50. Float: pbar_h,
  51. Float: pbar_m,
  52. Float: pbar_v,
  53. pbar_colour,
  54. bool: pbar_valid
  55. }
  56.  
  57. enum E_BAR_TEXT_DRAW
  58. {
  59. PlayerText: pbar_textdraw1,
  60. PlayerText: pbar_textdraw2,
  61. PlayerText: pbar_textdraw3
  62. }
  63.  
  64.  
  65. static
  66. pbar_Data[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_DATA],
  67. pbar_TextDraw[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_TEXT_DRAW];
  68.  
  69.  
  70. stock PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width = 55.5, Float:height = 3.2, color, Float:max = 100.0)
  71. {
  72. new
  73. barid;
  74.  
  75. for(barid = 0; barid < MAX_PLAYER_BARS; ++barid)
  76. {
  77. if(!pbar_Data[playerid][barid][pbar_valid])
  78. break;
  79. }
  80.  
  81. if(barid == MAX_PLAYER_BARS)
  82. return INVALID_PLAYER_BAR_ID;
  83.  
  84. pbar_TextDraw[playerid][barid][pbar_textdraw1] = CreatePlayerTextDraw(playerid, x, y, "_");
  85. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw1], 1);
  86. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw1], x + width, 0.0);
  87. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw1], 1.0, height / 10);
  88. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw1], 0x00000000 | (color & 0x000000FF));
  89.  
  90. pbar_TextDraw[playerid][barid][pbar_textdraw2] = CreatePlayerTextDraw(playerid, x + 1.2, y + 2.15, "_");
  91. PlayerTextDrawUseBox (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw2], 1);
  92. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw2], x + width - 2.0, 0.0);
  93. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw2], 1.0, height / 10 - 0.35);
  94. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw2], (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  95.  
  96. pbar_TextDraw[playerid][barid][pbar_textdraw3] = CreatePlayerTextDraw(playerid, x + 1.2, y + 2.15, "_");
  97. PlayerTextDrawTextSize (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw3], pb_percent(x, width, max, 1.0), 0.0);
  98. PlayerTextDrawLetterSize (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw3], 1.0, height / 10 - 0.35);
  99. PlayerTextDrawBoxColor (playerid, pbar_TextDraw[playerid][barid][pbar_textdraw3], color);
  100.  
  101. pbar_Data[playerid][barid][pbar_x] = x;
  102. pbar_Data[playerid][barid][pbar_y] = y;
  103. pbar_Data[playerid][barid][pbar_w] = width;
  104. pbar_Data[playerid][barid][pbar_h] = height;
  105. pbar_Data[playerid][barid][pbar_m] = max;
  106. pbar_Data[playerid][barid][pbar_colour] = color;
  107. pbar_Data[playerid][barid][pbar_valid] = true;
  108.  
  109. return PlayerBar:barid;
  110. }
  111.  
  112. stock DestroyPlayerProgressBar(playerid, PlayerBar:barid)
  113. {
  114. if(barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  115. {
  116. if(!pbar_Data[playerid][_:barid][pbar_valid])
  117. return 0;
  118.  
  119. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  120. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  121. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  122.  
  123. pbar_Data[playerid][_:barid][pbar_x] = 0.0;
  124. pbar_Data[playerid][_:barid][pbar_y] = 0.0;
  125. pbar_Data[playerid][_:barid][pbar_w] = 0.0;
  126. pbar_Data[playerid][_:barid][pbar_h] = 0.0;
  127. pbar_Data[playerid][_:barid][pbar_m] = 0.0;
  128. pbar_Data[playerid][_:barid][pbar_v] = 0.0;
  129. pbar_Data[playerid][_:barid][pbar_colour] = 0;
  130. pbar_Data[playerid][_:barid][pbar_valid] = false;
  131. return 1;
  132. }
  133. return 0;
  134. }
  135.  
  136. stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
  137. {
  138. if(IsPlayerConnected(playerid) && barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  139. {
  140. if(!pbar_Data[playerid][_:barid][pbar_valid])
  141. return 0;
  142.  
  143. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  144. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  145. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  146.  
  147. return 1;
  148. }
  149. return 0;
  150. }
  151.  
  152. stock HidePlayerProgressBar(playerid, PlayerBar:barid)
  153. {
  154. if(IsPlayerConnected(playerid) && barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  155. {
  156. if(!pbar_Data[playerid][_:barid][pbar_valid])
  157. return 0;
  158.  
  159. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  160. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  161. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  162.  
  163. return 1;
  164. }
  165. return 0;
  166. }
  167.  
  168. stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
  169. {
  170. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  171. return 0;
  172.  
  173. if(pbar_Data[playerid][_:barid][pbar_valid])
  174. {
  175. value = (value < 0.0) ? (0.0) : (value > pbar_Data[playerid][_:barid][pbar_m]) ? (pbar_Data[playerid][_:barid][pbar_m]) : (value);
  176.  
  177. PlayerTextDrawUseBox(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3], value > 0.0);
  178.  
  179. pbar_Data[playerid][_:barid][pbar_v] = value;
  180.  
  181. PlayerTextDrawTextSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3],
  182. pb_percent(pbar_Data[playerid][_:barid][pbar_x] + 4, pbar_Data[playerid][_:barid][pbar_w] - 12, pbar_Data[playerid][_:barid][pbar_m], value), 0.0);
  183.  
  184. return 1;
  185. }
  186.  
  187. return 0;
  188. }
  189.  
  190. stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
  191. {
  192. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  193. return INVALID_PLAYER_BAR_VALUE;
  194.  
  195. if(pbar_Data[playerid][_:barid][pbar_valid])
  196. return pbar_Data[playerid][_:barid][pbar_v];
  197.  
  198. return INVALID_PLAYER_BAR_VALUE;
  199. }
  200.  
  201. stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
  202. {
  203. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  204. return 0;
  205.  
  206. if(pbar_Data[playerid][_:barid][pbar_valid])
  207. {
  208. pbar_Data[playerid][_:barid][pbar_m] = max;
  209. SetPlayerProgressBarValue(playerid, barid, pbar_Data[playerid][_:barid][pbar_v]);
  210. return 1;
  211. }
  212. return 0;
  213. }
  214.  
  215. stock SetPlayerProgressBarColor(playerid, PlayerBar:barid, color)
  216. {
  217. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  218. return 0;
  219.  
  220. if(pbar_Data[playerid][_:barid][pbar_valid])
  221. {
  222. pbar_Data[playerid][_:barid][pbar_colour] = color;
  223. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1], 0x00000000 | (color & 0x000000FF));
  224.  
  225. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2], (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  226.  
  227. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3], color);
  228. return 1;
  229. }
  230. return 0;
  231. }
  232.  
  233. stock UpdatePlayerProgressBar(playerid, PlayerBar:barid)
  234. {
  235. return ShowPlayerProgressBar(playerid, barid);
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement