Advertisement
Guest User

hud

a guest
Jan 1st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.33 KB | None | 0 0
  1. local function Base()
  2.  
  3.  
  4.  
  5. draw.RoundedBox(0, 10, ScrH() - 160, 450, 150, Color(255,255,255,255))
  6. draw.RoundedBox(0, 10, ScrH() - 190, 450, 25, Color(255,255,255,255))
  7. draw.RoundedBox(0, 10, ScrH() - 220, 450, 25, Color(255,255,255,255))
  8. draw.RoundedBox(0, 10, ScrH() - 220, 450, 25, Color(72,72,72,255))
  9. draw.RoundedBox(0, 100, ScrH() - 130, 350, 2, Color(255,93,0,255)) --Line 1
  10. draw.RoundedBox(0, 100, ScrH() - 98, 60, 2, Color(255,93,0,255)) -- Line 2
  11. draw.RoundedBox(0, 100, ScrH() - 70, 140, 2, Color(255,93,0,255)) -- Line 3
  12. draw.RoundedBox(0, 100, ScrH() - 43, 140, 2, Color(255,93,0,255)) -- Line 4
  13.  
  14.  
  15.  
  16. --HUD DRAW--
  17.  
  18.  draw.DrawText( LocalPlayer():Nick(), "Trebuchet24", 100, ScrH () - 155 + 1, Color(255,93,0,255))
  19.  draw.DrawText( "$"..LocalPlayer():getDarkRPVar( "salary" ), "Trebuchet24", 100, ScrH () - 125 + 2, Color(255,93,0,255))
  20.  draw.DrawText( "$"..LocalPlayer():getDarkRPVar( "money" ), "Trebuchet24", 100, ScrH () - 95 + 2, Color(255,93,0,255))
  21.  draw.DrawText( LocalPlayer():getDarkRPVar( "job" ), "Trebuchet24", 100, ScrH () - 70 + 2, Color(255,93,0,255))
  22.  draw.SimpleText( "InvasionRP" ,"Trebuchet24", 10, ScrH() - 250, Color(0,161,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  23.  
  24.  
  25. --HUD HEALTH--
  26.  
  27. local DrawHealth = LocalPlayer():Health() or 0
  28. local EchoHealth = LocalPlayer():Health() or 0
  29.  
  30.         if DrawHealth > 100 then DrawHealth = 100 end
  31.         if DrawHealth < 0 then DrawHealth = 0 end
  32.  
  33.         if DrawHealth != 0 then
  34.                 draw.RoundedBox(0, 10, ScrH () - 220, (550-100) * DrawHealth / 100, 35-10, Color(255,0,0,255))
  35.                
  36.                 --HUD ARMOR--
  37.                
  38.                 draw.RoundedBox(0, 10, ScrH () - 190, 475-25, 25, Color(72,72,72,255))
  39.  
  40.  
  41. local DrawHealth = LocalPlayer():Armor() or 0
  42. local EchoHealth = LocalPlayer():Armor() or 0
  43.  
  44. if DrawHealth > 100 then DrawHealth = 100 end
  45. if DrawHealth < 0 then DrawHealth = 0 end
  46.  
  47.  
  48. draw.RoundedBox(0, 10, ScrH () - 190, (45) * DrawHealth / 10, 25, Color(0,161,255,255))
  49.  
  50. draw.DrawText( "Armor: "..EchoHealth, "Trebuchet24", 13, ScrH () - 187 - 2, Color(255,255,255,255))
  51.  
  52.         end
  53.  
  54.         draw.DrawText( "Health: "..EchoHealth, "Trebuchet24", 12, ScrH () - 223 + 2, Color(255,255,255,255))
  55.        
  56.         local hide = {
  57.     CHudHealth = true,
  58.     CHudBattery = true,
  59. }
  60.  
  61. hook.Add( "HUDShouldDraw", "HideHUD", function( name )
  62.     if ( hide[ name ] ) then
  63.         return false
  64.     end
  65.  
  66.     -- Don't return anything here, it may break other addons that rely on this hook.
  67. end )
  68.  
  69.  
  70. end
  71.  
  72. --Hide Original Hud
  73.  
  74. hook.Add( "HUDShouldDraw", "hide hud", function( name )
  75.      if ( name == "CHudHealth" or name == "CHudBattery" ) then
  76.          return false
  77.      end
  78.    
  79.      -- Never return anything default here, it will break other addons using this hook.
  80. end )
  81.  
  82.  
  83.  hook.Add("HUDPaint", "PlayerModel", function( )
  84.     local _p = LocalPlayer( );
  85.  
  86.     // Make sure valid player, otherwise model won't work
  87.     if ( !IsValid( _p ) ) then return; end
  88.  
  89.     // Useful vars we reuse...
  90.     local _model = _p:GetModel( );
  91.  
  92.     // Make sure the vgui element hasn't been made...
  93.     if ( !PlayerModel || !ispanel( PlayerModel ) ) then
  94.         PlayerModel = vgui.Create( "DModelPanel" );
  95.         PlayerModel:SetModel( _model );
  96.         PlayerModel.__Model = _model;
  97.         PlayerModel:SetPos( 12, ScrH( ) - 100 - 100 );
  98.         PlayerModel:SetAnimated( true );
  99.         PlayerModel.bAnimated = false;
  100.         PlayerModel:SetSize( 75, 150 )
  101.         PlayerModel:SetCamPos( Vector( 16, 0, 65 ) );
  102.         PlayerModel:SetLookAt( Vector( 0, 0, 65 ) );
  103.         PlayerModel:ParentToHUD( );
  104.     end
  105.  
  106.     // Update the model if it changes
  107.     if ( _p:GetModel( ) != PlayerModel.__Model ) then
  108.         PlayerModel:SetModel( _model );
  109.         PlayerModel.__Model = _model;
  110.     end
  111.  
  112.     // Draw it....
  113.     -- up to you.
  114. end );
  115.  
  116. /*---------------------------------------------------------------------------
  117. HUD ConVars
  118. ---------------------------------------------------------------------------*/
  119. local ConVars = {}
  120. local HUDWidth
  121. local HUDHeight
  122. local Color = Color
  123. local cvars = cvars
  124. local DarkRP = DarkRP
  125. local CurTime = CurTime
  126. local draw = draw
  127. local GetConVar = GetConVar
  128. local IsValid = IsValid
  129. local Lerp = Lerp
  130. local localplayer
  131. local math = math
  132. local pairs = pairs
  133. local ScrW, ScrH = ScrW, ScrH
  134. local SortedPairs = SortedPairs
  135. local string = string
  136. local surface = surface
  137. local table = table
  138. local timer = timer
  139. local tostring = tostring
  140.  
  141. CreateClientConVar("weaponhud", 0, true, false)
  142.  
  143. local colors = {}
  144. colors.black = Color(0, 0, 0, 255)
  145. colors.blue = Color(0, 0, 255, 255)
  146. colors.brightred = Color(200, 30, 30, 255)
  147. colors.darkred = Color(0, 0, 70, 100)
  148. colors.darkblack = Color(0, 0, 0, 200)
  149. colors.gray1 = Color(0, 0, 0, 155)
  150. colors.gray2 = Color(51, 58, 51,100)
  151. colors.red = Color(255, 0, 0, 255)
  152. colors.white = Color(255, 255, 255, 255)
  153. colors.white1 = Color(255, 255, 255, 200)
  154.  
  155. local function ReloadConVars()
  156.         ConVars = {
  157.                 background = {0,0,0,100},
  158.                 Healthbackground = {0,0,0,200},
  159.                 Healthforeground = {140,0,0,180},
  160.                 HealthText = {255,255,255,200},
  161.                 Job1 = {0,0,150,200},
  162.                 Job2 = {0,0,0,255},
  163.                 salary1 = {0,150,0,200},
  164.                 salary2 = {0,0,0,255}
  165.         }
  166.  
  167.         for name, Colour in pairs(ConVars) do
  168.                 ConVars[name] = {}
  169.                 for num, rgb in SortedPairs(Colour) do
  170.                         local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
  171.                         table.insert(ConVars[name], CVar:GetInt())
  172.  
  173.                         if not cvars.GetConVarCallbacks(name..num, false) then
  174.                                 cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
  175.                         end
  176.                 end
  177.                 ConVars[name] = Color(unpack(ConVars[name]))
  178.         end
  179.  
  180.  
  181.         HUDWidth = (GetConVar("HudW") or  CreateClientConVar("HudW", 240, true, false)):GetInt()
  182.         HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
  183.  
  184.         if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
  185.                 cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
  186.                 cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
  187.         end
  188. end
  189. ReloadConVars()
  190.  
  191. local Scrw, Scrh, RelativeX, RelativeY
  192. /*---------------------------------------------------------------------------
  193. HUD Seperate Elements
  194. ---------------------------------------------------------------------------*/
  195.  
  196. local Page = Material("icon16/page_white_text.png")
  197. local function GunLicense()
  198.         if localplayer:getDarkRPVar("HasGunlicense") then
  199.                 surface.SetMaterial(Page)
  200.                 surface.SetDrawColor(255, 255, 255, 255)
  201.                 surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32)
  202.         end
  203. end
  204.  
  205. local function Agenda()
  206.         local ply = LocalPlayer()
  207.  
  208.         local agenda = ply:getAgendaTable()
  209.         if not agenda then return end
  210.  
  211.         draw.RoundedBox(10, 10, 10, 460, 110, colors.gray1)
  212.         draw.RoundedBox(10, 12, 12, 456, 106, colors.gray2)
  213.         draw.RoundedBox(10, 12, 12, 456, 20, colors.darkred)
  214.  
  215.         draw.DrawNonParsedText(agenda.Title, "DarkRPHUD1", 30, 12, colors.red, 0)
  216.  
  217.         local text = ply:getDarkRPVar("agenda") or ""
  218.  
  219.         text = text:gsub("//", "\n"):gsub("\\n", "\n")
  220.         text = DarkRP.textWrap(text, "DarkRPHUD1", 440)
  221.         draw.DrawNonParsedText(text, "DarkRPHUD1", 30, 35, colors.white, 0)
  222. end
  223.  
  224. local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
  225. local function DrawVoiceChat()
  226.         if localplayer.DRPIsTalking then
  227.                 local chbxX, chboxY = chat.GetChatBoxPos()
  228.  
  229.                 local Rotating = math.sin(CurTime()*3)
  230.                 local backwards = 0
  231.                 if Rotating < 0 then
  232.                         Rotating = 1-(1+Rotating)
  233.                         backwards = 180
  234.                 end
  235.                 surface.SetTexture(VoiceChatTexture)
  236.                 surface.SetDrawColor(ConVars.Healthforeground)
  237.                 surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
  238.         end
  239. end
  240.  
  241. CreateConVar("DarkRP_LockDown", 0, {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE})
  242. local function LockDown()
  243.         local chbxX, chboxY = chat.GetChatBoxPos()
  244.         if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
  245.                 local cin = (math.sin(CurTime()) + 1) / 2
  246.                 local chatBoxSize = math.floor(ScrH() / 4)
  247.                 draw.DrawNonParsedText(DarkRP.getPhrase("lockdown_started"), "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
  248.         end
  249. end
  250.  
  251. local Arrested = function() end
  252.  
  253. usermessage.Hook("GotArrested", function(msg)
  254.         local StartArrested = CurTime()
  255.         local ArrestedUntil = msg:ReadFloat()
  256.  
  257.         Arrested = function()
  258.                 if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then
  259.                 draw.DrawNonParsedText(DarkRP.getPhrase("youre_arrested", math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, colors.white, 1)
  260.                 elseif not localplayer:getDarkRPVar("Arrested") then
  261.                         Arrested = function() end
  262.                 end
  263.         end
  264. end)
  265.  
  266. local AdminTell = function() end
  267.  
  268. usermessage.Hook("AdminTell", function(msg)
  269.         timer.Destroy("DarkRP_AdminTell")
  270.         local Message = msg:ReadString()
  271.  
  272.         AdminTell = function()
  273.                 draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, colors.darkblack)
  274.                 draw.DrawNonParsedText(DarkRP.getPhrase("listen_up"), "GModToolName", ScrW() / 2 + 10, 10, colors.white, 1)
  275.                 draw.DrawNonParsedText(Message, "ChatFont", ScrW() / 2 + 10, 80, colors.brightred, 1)
  276.         end
  277.  
  278.         timer.Create("DarkRP_AdminTell", 10, 1, function()
  279.                 AdminTell = function() end
  280.         end)
  281. end)
  282.  
  283. /*---------------------------------------------------------------------------
  284. Entity HUDPaint things
  285. ---------------------------------------------------------------------------*/
  286. local function DrawPlayerInfo(ply)
  287.         local pos = ply:EyePos()
  288.  
  289.         pos.z = pos.z + 10 -- The position we want is a bit above the position of the eyes
  290.         pos = pos:ToScreen()
  291.         pos.y = pos.y - 50 -- Move the text up a few pixels to compensate for the height of the text
  292.  
  293.         if GAMEMODE.Config.showname and not ply:getDarkRPVar("wanted") then
  294.                 draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
  295.                 draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  296.         end
  297.  
  298.         if GAMEMODE.Config.showhealth and not ply:getDarkRPVar("wanted") then
  299.                 draw.DrawNonParsedText(DarkRP.getPhrase("health", ply:Health()), "DarkRPHUD2", pos.x + 1, pos.y + 21, colors.black, 1)
  300.                 draw.DrawNonParsedText(DarkRP.getPhrase("health", ply:Health()), "DarkRPHUD2", pos.x, pos.y + 20, colors.white1, 1)
  301.         end
  302.  
  303.         if GAMEMODE.Config.showjob then
  304.                 local teamname = team.GetName(ply:Team())
  305.                 draw.DrawNonParsedText(ply:getDarkRPVar("job") or teamname, "DarkRPHUD2", pos.x + 1, pos.y + 41, colors.black, 1)
  306.                 draw.DrawNonParsedText(ply:getDarkRPVar("job") or teamname, "DarkRPHUD2", pos.x, pos.y + 40, colors.white1, 1)
  307.         end
  308.  
  309.         if ply:getDarkRPVar("HasGunlicense") then
  310.                 surface.SetMaterial(Page)
  311.                 surface.SetDrawColor(255,255,255,255)
  312.                 surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
  313.         end
  314. end
  315.  
  316. local function DrawWantedInfo(ply)
  317.         if not ply:Alive() then return end
  318.  
  319.         local pos = ply:EyePos()
  320.         if not pos:isInSight({localplayer, ply}) then return end
  321.  
  322.         pos.z = pos.z + 14
  323.         pos = pos:ToScreen()
  324.  
  325.         if GAMEMODE.Config.showname then
  326.                 draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
  327.                 draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  328.         end
  329.  
  330.         local wantedText = DarkRP.getPhrase("wanted", tostring(ply:getDarkRPVar("wantedReason")))
  331.  
  332.         draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x, pos.y - 40, colors.white1, 1)
  333.         draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x + 1, pos.y - 41, colors.red, 1)
  334. end
  335.  
  336. /*---------------------------------------------------------------------------
  337. The Entity display: draw HUD information about entities
  338. ---------------------------------------------------------------------------*/
  339. local function DrawEntityDisplay()
  340.  
  341.         local shootPos = localplayer:GetShootPos()
  342.         local aimVec = localplayer:GetAimVector()
  343.  
  344.         for k, ply in pairs(players or player.GetAll()) do
  345.                 if not ply:Alive() or ply == localplayer then continue end
  346.                 local hisPos = ply:GetShootPos()
  347.                 if ply:getDarkRPVar("wanted") then DrawWantedInfo(ply) end
  348.  
  349.                 if GAMEMODE.Config.globalshow then
  350.                         DrawPlayerInfo(ply)
  351.                 -- Draw when you're (almost) looking at him
  352.                 elseif not GAMEMODE.Config.globalshow and hisPos:DistToSqr(shootPos) < 160000 then
  353.                         local pos = hisPos - shootPos
  354.                         local unitPos = pos:GetNormalized()
  355.                         if unitPos:Dot(aimVec) > 0.95 then
  356.                                 local trace = util.QuickTrace(shootPos, pos, localplayer)
  357.                                 if trace.Hit and trace.Entity ~= ply then return end
  358.                                 DrawPlayerInfo(ply)
  359.                         end
  360.                 end
  361.         end
  362.  
  363.         local tr = localplayer:GetEyeTrace()
  364.  
  365.         if IsValid(tr.Entity) and tr.Entity:isKeysOwnable() and tr.Entity:GetPos():Distance(localplayer:GetPos()) < 200 then
  366.                 tr.Entity:drawOwnableInfo()
  367.         end
  368. end
  369.  
  370. /*---------------------------------------------------------------------------
  371. Drawing death notices
  372. ---------------------------------------------------------------------------*/
  373. function GAMEMODE:DrawDeathNotice(x, y)
  374.         if not GAMEMODE.Config.showdeaths then return end
  375.         self.BaseClass:DrawDeathNotice(x, y)
  376. end
  377.  
  378. /*---------------------------------------------------------------------------
  379. Display notifications
  380. ---------------------------------------------------------------------------*/
  381. local function DisplayNotify(msg)
  382.         local txt = msg:ReadString()
  383.         GAMEMODE:AddNotify(txt, msg:ReadShort(), msg:ReadLong())
  384.         surface.PlaySound("buttons/lightswitch2.wav")
  385.  
  386.         -- Log to client console
  387.         print(txt)
  388. end
  389. usermessage.Hook("_Notify", DisplayNotify)
  390.  
  391. /*---------------------------------------------------------------------------
  392. Remove some elements from the HUD in favour of the DarkRP HUD
  393. ---------------------------------------------------------------------------*/
  394. function GAMEMODE:HUDShouldDraw(name)
  395.         if name == "CHudHealth" or
  396.                 name == "CHudBattery" or
  397.                 name == "CHudSuitPower" or
  398.                 (HelpToggled and name == "CHudChat") then
  399.                         return false
  400.         else
  401.                 return true
  402.         end
  403. end
  404.  
  405. /*---------------------------------------------------------------------------
  406. Disable players' names popping up when looking at them
  407. ---------------------------------------------------------------------------*/
  408. function GAMEMODE:HUDDrawTargetID()
  409.   return false
  410. end
  411.  
  412. /*---------------------------------------------------------------------------
  413. Actual HUDPaint hook
  414. ---------------------------------------------------------------------------*/
  415. function DrawHUD()
  416.        localplayer = localplayer and IsValid(localplayer) and localplayer or LocalPlayer()
  417.        if not IsValid(localplayer) then return end
  418.      
  419.        -- Custom
  420.        Base()
  421.      
  422.        -- Default
  423.        GunLicense()
  424.        Agenda()
  425.        DrawVoiceChat()
  426.        LockDown()
  427.        Arrested()
  428.        AdminTell()
  429.        DrawEntityDisplay()
  430.      
  431. end
  432. hook.Add("HUDPaint", "DrawHUD", DrawHUD)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement