DarkNessProvides

GMOD Hud with ammo count :)

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