Guest User

HealthBarColors

a guest
Nov 13th, 2019
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. #include <sscanf2>
  3. #include <Progress2>
  4. #include <zcmd>
  5.  
  6. new PlayerBar:HealthBar[MAX_PLAYERS];
  7. #define HPBAR_DIALOG 2222 //change if in use
  8. #define MAX_BAR_COLORS 5 //change if you add more
  9.  
  10. new hpbar_colors[MAX_BAR_COLORS] =
  11. {
  12. 0xFF0000FF, 0x00FF00FF, 0xFFFF00FF, 0x0000FFFF, 0xFFFFFFFF
  13. };
  14.  
  15. public OnPlayerConnect(playerid)
  16. {
  17. if(!IsPlayerNPC(playerid))
  18. {
  19. HealthBar[playerid] = CreatePlayerProgressBar(playerid, 547.666564, 68.995140, 62.5, 5.6, 0x00FF00FF, 100.0, BAR_DIRECTION_RIGHT, 0x000000FF);
  20. }
  21. return 1;
  22. }
  23.  
  24. CMD:hpbarcolor(playerid, params[])
  25. {
  26. new hex;
  27. if(sscanf(params, "x", hex)) return SendClientMessage(playerid, 0xFFFFFFFF, "/hpbarcolor [hex]");
  28. SetPlayerProgressBarColor(playerid, HealthBar[playerid], hex);
  29. return 1;
  30. }
  31.  
  32. CMD:hpbarcolors(playerid, params[]) //edit if you added more
  33. {
  34. ShowPlayerDialog(playerid, HPBAR_DIALOG, DIALOG_STYLE_LIST, "HP BAR COLORS", "{FF0000}Red\n{00FF00}Green\n{FFFF00}Yellow\n{0000FF}Blue\n{FFFFFF}White", "Set", "Cancel");
  35. return 1;
  36. }
  37.  
  38. public OnPlayerDeath(playerid)
  39. {
  40. if(!IsPlayerNPC(playerid))
  41. {
  42. HidePlayerProgressBar(playerid, HealthBar[playerid]);
  43. }
  44. return 1;
  45. }
  46.  
  47. public OnPlayerSpawn(playerid)
  48. {
  49. if(!IsPlayerNPC(playerid))
  50. {
  51. SetPlayerProgressBarValue(playerid, HealthBar[playerid], 100.0);
  52. ShowPlayerProgressBar(playerid, HealthBar[playerid]);
  53. }
  54. return 1;
  55. }
  56.  
  57. public OnPlayerDisconnect(playerid, reason)
  58. {
  59. if(!IsPlayerNPC(playerid))
  60. {
  61. DestroyPlayerProgressBar(playerid, HealthBar[playerid]);
  62. }
  63. return 1;
  64. }
  65.  
  66. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
  67. {
  68. new Float:HP;
  69. if(!IsPlayerNPC(playerid))
  70. {
  71. GetPlayerHealth(playerid, HP);
  72. SetPlayerProgressBarValue(playerid, HealthBar[playerid], HP-amount);
  73. }
  74. return 1;
  75. }
  76.  
  77. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  78. {
  79. switch(dialogid)
  80. {
  81. case HPBAR_DIALOG:
  82. {
  83. if(response)
  84. {
  85. for(new i = 0; i < MAX_BAR_COLORS; i++)
  86. {
  87. if(i != listitem) continue;
  88. SetPlayerProgressBarColor(playerid, HealthBar[playerid], hpbar_colors[i]);
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. return 0;
  95. }
RAW Paste Data