Guest User

Untitled

a guest
Apr 8th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 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.  
  113.  
  114. stock DestroyPlayerProgressBar(playerid, PlayerBar:barid)
  115. {
  116. if(barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  117. {
  118. if(!pbar_Data[playerid][_:barid][pbar_valid])
  119. return 0;
  120.  
  121. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  122. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  123. PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  124.  
  125. pbar_Data[playerid][_:barid][pbar_x] = 0.0;
  126. pbar_Data[playerid][_:barid][pbar_y] = 0.0;
  127. pbar_Data[playerid][_:barid][pbar_w] = 0.0;
  128. pbar_Data[playerid][_:barid][pbar_h] = 0.0;
  129. pbar_Data[playerid][_:barid][pbar_m] = 0.0;
  130. pbar_Data[playerid][_:barid][pbar_v] = 0.0;
  131. pbar_Data[playerid][_:barid][pbar_colour] = 0;
  132. pbar_Data[playerid][_:barid][pbar_valid] = false;
  133. return 1;
  134. }
  135. return 0;
  136. }
  137.  
  138. // All player textdraws delete anyways just clear all bars
  139. public OnPlayerDisconnect(playerid, reason)
  140. {
  141. for(new i = 0; i < MAX_PLAYER_BARS; i++) { pbar_Data[playerid][_:i][pbar_valid] = false; }
  142. if (funcidx("PB_OnPlayerDisconnect") != -1)
  143. {
  144. return CallLocalFunction("PB_OnPlayerDisconnect", "ii", playerid, reason);
  145. }
  146. return 1;
  147. }
  148. #if defined _ALS_OnPlayerDisconnect
  149. #undef OnPlayerDisconnect
  150. #else
  151. #define _ALS_OnPlayerDisconnect
  152. #endif
  153. #define OnPlayerDisconnect PB_OnPlayerDisconnect
  154.  
  155. forward PB_OnPlayerDisconnect(playerid, reason);
  156.  
  157.  
  158. stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
  159. {
  160. if(IsPlayerConnected(playerid) && barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  161. {
  162. if(!pbar_Data[playerid][_:barid][pbar_valid])
  163. return 0;
  164.  
  165. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  166. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  167. PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  168.  
  169. return 1;
  170. }
  171. return 0;
  172. }
  173.  
  174. stock HidePlayerProgressBar(playerid, PlayerBar:barid)
  175. {
  176. if(IsPlayerConnected(playerid) && barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  177. {
  178. if(!pbar_Data[playerid][_:barid][pbar_valid])
  179. return 0;
  180.  
  181. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  182. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  183. PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  184.  
  185. return 1;
  186. }
  187. return 0;
  188. }
  189.  
  190. stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
  191. {
  192. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  193. return 0;
  194.  
  195. if(pbar_Data[playerid][_:barid][pbar_valid])
  196. {
  197. value = (value < 0.0) ? (0.0) : (value > pbar_Data[playerid][_:barid][pbar_m]) ? (pbar_Data[playerid][_:barid][pbar_m]) : (value);
  198.  
  199. PlayerTextDrawUseBox(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3], value > 0.0);
  200.  
  201. pbar_Data[playerid][_:barid][pbar_v] = value;
  202.  
  203. PlayerTextDrawTextSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3],
  204. 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);
  205.  
  206. return 1;
  207. }
  208.  
  209. return 0;
  210. }
  211.  
  212. stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
  213. {
  214. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  215. return INVALID_PLAYER_BAR_VALUE;
  216.  
  217. if(pbar_Data[playerid][_:barid][pbar_valid])
  218. return pbar_Data[playerid][_:barid][pbar_v];
  219.  
  220. return INVALID_PLAYER_BAR_VALUE;
  221. }
  222.  
  223. stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
  224. {
  225. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  226. return 0;
  227.  
  228. if(pbar_Data[playerid][_:barid][pbar_valid])
  229. {
  230. pbar_Data[playerid][_:barid][pbar_m] = max;
  231. SetPlayerProgressBarValue(playerid, barid, pbar_Data[playerid][_:barid][pbar_v]);
  232. return 1;
  233. }
  234. return 0;
  235. }
  236.  
  237. stock SetPlayerProgressBarColor(playerid, PlayerBar:barid, color)
  238. {
  239. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  240. return 0;
  241.  
  242. if(pbar_Data[playerid][_:barid][pbar_valid])
  243. {
  244. pbar_Data[playerid][_:barid][pbar_colour] = color;
  245. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1], 0x00000000 | (color & 0x000000FF));
  246.  
  247. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2], (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  248.  
  249. PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3], color);
  250. return 1;
  251. }
  252. return 0;
  253. }
  254.  
  255. stock UpdatePlayerProgressBar(playerid, PlayerBar:barid)
  256. {
  257. return ShowPlayerProgressBar(playerid, barid);
  258. }
Advertisement
Add Comment
Please, Sign In to add comment