1
0

progress.inc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /**
  2. * Progress Bar 1.3.1.0
  3. * Copyright 2007-2010 Infernus' Group,
  4. * Fl?vio Toribio (flavio_toibio@hotmail.com)
  5. *
  6. * Updated by Southclaw for use with the PlayerTextDraws of 0.3e
  7. * Updated again by Southclaw for some bugfixes and removal of the per-player textdraw array
  8. * Textdraw IDs are now kept in a separate array that isn't per-player, to save memory.
  9. *
  10. */
  11. #if defined _playerprogress_included
  12. #endinput
  13. #endif
  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. #tryinclude <foreach>
  21. #define _playerprogress_included
  22. #define _playerprogress_version 0x1310
  23. #define MAX_PLAYER_BARS (MAX_PLAYER_TEXT_DRAWS / 3)
  24. #define INVALID_PLAYER_BAR_VALUE (Float:0xFFFFFFFF)
  25. #define INVALID_PLAYER_BAR_ID (PlayerBar:-1)
  26. #define pb_percent(%1,%2,%3,%4) ((%1 - 6.0) + ((((%1 + 6.0 + %2 - 2.0) - %1) / %3) * %4))
  27. //pb_percent(x, width, max, value)
  28. /* Pawno/Infernus Pawn Editor function list
  29. native PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  30. native DestroyPlayerProgressBar(playerid, PlayerBar:barid);
  31. native ShowPlayerProgressBar(playerid, PlayerBar:barid);
  32. native HidePlayerProgressBar(playerid, PlayerBar:barid);
  33. native SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value);
  34. native Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  35. native SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max);
  36. native SetPlayerProgressBarColor(playerid, PlayerBar:barid, color);
  37. native UpdatePlayerProgressBar(playerid, PlayerBar:barid);
  38. */
  39. forward PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  40. forward Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  41. enum E_BAR_DATA
  42. {
  43. Float:pbar_x,
  44. Float:pbar_y,
  45. Float:pbar_w,
  46. Float:pbar_h,
  47. Float:pbar_m,
  48. Float:pbar_v,
  49. pbar_colour,
  50. bool:pbar_valid
  51. }
  52. enum E_BAR_TEXT_DRAW
  53. {
  54. PlayerText:pbar_textdraw1,
  55. PlayerText:pbar_textdraw2,
  56. PlayerText:pbar_textdraw3,
  57. }
  58. static
  59. PlayerBars[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_DATA],
  60. PlayerBarText[MAX_PLAYER_BARS][E_BAR_TEXT_DRAW];
  61. stock PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0)
  62. {
  63. new
  64. barid;
  65. for(barid = 0; barid < MAX_PLAYER_BARS; ++barid) // Changed from `Bars` to `MAX_PLAYER_BARS` rather than getting the size of the second cell
  66. if(!PlayerBars[playerid][barid][pbar_valid]) break;
  67. if(PlayerBars[playerid][barid][pbar_valid] || barid == MAX_PLAYER_BARS)
  68. return INVALID_PLAYER_BAR_ID;
  69. new PlayerText:in_t = PlayerBarText[barid][pbar_textdraw1] = CreatePlayerTextDraw(playerid, x, y, "_");
  70. PlayerTextDrawUseBox (playerid, in_t, 1);
  71. PlayerTextDrawTextSize (playerid, in_t, x + width, 0.0);
  72. PlayerTextDrawLetterSize (playerid, in_t, 1.0, height / 10);
  73. PlayerTextDrawBoxColor (playerid, in_t, 0x00000000 | (color & 0x000000FF));
  74. in_t = PlayerBarText[barid][pbar_textdraw2] = CreatePlayerTextDraw(playerid, x + 1.2, y + 2.15, "_");
  75. PlayerTextDrawUseBox (playerid, in_t, 1);
  76. PlayerTextDrawTextSize (playerid, in_t, x + width - 2.0, 0.0);
  77. PlayerTextDrawLetterSize (playerid, in_t, 1.0, height / 10 - 0.35);
  78. PlayerTextDrawBoxColor (playerid, in_t, (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  79. in_t = PlayerBarText[barid][pbar_textdraw3] = CreatePlayerTextDraw(playerid, x + 1.2, y + 2.15, "_");
  80. PlayerTextDrawTextSize (playerid, in_t, pb_percent(x, width, max, 1.0), 0.0);
  81. PlayerTextDrawLetterSize (playerid, in_t, 1.0, height / 10 - 0.35);
  82. PlayerTextDrawBoxColor (playerid, in_t, color);
  83. PlayerBars[playerid][barid][pbar_x] = x;
  84. PlayerBars[playerid][barid][pbar_y] = y;
  85. PlayerBars[playerid][barid][pbar_w] = width;
  86. PlayerBars[playerid][barid][pbar_h] = height;
  87. PlayerBars[playerid][barid][pbar_m] = max;
  88. PlayerBars[playerid][barid][pbar_colour] = color;
  89. PlayerBars[playerid][barid][pbar_valid] = true;
  90. return PlayerBar:barid;
  91. }
  92. stock DestroyPlayerProgressBar(playerid, PlayerBar:barid)
  93. {
  94. if(barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  95. {
  96. if(!PlayerBars[playerid][_:barid][pbar_valid])
  97. return 0;
  98. PlayerTextDrawDestroy(playerid, PlayerBarText[_:barid][pbar_textdraw1]);
  99. PlayerTextDrawDestroy(playerid, PlayerBarText[_:barid][pbar_textdraw2]);
  100. PlayerTextDrawDestroy(playerid, PlayerBarText[_:barid][pbar_textdraw3]);
  101. PlayerBars[playerid][_:barid][pbar_x] = 0.0;
  102. PlayerBars[playerid][_:barid][pbar_y] = 0.0;
  103. PlayerBars[playerid][_:barid][pbar_w] = 0.0;
  104. PlayerBars[playerid][_:barid][pbar_h] = 0.0;
  105. PlayerBars[playerid][_:barid][pbar_m] = 0.0;
  106. PlayerBars[playerid][_:barid][pbar_v] = 0.0;
  107. PlayerBars[playerid][_:barid][pbar_colour] = 0;
  108. PlayerBars[playerid][_:barid][pbar_valid] = false;
  109. return 1;
  110. }
  111. return 0;
  112. }
  113. stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
  114. {
  115. if(IsPlayerConnected(playerid) && barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  116. {
  117. if(!PlayerBars[playerid][_:barid][pbar_valid])
  118. return 0;
  119. PlayerTextDrawShow(playerid, PlayerBarText[_:barid][pbar_textdraw1]);
  120. PlayerTextDrawShow(playerid, PlayerBarText[_:barid][pbar_textdraw2]);
  121. PlayerTextDrawShow(playerid, PlayerBarText[_:barid][pbar_textdraw3]);
  122. return 1;
  123. }
  124. return 0;
  125. }
  126. stock HidePlayerProgressBar(playerid, PlayerBar:barid)
  127. {
  128. if(IsPlayerConnected(playerid) && barid != INVALID_PLAYER_BAR_ID && PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS)
  129. {
  130. if(!PlayerBars[playerid][_:barid][pbar_valid])
  131. return 0;
  132. PlayerTextDrawHide(playerid, PlayerBarText[_:barid][pbar_textdraw1]);
  133. PlayerTextDrawHide(playerid, PlayerBarText[_:barid][pbar_textdraw2]);
  134. PlayerTextDrawHide(playerid, PlayerBarText[_:barid][pbar_textdraw3]);
  135. return 1;
  136. }
  137. return 0;
  138. }
  139. stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
  140. {
  141. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  142. return 0;
  143. if(PlayerBars[playerid][_:barid][pbar_valid])
  144. {
  145. value =
  146. (value < 0.0) ? (0.0) : (value > PlayerBars[playerid][_:barid][pbar_m]) ? (PlayerBars[playerid][_:barid][pbar_m]) : (value);
  147. PlayerTextDrawUseBox(playerid, PlayerBarText[_:barid][pbar_textdraw3], value > 0.0);
  148. PlayerBars[playerid][_:barid][pbar_v] = value;
  149. PlayerTextDrawTextSize(playerid, PlayerBarText[_:barid][pbar_textdraw3],
  150. pb_percent(PlayerBars[playerid][_:barid][pbar_x], PlayerBars[playerid][_:barid][pbar_w], PlayerBars[playerid][_:barid][pbar_m], value), 0.0);
  151. HidePlayerProgressBar(playerid, PlayerBar:barid);
  152. ShowPlayerProgressBar(playerid, PlayerBar:barid);
  153. return 1;
  154. }
  155. return 0;
  156. }
  157. stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
  158. {
  159. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  160. return INVALID_PLAYER_BAR_VALUE;
  161. if(PlayerBars[playerid][_:barid][pbar_valid])
  162. return PlayerBars[playerid][_:barid][pbar_v];
  163. return INVALID_PLAYER_BAR_VALUE;
  164. }
  165. stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
  166. {
  167. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  168. return 0;
  169. if(PlayerBars[playerid][_:barid][pbar_valid])
  170. {
  171. PlayerBars[playerid][_:barid][pbar_m] = max;
  172. SetPlayerProgressBarValue(playerid, barid, PlayerBars[playerid][_:barid][pbar_v]);
  173. return 1;
  174. }
  175. return 0;
  176. }
  177. stock SetPlayerProgressBarColor(playerid, PlayerBar:barid, color)
  178. {
  179. if(barid == INVALID_PLAYER_BAR_ID || PlayerBar:MAX_PLAYER_BARS < barid < PlayerBar:-1)
  180. return 0;
  181. if(PlayerBars[playerid][_:barid][pbar_valid])
  182. {
  183. PlayerBars[playerid][_:barid][pbar_colour] = color;
  184. PlayerTextDrawBoxColor(playerid, PlayerBarText[_:barid][pbar_textdraw1], 0x00000000 | (color & 0x000000FF));
  185. PlayerTextDrawBoxColor(playerid, PlayerBarText[_:barid][pbar_textdraw2],
  186. (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  187. PlayerTextDrawBoxColor(playerid, PlayerBarText[_:barid][pbar_textdraw3], color);
  188. return 1;
  189. }
  190. return 0;
  191. }
  192. stock UpdatePlayerProgressBar(playerid, PlayerBar:barid)
  193. {
  194. return ShowPlayerProgressBar(playerid, barid);
  195. }