Guest User

Untitled

a guest
May 7th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.09 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 by Southclaw again with some minor fixes and improvements
  8.  *
  9.  */
  10.  
  11. #if defined _playerprogress_included
  12.     #endinput
  13. #endif
  14.  
  15. #if !defined _samp_included
  16.     #tryinclude <a_samp>
  17.     #if !defined _samp_included
  18.         #error could not locate a_samp.inc file, please check your server includes
  19.     #endif
  20. #endif
  21.  
  22. #define _playerprogress_included
  23. #define _playerprogress_version 0x1310
  24.  
  25. #define MAX_PLAYER_BARS             (MAX_PLAYER_TEXT_DRAWS / 3)
  26. #define INVALID_PLAYER_BAR_VALUE    (Float:0xFFFFFFFF)
  27. #define INVALID_PLAYER_BAR_ID       (PlayerBar:-1)
  28. #define pb_percent(%1,%2,%3,%4) ((%1 - 6.0) + ((((%1 + 6.0 + %2 - 2.0) - %1) / %3) * %4))
  29. //pb_percent(x, width, max, value)
  30.  
  31. /* Pawno/Infernus Pawn Editor function list
  32. native PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  33. native DestroyPlayerProgressBar(playerid, PlayerBar:barid);
  34. native ShowPlayerProgressBar(playerid, PlayerBar:barid);
  35. native HidePlayerProgressBar(playerid, PlayerBar:barid);
  36. native SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value);
  37. native Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  38. native SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max);
  39. native SetPlayerProgressBarColor(playerid, PlayerBar:barid, color);
  40. native UpdatePlayerProgressBar(playerid, PlayerBar:barid);
  41. */
  42.  
  43. forward PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0);
  44. forward Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid);
  45.  
  46. enum E_BAR_DATA
  47. {
  48. Float:      pbar_x,
  49. Float:      pbar_y,
  50. Float:      pbar_w,
  51. Float:      pbar_h,
  52. Float:      pbar_m,
  53. Float:      pbar_v,
  54.             pbar_colour,
  55. bool:       pbar_valid
  56. }
  57.  
  58. enum E_BAR_TEXT_DRAW
  59. {
  60. PlayerText: pbar_textdraw1,
  61. PlayerText: pbar_textdraw2,
  62. PlayerText: pbar_textdraw3
  63. }
  64.  
  65.  
  66. static
  67.             pbar_Data[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_DATA],
  68.             pbar_TextDraw[MAX_PLAYERS][MAX_PLAYER_BARS][E_BAR_TEXT_DRAW];
  69.  
  70.  
  71. stock PlayerBar:CreatePlayerProgressBar(playerid, Float:x, Float:y, Float:width = 55.5, Float:height = 3.2, color, Float:max = 100.0)
  72. {
  73.     new 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(!IsPlayerConnected(playerid))
  115.         return 0;
  116.  
  117.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  118.         return 0;
  119.  
  120.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  121.         return 0;
  122.  
  123.     PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  124.     PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  125.     PlayerTextDrawDestroy(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  126.  
  127.     pbar_Data[playerid][_:barid][pbar_x] = 0.0;
  128.     pbar_Data[playerid][_:barid][pbar_y] = 0.0;
  129.     pbar_Data[playerid][_:barid][pbar_w] = 0.0;
  130.     pbar_Data[playerid][_:barid][pbar_h] = 0.0;
  131.     pbar_Data[playerid][_:barid][pbar_m] = 0.0;
  132.     pbar_Data[playerid][_:barid][pbar_v] = 0.0;
  133.     pbar_Data[playerid][_:barid][pbar_colour] = 0;
  134.     pbar_Data[playerid][_:barid][pbar_valid] = false;
  135.  
  136.     return 1;
  137. }
  138.  
  139. public OnPlayerDisconnect(playerid, reason)
  140. {
  141.     for(new i; i < MAX_PLAYER_BARS; i++)
  142.         pbar_Data[playerid][_:i][pbar_valid] = false;
  143.  
  144.     #if defined ppb_OnPlayerDisconnect
  145.         return ppb_OnPlayerDisconnect(playerid, reason);
  146.     #else
  147.         return 1;
  148.     #endif
  149. }
  150. #if defined _ALS_OnPlayerDisconnect
  151.     #undef OnPlayerDisconnect
  152. #else
  153.     #define _ALS_OnPlayerDisconnect
  154. #endif
  155.  
  156. #define OnPlayerDisconnect ppb_OnPlayerDisconnect
  157. #if defined ppb_OnPlayerDisconnect
  158.     forward ppb_OnPlayerDisconnect(playerid, reason);
  159. #endif
  160.  
  161. stock ShowPlayerProgressBar(playerid, PlayerBar:barid)
  162. {
  163.     if(!IsPlayerConnected(playerid))
  164.         return 0;
  165.  
  166.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  167.         return 0;
  168.  
  169.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  170.         return 0;
  171.  
  172.     PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  173.     PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  174.     PlayerTextDrawShow(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  175.  
  176.     return 1;
  177. }
  178.  
  179. stock HidePlayerProgressBar(playerid, PlayerBar:barid)
  180. {
  181.     if(!IsPlayerConnected(playerid))
  182.         return 0;
  183.  
  184.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  185.         return 0;
  186.  
  187.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  188.         return 0;
  189.  
  190.     PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1]);
  191.     PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2]);
  192.     PlayerTextDrawHide(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3]);
  193.  
  194.     return 1;
  195. }
  196.  
  197. stock SetPlayerProgressBarValue(playerid, PlayerBar:barid, Float:value)
  198. {
  199.     if(!IsPlayerConnected(playerid))
  200.         return 0;
  201.  
  202.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  203.         return 0;
  204.  
  205.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  206.         return 0;
  207.  
  208.     value = (value < 0.0) ? (0.0) : (value > pbar_Data[playerid][_:barid][pbar_m]) ? (pbar_Data[playerid][_:barid][pbar_m]) : (value);
  209.  
  210.     PlayerTextDrawUseBox(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3], value > 0.0);
  211.  
  212.     pbar_Data[playerid][_:barid][pbar_v] = value;
  213.  
  214.     PlayerTextDrawTextSize(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3],
  215.         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);
  216.  
  217.     return 1;
  218. }
  219.  
  220. stock Float:GetPlayerProgressBarValue(playerid, PlayerBar:barid)
  221. {
  222.     if(!IsPlayerConnected(playerid))
  223.         return INVALID_PLAYER_BAR_VALUE;
  224.  
  225.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  226.         return INVALID_PLAYER_BAR_VALUE;
  227.  
  228.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  229.         return INVALID_PLAYER_BAR_VALUE;
  230.  
  231.     return pbar_Data[playerid][_:barid][pbar_v];
  232. }
  233.  
  234. stock SetPlayerProgressBarMaxValue(playerid, PlayerBar:barid, Float:max)
  235. {
  236.     if(!IsPlayerConnected(playerid))
  237.         return 0;
  238.  
  239.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  240.         return 0;
  241.  
  242.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  243.         return 0;
  244.  
  245.     pbar_Data[playerid][_:barid][pbar_m] = max;
  246.     SetPlayerProgressBarValue(playerid, barid, pbar_Data[playerid][_:barid][pbar_v]);
  247.  
  248.     return 1;
  249. }
  250.  
  251. stock SetPlayerProgressBarColor(playerid, PlayerBar:barid, color)
  252. {
  253.     if(!IsPlayerConnected(playerid))
  254.         return 0;
  255.  
  256.     if(!(PlayerBar:-1 < barid < PlayerBar:MAX_PLAYER_BARS))
  257.         return 0;
  258.  
  259.     if(!pbar_Data[playerid][_:barid][pbar_valid])
  260.         return 0;
  261.  
  262.     pbar_Data[playerid][_:barid][pbar_colour] = color;
  263.     PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw1], 0x00000000 | (color & 0x000000FF));
  264.  
  265.     PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw2], (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2)));
  266.  
  267.     PlayerTextDrawBoxColor(playerid, pbar_TextDraw[playerid][_:barid][pbar_textdraw3], color);
  268.  
  269.     return 1;
  270. }
  271.  
  272. stock UpdatePlayerProgressBar(playerid, PlayerBar:barid)
  273. {
  274.     return ShowPlayerProgressBar(playerid, barid);
  275. }
Add Comment
Please, Sign In to add comment