Guest User

Untitled

a guest
Apr 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.01 KB | None | 0 0
  1. ----------------------------------------------------------------
  2. //Setting up some database stuff
  3. ----------------------------------------------------------------
  4. HUD = {}
  5. ICON = {}
  6. ICON.Health = surface.GetTextureID("hud/plus")
  7. ICON.Armor = surface.GetTextureID("hud/shield3")
  8.  
  9. ----------------------------------------------------------------
  10. //Setting up some variables
  11. ----------------------------------------------------------------
  12.  
  13.  function PostEntity()
  14.     ply = LocalPlayer()
  15.     FakeHealth = LocalPlayer():Health()
  16.     FakeArmor = LocalPlayer():Armor()
  17.     len = 0
  18.     Newlen = 0
  19. end
  20. hook.Add( "InitPostEntity", "MapStartTrigger", PostEntity )
  21.  
  22. local NewName
  23. ----------------------------------------------------------------
  24. //All the HUD stuff
  25. ----------------------------------------------------------------
  26. function HUD.display()
  27.     local ScrY = ScrH()/2; local ScrX = ScrH()/2;
  28.  
  29.  
  30.  
  31. ----------------------------------------------------------------
  32. //HUD - Name
  33. ----------------------------------------------------------------
  34.     StrLen = string.len(LocalPlayer():Nick())
  35.     shortName = string.sub(ply:Nick(), 1, 23)
  36.    
  37.  
  38.     if (StrLen >= 23) then
  39.     DrawBox(ScrX-450, ScrY-500, Newlen+35, 18, 100, 100, 100, 100) -- Name BG Box
  40.     DrawBoxLine(ScrX-450, ScrY-500, Newlen+35, 18, 230, 230, 230, 255) -- Name Box Line
  41.     DrawText(shortName.."...",  ScrX-441, ScrY-499, 255, 255, 255, 255) -- Name Text
  42.     Newlen = surface.GetTextSize(shortName)
  43.     end
  44.    
  45.     if (StrLen < 23) then
  46.     DrawBox(ScrX-450, ScrY-500, len+20, 18, 100, 100, 100, 100) -- Name BG Box
  47.     DrawText(ply:Nick(), ScrX-441, ScrY-499, 255, 255, 255, 255) -- Name Text
  48.     len = surface.GetTextSize(ply:Nick())
  49.     DrawBoxLine(ScrX-450, ScrY-500, len+20, 18, 230, 230, 230, 255) -- Name Box Line
  50.     end
  51.    
  52.  
  53. ----------------------------------------------------------------
  54. //HUD - Health
  55. ----------------------------------------------------------------
  56.     FakeHealth = math.Approach(FakeHealth, LocalPlayer():Health(), 0.4) --Slow health movement
  57.     Frac = FakeHealth/100
  58.     HPBar = math.Clamp(Frac,0,1)
  59.     local color = 255 * math.Clamp(math.sin(CurTime()*4),0,1) -- Health flashing
  60.    
  61.     DrawBox(ScrX-450, ScrY-480, 20, 18, 100, 100, 100, 100) -- HP Icon BG Box
  62.     DrawBox(ScrX-425, ScrY-478, 500, 14, 100, 100, 100, 100) -- HP Bar BG Box
  63.     DrawBoxLine(ScrX-450, ScrY-480, 20, 18, 255, 255, 255, 255) -- Health Icon Box
  64.     DrawTexture(ICON.Health, ScrX-448, ScrY-479, 16, 16, 255, 255, 255, 255) -- Health Icon
  65.     DrawBoxLine(ScrX-425, ScrY-478, 500, 14, 255, 255, 255, 255) -- Health Box
  66.    
  67.     DrawBox(ScrX-422, ScrY-475, HPBar*494, 8, 255, 255, 255, 255) -- Health Bar
  68.     if (LocalPlayer():Health()) <=40 then
  69.     DrawBox(ScrX-422, ScrY-475, HPBar*494, 8, 255, 200, 0, 255)end -- Health Bar
  70.     if (LocalPlayer():Health()) <=35 then
  71.     DrawBox(ScrX-422, ScrY-475, HPBar*494, 8, 255, 100, 0, 255)end -- Health Bar
  72.     if (LocalPlayer():Health()) <=25 then
  73.     DrawBox(ScrX-422, ScrY-475, HPBar*494, 8, color, 0, 0, color)end -- Health Bar
  74.  
  75. ----------------------------------------------------------------
  76. //HUD - Stamina
  77. ----------------------------------------------------------------
  78.     FakeArmor = math.Approach(FakeArmor, LocalPlayer():Armor(), 0.4) --Slow health movement
  79.     FracArm = FakeArmor/100
  80.     ArmBar = math.Clamp(FracArm,0,1)
  81.    
  82.    
  83.     DrawBox(ScrX-450, ScrY-460, 20, 18, 100, 100, 100, 100) -- Stamina Icon BG Box
  84.     DrawBox(ScrX-425, ScrY-458, 500, 14, 100, 100, 100, 100) -- Stamina Bar BG Box
  85.     DrawBoxLine(ScrX-450, ScrY-460, 20, 18, 255, 255, 255, 255) -- Stamina Icon Box
  86.     DrawTexture(ICON.Armor, ScrX-448, ScrY-459, 16, 16, 255, 255, 255, 255) -- Stamina Icon
  87.    
  88.     DrawBoxLine(ScrX-425, ScrY-458, 500, 14, 255, 255, 255, 255) -- Stamina Bar Box
  89.     DrawBox(ScrX-422, ScrY-455, ArmBar*494, 8, 255, 255, 255, 255) -- Stamina Bar
  90. --  DrawBox(ScrX-422, ScrY-455, Stamina, 8, 255, 200, 0, Stambeat)
  91.    
  92.    
  93.  
  94. end
  95. hook.Add("HUDPaint", "DrawHUD", HUD.display)
  96.  
  97.  
  98.  
  99.  
  100.  
  101. -------------------------------------------------------------------------
  102. //Custom functions -- Makes it easier to apply in the main function
  103. -------------------------------------------------------------------------
  104. function DrawBox(x, y, w, h, r, g, b, a)
  105. surface.SetDrawColor( r, g, b, a )
  106. surface.DrawRect(x, y, w, h)
  107. end
  108. function DrawBoxLine(x, y, w, h, r, g, b, a)
  109. surface.SetDrawColor( r, g, b, a )
  110. surface.DrawOutlinedRect(x, y, w, h)
  111. end
  112. function DrawText(text, x, y, r, g, b, a)
  113. surface.SetTextColor( r, g, b, a )
  114. surface.SetTextPos( x, y )
  115. surface.SetFont( "MenuLarge" )
  116. surface.DrawText( text )
  117. end
  118. function DrawTexture(tex, x, y, w, h, r, g, b, a)
  119. surface.SetDrawColor( r, g, b, a )
  120. surface.SetTexture( tex );
  121. surface.DrawTexturedRect( x, y, w, h);
  122. end
  123.  
  124.  
  125.  
  126.  
  127. -------------------------------------------------------------------------
  128. //Hide original HUD
  129. -------------------------------------------------------------------------
  130. function hidehud(name)
  131.     for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do
  132.         if name == v then return false end
  133.     end
  134. end
  135. hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)
Add Comment
Please, Sign In to add comment