Advertisement
Guest User

Untitled

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