shadowndacorner

DarkRP hud

Apr 16th, 2012
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.16 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. HUD ConVars
  3. ---------------------------------------------------------------------------*/
  4. local ConVars = {}
  5. local HUDWidth
  6. local HUDHeight
  7. local RelativeX
  8. local RelativeY
  9.  
  10. local function ReloadConVars()
  11.     ConVars = {
  12.         background = Color(0,0,0,100),
  13.         Healthbackground = Color(0,0,0,200),
  14.         Healthforeground = Color(140,0,0,180),
  15.         HealthText = Color(255,255,255,200),
  16.         Job1 = Color(0,0,150,200),
  17.         Job2 = Color(0,0,0,255),
  18.         salary1 = Color(0,150,0,200),
  19.         salary2 = Color(0,0,0,255)
  20.     }
  21.     RelativeX = 0
  22.     RelativeY = 40
  23.    
  24.     HUDWidth = ScrW()
  25.     HUDHeight = ScrH()/20
  26.     //HUDWidth = (GetConVar("HudW") or  CreateClientConVar("HudW", 240, true, false)):GetInt()
  27.     //HUDHeight = ((GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()+15)
  28. end
  29. ReloadConVars()
  30.  
  31.  
  32. //local Scrw, Scrh, RelativeX, RelativeY
  33. /*---------------------------------------------------------------------------
  34. HUD Seperate Elements
  35. ---------------------------------------------------------------------------*/
  36. local Health = 0
  37. local function DrawHealth(offset)
  38.     offset=offset or 80
  39.     Health = (Health == LocalPlayer():Health() and Health) or Lerp(0.1, Health, LocalPlayer():Health())
  40.     local DrawHealth = math.Clamp(Health / GetConVarNumber("startinghealth"), 0, 1)
  41.     local Border = math.Min(6, math.pow(2, math.Round(3*DrawHealth)))
  42.     draw.DrawText("Health", "TargetID", RelativeX + offset-40+4+6, RelativeY - 32, Color(255, 255, 255, 255), 1)
  43.     draw.RoundedBox(Border, RelativeX + offset+4, RelativeY - 30, /*HUDWidth - 8 -*/ ScrW()/5-8, 20, Color(0,0,0,200))
  44.     draw.RoundedBox(Border, RelativeX + offset+5, RelativeY - 29, /*(HUDWidth - 9)*/ (ScrW()/5-9) * DrawHealth, 18, Color(140,0,0,180))
  45.     draw.DrawText(math.Max(0, math.Round(Health)), "TargetID", RelativeX + offset+4 + (ScrW()/5-8)/2, RelativeY - 32, Color(255, 255, 255, 255), 1)
  46. end
  47.  
  48. local function DrawInfo()
  49.     local ply = LocalPlayer()
  50.     local Salary
  51.     if ply:EV_GetRank()=="donator" or ply:IsAdmin() or ply:IsSuperAdmin() then
  52.         Salary =    LANGUAGE.salary .. CUR .. (LocalPlayer().DarkRPVars.salary.." (x2)" or 0)
  53.     else
  54.         Salary =    LANGUAGE.salary .. CUR .. (LocalPlayer().DarkRPVars.salary or 0)
  55.     end
  56.    
  57.     /*local JobWallet = // old wallet stuff
  58.     LANGUAGE.job .. (LocalPlayer().DarkRPVars.job or "") .. "\n"..
  59.     LANGUAGE.wallet .. CUR .. (LocalPlayer().DarkRPVars.money or 0).."\n"..
  60.     LANGUAGE.points .. (LocalPlayer().DarkRPVars.points or 0)
  61.     */
  62.    
  63.     draw.TexturedQuad({
  64.         texture=surface.GetTextureID("gui/silkicons/"..evolve.ranks[LocalPlayer():EV_GetRank()].Icon),
  65.         //texture="gui/gradient",
  66.         //color=Color(255, 255, 255, 255),
  67.         x=ScrW()/20-32,
  68.         y=RelativeY-30,
  69.         w=16,
  70.         h=16
  71.     })
  72.     draw.DrawText(LocalPlayer():Nick(), "TargetID", ScrW()/20-10, RelativeY - 32, Color(255, 255, 255, 255), 0)
  73.     surface.SetFont("TargetID")
  74.     local w, h = surface.GetTextSize(Salary)
  75.     draw.DrawText(LANGUAGE.job .. (LocalPlayer().DarkRPVars.job or ""), "TargetID", RelativeX + (ScrW()/10)*5, RelativeY - 32, Color(255, 255, 255, 255), 0)
  76. end
  77.  
  78. local function GunLicense()
  79.     if LocalPlayer().DarkRPVars.HasGunlicense then
  80.         local QuadTable = {}  
  81.        
  82.         QuadTable.texture   = surface.GetTextureID( "gui/silkicons/page" )
  83.         QuadTable.color     = Color( 255, 255, 255, 100 )  
  84.        
  85.         QuadTable.x = RelativeX + HUDWidth + 31
  86.         QuadTable.y = ScrH() - 32
  87.         QuadTable.w = 32
  88.         QuadTable.h = 32
  89.         draw.TexturedQuad(QuadTable)
  90.     end
  91. end
  92.  
  93. local function JobHelp()
  94.     local Helps = {"Cop", "Mayor", "Admin", "Boss"}
  95.  
  96.     for k,v in pairs(Helps) do
  97.         if LocalPlayer().DarkRPVars["help"..v] then
  98.             draw.RoundedBox(10, 10, 10, 590, 194, Color(0, 0, 0, 255))
  99.             draw.RoundedBox(10, 12, 12, 586, 190, Color(51, 58, 51, 200))
  100.             draw.RoundedBox(10, 12, 12, 586, 20, Color(0, 0, 70, 200))
  101.             draw.DrawText(v.." Help", "ScoreboardText", 30, 12, Color(255,0,0,255),0)
  102.             draw.DrawText(string.format(LANGUAGE[v:lower().."help"], GetConVarNumber("jailtimer")), "ScoreboardText", 30, 35, Color(255,255,255,255),0)
  103.         end
  104.     end
  105. end
  106.  
  107. local function Agenda()
  108.     local HUDHeight2=HUDHeight+10
  109.     local DrawAgenda, AgendaManager = DarkRPAgendas[LocalPlayer():Team()], LocalPlayer():Team()
  110.     if not DrawAgenda then
  111.         for k,v in pairs(DarkRPAgendas) do
  112.             if table.HasValue(v.Listeners, LocalPlayer():Team()) then
  113.                 DrawAgenda, AgendaManager = DarkRPAgendas[k], k
  114.                 break
  115.             end
  116.         end
  117.     end
  118.     if DrawAgenda then
  119.         draw.RoundedBox(10, 10, 10, 460, 110+HUDHeight2, Color(0, 0, 0, 155))
  120.         draw.RoundedBox(10, 12, 12, 456, 106+HUDHeight2, Color(51, 58, 51,100))
  121.         draw.RoundedBox(10, 12, 12, 456, 20+HUDHeight2, Color(0, 0, 70, 100))
  122.        
  123.         draw.DrawText(DrawAgenda.Title, "ScoreboardText", 30, 12+HUDHeight2, Color(255,0,0,255),0)
  124.        
  125.         local AgendaText = ""
  126.         for k,v in pairs(team.GetPlayers(AgendaManager)) do
  127.             AgendaText = AgendaText .. (v.DarkRPVars.agenda or "")
  128.         end
  129.         draw.DrawText(string.gsub(string.gsub(AgendaText, "//", "\n"), "\\n", "\n"), "ScoreboardText", 30, 35+HUDHeight2, Color(255,255,255,255),0)
  130.     end
  131. end
  132.  
  133. local function DrawVoiceChat()
  134.     if LocalPlayer().DRPIsTalking then
  135.         local chbxX, chboxY = chat.GetChatBoxPos()
  136.  
  137.         local Rotating = math.sin(CurTime()*3)
  138.         local backwards = 0
  139.         if Rotating < 0 then
  140.             Rotating = 1-(1+Rotating)
  141.             backwards = 180
  142.         end
  143.         surface.SetTexture(surface.GetTextureID( "voice/icntlk_pl" ))
  144.         surface.SetDrawColor(ConVars.Healthforeground)
  145.         surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
  146.     end
  147. end
  148.  
  149. local function LockDown()
  150.     local chbxX, chboxY = chat.GetChatBoxPos()
  151.     if tobool(GetConVarNumber("DarkRP_LockDown")) then
  152.         local cin = (math.sin(CurTime()) + 1) / 2
  153.         draw.DrawText(LANGUAGE.lockdown_started, "ScoreboardSubtitle", chbxX, chboxY + 260, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
  154.     end
  155.    
  156. end
  157.  
  158. local Arrested = function() end
  159.  
  160. usermessage.Hook("GotArrested", function(msg)
  161.     local StartArrested = CurTime()
  162.     local ArrestedUntil = msg:ReadFloat()
  163.    
  164.     Arrested = function()
  165.         if CurTime() - StartArrested <= ArrestedUntil and LocalPlayer().DarkRPVars.Arrested then
  166.         draw.DrawText(string.format(LANGUAGE.youre_arrested, math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "ScoreboardText", ScrW()/2, ScrH() - ScrH()/12, Color(255,255,255,255), 1)
  167.         elseif not LocalPlayer().DarkRPVars.Arrested then
  168.             Arrested = function() end
  169.         end
  170.     end
  171. end)
  172.  
  173. local AdminTell = function() end
  174.  
  175. usermessage.Hook("AdminTell", function(msg)
  176.     local Message = msg:ReadString()
  177.  
  178.     AdminTell = function()
  179.         draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, Color(0, 0, 0, 255))
  180.         draw.DrawText(LANGUAGE.listen_up, "GModToolName", ScrW() / 2 + 10, 10, Color(255, 255, 255, 255), 1)
  181.         draw.DrawText(Message, "ChatFont", ScrW() / 2 + 10, 65, Color(200, 30, 30, 255), 1)
  182.     end
  183.  
  184.     timer.Simple(10, function()
  185.         AdminTell = function() end
  186.     end)
  187. end)
  188.  
  189. /*---------------------------------------------------------------------------
  190. Drawing the HUD elements such as Health etc.
  191. ---------------------------------------------------------------------------*/
  192. local function DrawHUD()
  193.  
  194.     --Background
  195.     draw.RoundedBox(0, RelativeX, RelativeY-40,  HUDWidth, HUDHeight, Color(40,40,40,200))
  196.  
  197.     DrawHealth(ScrW()/5)
  198.     DrawInfo()
  199.     draw.RoundedBox(0, RelativeX, RelativeY-40,  HUDWidth, HUDHeight/2, Color(255,255,255,50))
  200.     GunLicense()
  201.     Agenda()
  202.     JobHelp()
  203.     DrawVoiceChat()
  204.     LockDown()
  205.  
  206.     Arrested()
  207.     AdminTell()
  208.    
  209. end
  210.  
  211. /*---------------------------------------------------------------------------
  212. Entity HUDPaint things
  213. ---------------------------------------------------------------------------*/
  214. local function DrawPlayerInfo(ply)
  215.     local pos = ply:EyePos()
  216.  
  217.     pos.z = pos.z + 34
  218.     pos = pos:ToScreen()
  219.  
  220.     if GetConVarNumber("nametag") == 1 then
  221.         draw.DrawText(ply:Nick(), "TargetID", pos.x + 1, pos.y + 1, Color(0, 0, 0, 255), 1)
  222.         draw.DrawText(ply:Nick(), "TargetID", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  223.         draw.DrawText(LANGUAGE.health ..ply:Health(), "TargetID", pos.x + 1, pos.y + 21, Color(0, 0, 0, 255), 1)
  224.         draw.DrawText(LANGUAGE.health..ply:Health(), "TargetID", pos.x, pos.y + 20, Color(255,255,255,200), 1)
  225.     end
  226.  
  227.     if GetConVarNumber("jobtag") == 1 then
  228.         draw.DrawText(ply.DarkRPVars.job or "", "TargetID", pos.x + 1, pos.y + 41, Color(0, 0, 0, 255), 1)
  229.         draw.DrawText(ply.DarkRPVars.job or "", "TargetID", pos.x, pos.y + 40, Color(255, 255, 255, 200), 1)
  230.     end
  231.    
  232.     if ply.DarkRPVars.HasGunlicense then
  233.         surface.SetTexture(surface.GetTextureID("gui/silkicons/page"))
  234.         surface.SetDrawColor(255,255,255,255)
  235.         surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
  236.     end
  237. end
  238.  
  239. local function DrawWantedInfo(ply)
  240.     if not ply:Alive() then return end
  241.  
  242.     local pos = ply:EyePos()
  243.     if not pos:RPIsInSight({LocalPlayer(), ply}) then return end
  244.  
  245.     pos.z = pos.z + 14
  246.     pos = pos:ToScreen()
  247.  
  248.     if GetConVarNumber("nametag") == 1 then
  249.         draw.DrawText(ply:Nick(), "TargetID", pos.x + 1, pos.y + 1, Color(0, 0, 0, 255), 1)
  250.         draw.DrawText(ply:Nick(), "TargetID", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  251.     end
  252.  
  253.     draw.DrawText(LANGUAGE.wanted.."\nReason: "..tostring(ply.DarkRPVars["wantedReason"]), "TargetID", pos.x, pos.y - 40, Color(255, 255, 255, 200), 1)
  254.     draw.DrawText(LANGUAGE.wanted.."\nReason: "..tostring(ply.DarkRPVars["wantedReason"]), "TargetID", pos.x + 1, pos.y - 41, Color(255, 0, 0, 255), 1)
  255. end
  256.  
  257. /*---------------------------------------------------------------------------
  258. The Entity display: draw HUD information about entities
  259. ---------------------------------------------------------------------------*/
  260. local function DrawEntityDisplay()
  261.     for k, ply in pairs(player.GetAll()) do
  262.         if not ply:Alive() then continue end
  263.  
  264.         ply.DarkRPVars = ply.DarkRPVars or {}
  265.         if ply.DarkRPVars.wanted then DrawWantedInfo(ply) end
  266.  
  267.         if GetConVarNumber("globalshow") == 1 and ply ~= LocalPlayer() then DrawPlayerInfo(ply) end
  268.     end
  269.  
  270.     local tr = LocalPlayer():GetEyeTrace()
  271.     if tr.Entity and tr.Entity.IsValid and ValidEntity(tr.Entity) and tr.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 400 then
  272.         if tr.Entity:IsPlayer() and not tobool(GetConVarNumber("globalshow")) then
  273.             DrawPlayerInfo(tr.Entity)
  274.         end
  275.     end
  276.  
  277.     if tr.Entity:IsOwnable() then
  278.         tr.Entity:DrawOwnableInfo()
  279.     end
  280. end
  281.  
  282. /*---------------------------------------------------------------------------
  283. Zombie display
  284. ---------------------------------------------------------------------------*/
  285. local function DrawZombieInfo()
  286.     if not LocalPlayer().DarkRPVars.zombieToggle then return end
  287.     for x=1, LocalPlayer().DarkRPVars.numPoints, 1 do
  288.         local zPoint = LocalPlayer().DarkRPVars["zPoints".. x]
  289.         if zPoint then
  290.             zPoint = zPoint:ToScreen()
  291.             draw.DrawText("Zombie Spawn (" .. x .. ")", "TargetID", zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1)
  292.             draw.DrawText("Zombie Spawn (" .. x .. ")", "TargetID", zPoint.x + 1, zPoint.y - 21, Color(255, 0, 0, 255), 1)
  293.         end
  294.     end
  295. end
  296.  
  297. /*---------------------------------------------------------------------------
  298. Actual HUDPaint hook
  299. ---------------------------------------------------------------------------*/
  300. function GAMEMODE:HUDPaint()
  301.     if GetConVarNumber("cl_drawhud") >= 1 then
  302.         DrawHUD()
  303.         DrawZombieInfo()
  304.         DrawEntityDisplay()
  305.         self.BaseClass:HUDPaint()
  306.     end
  307. end
Advertisement
Add Comment
Please, Sign In to add comment