Advertisement
Shy353

GUI Health and Armour bar for VCMP

Sep 12th, 2020 (edited)
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.41 KB | None | 0 0
  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. last updated: 3/31/2021
  4. - Changed timer to Script::ScriptProcess function.
  5. -Shy
  6. */
  7. // Remove the health and armour bar from the hud
  8. Hud.RemoveFlags(HUD_FLAG_HEALTH);
  9.  
  10. // official function, scriptload
  11. function Script::ScriptLoad()
  12. {
  13. //Show the armor and UI health to the client
  14.     ShowHealth();
  15. }
  16.  
  17. function Script::ScriptProcess()
  18. {
  19. updateHealthVal(); //better than a timer, remember to not use the function two times in your scripts or different files even!
  20. }
  21.  
  22. function updateHealthVal()
  23. {
  24.     local plr = World.FindLocalPlayer();
  25. local H = plr.Health, A = plr.Armour;
  26.     UI.ProgressBar("HPBAR").Value = H; //updatethe value again
  27.     UI.Label("Bar").Text = H; //update the player's health label again
  28.     UI.ProgressBar("ARMBAR").Value = A; //update armour value
  29.     UI.Label("ABar").Text = A; //update text
  30. }
  31.  
  32. // the main function which'll show Armour & health bar
  33. function ShowHealth()
  34. {
  35. local plr = World.FindLocalPlayer(); // find player (client side)
  36. local H = plr.Health; // player's Hp
  37. local A = plr.Armour; // PLAYER'S Armour
  38. //Health main canvas
  39. UI.Canvas({
  40.         id = "canvy"
  41.         align = "bottom_left"
  42.         children = [
  43.                                         UI.Sprite({
  44.                 id = "heal"
  45.                 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 */
  46.                 align = "hud_top"
  47.                 move = { down = 92, left = 320}
  48.                 Size = VectorScreen( 270, 60 )
  49.             })
  50. //ProgressBar which'll show health
  51. UI.ProgressBar({
  52.                     id = "HPBAR"  
  53.                     BackgroundShade = 0.2
  54.                     align = "hud_top"
  55.                     MaxValue = 100
  56.                     Thickness = 2
  57.                     selectedColour = Colour( 255, 0, 0 )
  58.                     StartColour = Colour( 255, 0, 0 )
  59.                     EndColour = Colour( 0, 210, 0 )
  60.                     Size = VectorScreen(63, 23)
  61.                     Value = H // reduces along with the health
  62.                 move = { down = 118, left = 226}
  63.                 })
  64. // label shows the hp player has   
  65.                 UI.Label({
  66.                     id = "Bar"
  67.                     align = "hud_top"
  68.                     Text = H
  69.                     TextColour = Colour( 255, 255, 255 )
  70.                     FontFlags = GUI_FFLAG_BOLD | GUI_FFLAG_OUTLINE
  71.                     FontSize = 12
  72.                 move = { down = 117, left = 228}
  73.                 })
  74.         ]
  75.     })
  76. /* The following is same as the above health canvas, just sprites are changed and value is set to armour */
  77. UI.Canvas({
  78.         id = "acanvy"
  79.         align = "bottom_left"
  80.         children = [
  81.                             UI.Sprite({
  82.                 id = "arm"
  83.                 file = "ArmourBar.png"
  84.                 align = "hud_top"
  85.                 move = { down = 92, left = 200}
  86.                 Size = VectorScreen( 270, 60 )
  87.             })
  88. UI.ProgressBar({
  89.                     id = "ARMBAR"  
  90.                     BackgroundShade = 0.2
  91.                     align = "hud_top"
  92.                     MaxValue = 100
  93.                     Thickness = 2
  94.                     selectedColour = Colour( 160, 160, 160 )
  95.                     StartColour = Colour( 160, 160, 160 )
  96.                     EndColour = Colour( 160, 160, 160 )
  97.                     Size = VectorScreen(63, 23)
  98.                     Value = A
  99.                 move = { down = 120, left = 106}
  100.                 }) 
  101.                 UI.Label({
  102.                     id = "ABar"
  103.                     align = "hud_top"
  104.                     Text = A
  105.                     TextColour = Colour( 255, 255, 255 )
  106.                     FontFlags = GUI_FFLAG_BOLD | GUI_FFLAG_OUTLINE
  107.                     FontSize = 12
  108.                 move = { down = 119, left = 107}
  109.                 })
  110.         ]
  111.     })
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement