Shy353

GUI Health and Armour bar for VCMP

Sep 12th, 2020 (edited)
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. You need to have the two images in your 'sprites' folder inside the store folder. You can also use your own image but you'll have to amend the code in order to make bar inside the image and other changes. The link for the files is here: http://www.mediafire.com/folder/xbvptwd35o5m3/sprites
  3. -Shy
  4. */
  5. // Remove the health and armour bar from the hud
  6. Hud.RemoveFlags(HUD_FLAG_HEALTH);
  7.  
  8. // official function, scriptload
  9. function Script::ScriptLoad()
  10. {
  11. //Show the armour and UI health to the client
  12.     ShowHealth();
  13. }
  14. // the main function which'll show Armour & health bar
  15. function ShowHealth()
  16. {
  17. local plr = World.FindLocalPlayer(); // find player (client side)
  18. local H = plr.Health; // player's Hp
  19. local A = plr.Armour; // PLAYER'S Armour
  20. //Health main canvas
  21. UI.Canvas({
  22.         id = "canvy"
  23.         align = "bottom_left"
  24.         children = [
  25.                                         UI.Sprite({
  26.                 id = "heal"
  27.                 file = "HPBar.png" /* loading sprite downloaded from sprites folder in the above provided link, if you haven't added any sprite, the system will throw error */
  28.                 align = "hud_top"
  29.                 move = { down = 92, left = 320}
  30.                 Size = VectorScreen( 270, 60 )
  31.             })
  32. //ProgressBar which'll show health
  33. UI.ProgressBar({
  34.                     id = "HPBAR"  
  35.                     BackgroundShade = 0.2
  36.                     align = "hud_top"
  37.                     MaxValue = 100
  38.                     Thickness = 2
  39.                     selectedColour = Colour( 255, 0, 0 )
  40.                     StartColour = Colour( 255, 0, 0 )
  41.                     EndColour = Colour( 0, 210, 0 )
  42.                     Size = VectorScreen(63, 23)
  43.                     Value = H // reduces along with the health
  44.                 move = { down = 118, left = 226}
  45.                 })
  46. // label shows the hp player has   
  47.                 UI.Label({
  48.                     id = "Bar"
  49.                     align = "hud_top"
  50.                     Text = H
  51.                     TextColour = Colour( 255, 255, 255 )
  52.                     FontFlags = GUI_FFLAG_BOLD | GUI_FFLAG_OUTLINE
  53.                     FontSize = 12
  54.                 move = { down = 117, left = 228}
  55.                 })
  56.         ]
  57.     })
  58. /* running a timer every 0.1 secound to check the player's health each frame and update the progress bar and label, needs ysc's timers(already included in DecUI) */
  59. Timer.Create(this, function(ext = null)
  60. {
  61.     local plr = World.FindLocalPlayer();
  62. local H = plr.Health;
  63.     UI.ProgressBar("HPBAR").Value = H; //updatethe value again
  64.     UI.Label("Bar").Text = H; //update the player's health label again
  65. }, 100, 0, "H");
  66. /* The following is same as the above health canvas, just sprites are changed and value is set to armour */
  67. UI.Canvas({
  68.         id = "acanvy"
  69.         align = "bottom_left"
  70.         children = [
  71.                             UI.Sprite({
  72.                 id = "arm"
  73.                 file = "ArmourBar.png"
  74.                 align = "hud_top"
  75.                 move = { down = 92, left = 200}
  76.                 Size = VectorScreen( 270, 60 )
  77.             })
  78. UI.ProgressBar({
  79.                     id = "ARMBAR"  
  80.                     BackgroundShade = 0.2
  81.                     align = "hud_top"
  82.                     MaxValue = 100
  83.                     Thickness = 2
  84.                     selectedColour = Colour( 160, 160, 160 )
  85.                     StartColour = Colour( 160, 160, 160 )
  86.                     EndColour = Colour( 160, 160, 160 )
  87.                     Size = VectorScreen(63, 23)
  88.                     Value = A
  89.                 move = { down = 120, left = 106}
  90.                 }) 
  91.                 UI.Label({
  92.                     id = "ABar"
  93.                     align = "hud_top"
  94.                     Text = A
  95.                     TextColour = Colour( 255, 255, 255 )
  96.                     FontFlags = GUI_FFLAG_BOLD | GUI_FFLAG_OUTLINE
  97.                     FontSize = 12
  98.                 move = { down = 119, left = 107}
  99.                 })
  100.         ]
  101.     })
  102. Timer.Create(this, function(ext = null)
  103. {
  104.     local plr = World.FindLocalPlayer();
  105. local A = plr.Armour;
  106.     UI.ProgressBar("ARMBAR").Value = A;
  107.     UI.Label("ABar").Text = A;
  108. }, 100, 0, "A");
  109. }
RAW Paste Data