Advertisement
Lordz

ProgressBar - SouthClaw_Toribo

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