Guest User

Untitled

a guest
May 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. citadel_hud = {};
  2.  
  3. local function clr( color ) return color.r, color.g, color.b, color.a; end
  4.  
  5. function citadel_hud:PaintBar( x, y, w, h, colors, value )
  6.  
  7.         self:PaintPanel( x, y, w, h );
  8.  
  9.         x = x + 1; y = y + 1;
  10.         w = w - 2; h = h - 2;
  11.      
  12.         local width = w * math.Clamp( value, 0, 1 );
  13.         local shade = 4;
  14.      
  15.         surface.SetDrawColor( clr( colors.shade ) );
  16.         surface.DrawRect( x, y, width, shade );
  17.      
  18.         surface.SetDrawColor( clr( colors.fill ) );
  19.         surface.DrawRect( x, y + shade, width, h - shade );
  20.  
  21. end
  22.  
  23. function citadel_hud:PaintPanel( x, y, w, h, colors )
  24.    
  25.         surface.SetDrawColor( clr( colors.background.border ) );
  26.         surface.DrawOutlinedRect( x, y, w, h );
  27.        
  28.         x = x + 1; y = y + 1;
  29.         w = w - 2; h = h - 2;
  30.        
  31.         surface.SetDrawColor( clr( colors.background.background ) );
  32.         surface.DrawRect( x, y, w, h );
  33.    
  34. end
  35.  
  36. function citadel_hud:PaintText( x, y, text, font, colors )
  37.  
  38.         surface.SetFont( font );
  39.         surface.SetTextPos( x + 1, y + 1 );
  40.         surface.SetTextColor( clr( colors.shadow ) );
  41.         surface.DrawText( text );
  42.        
  43.         surface.SetTextPos( x, y );
  44.         surface.SetTextColor( clr( colors.text ) );
  45.         surface.DrawText( text );
  46.        
  47. end
  48.  
  49. function citadel_hud:TextSize( text, font )
  50.  
  51.         surface.SetFont( font );
  52.         return surface.GetTextSize( text );
  53.        
  54. end
  55.  
  56.  
  57. local vars =
  58. {
  59.  
  60.         font = "TargetID",
  61.        
  62.         padding = 10,
  63.         margin = 35,
  64.        
  65.         text_spacing = 2,
  66.         bar_spacing = 5,
  67.        
  68.         bar_height = 16,
  69.        
  70.         width = 0.25
  71.        
  72. };
  73.  
  74. local colors =
  75. {
  76.  
  77.         background =
  78.         {
  79.        
  80.                 border = Color( 190, 255, 128, 255 ),
  81.                 background = Color( 120, 240, 0, 75 )
  82.        
  83.         },
  84.        
  85.         text =
  86.         {
  87.        
  88.                 shadow = Color( 0, 0, 0, 200 ),
  89.                 text = Color( 255, 255, 255, 255 ),
  90.                
  91.         },
  92.        
  93.         health_bar =
  94.         {
  95.        
  96.                 border = Color( 255, 0, 0, 255 ),
  97.                 background = Color( 255, 0, 0, 75 ),
  98.                 shade = Color( 255, 104, 104, 255 ),
  99.                 fill = Color( 232, 0, 0, 255 )
  100.                
  101.         },
  102.        
  103.         suit_bar =
  104.         {
  105.                 border = Color( 0, 0, 255, 255 ),
  106.                 background = Color( 0, 0, 255, 75 ),
  107.                 shade = Color( 136, 136, 255, 255 ),
  108.                 fill = Color( 0, 0, 219, 255 )
  109.                
  110.         }  
  111.  
  112. };     
  113.  
  114.  
  115. function citadel_HUDPaint()
  116.  
  117.     local client = LocalPlayer();
  118.  
  119.     if( !client:Alive() ) then return; end
  120.    
  121.     local th = citadel_hud:TextSize( "TEXT", vars.font );
  122.    
  123.     local i = 2;
  124.    
  125.     local width = vars.width * ScrW();
  126.     local bar_width = width - ( vars.padding * i );
  127.     local height = ( vars.padding * i ) + ( th * i ) + ( vars.text_spacing * i ) + ( vars.bar_height * i ) + vars.bar_spacing;
  128.    
  129.     local x = vars.margin;
  130.     local y = ScrH() - vars.margin - height;
  131.    
  132.     local cx = x + vars.padding;
  133.     local cy = y + vars.padding;
  134.    
  135.     citadel_hud:PaintPanel( x, y, width, height, colors.background );
  136.    
  137.     local by = th + vars.text_spacing;
  138.    
  139.     local text = string.format( "Health: "..client:Health() );
  140.     citadel_hud:PaintText( cx, cy, text, vars.font, colors.text );
  141.     citadel_hud:PaintBar( cx, cy + by, bar_width, vars.bar_height, colors.health_bar, client:Health() / 100 );
  142.    
  143.     by = by + vars.bar_height + vars.bar_spacing;
  144.    
  145.     local text = string.format( "Suit: "..client:Armor() );
  146.     citadel_hud:PaintText( cx, cy + by, text, vars.font, colors.text );
  147.     citadel_hud:PaintBar( cx, cy + by + th + vars.text_spacing, bar_width, vars.bar_height, colors.suit_bar, client:Armor() / 100 );
  148.  
  149. end
  150. hook.Add( "HUDPaint", "PaintCitadelHud", citadel_HUDPaint );
Add Comment
Please, Sign In to add comment