Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------------------------------------
- HUD ConVars
- ---------------------------------------------------------------------------*/
- local ConVars = {}
- local HUDWidth
- local HUDHeight
- local Color = Color
- local cvars = cvars
- local draw = draw
- local GetConVar = GetConVar
- local Lerp = Lerp
- local localplayer
- local pairs = pairs
- local SortedPairs = SortedPairs
- local string = string
- local surface = surface
- local table = table
- local tostring = tostring
- CreateClientConVar("weaponhud", 0, true, false)
- local function ReloadConVars()
- ConVars = {
- background = {0,255,0,},
- Healthbackground = {0,0,0,200},
- Healthforeground = {140,0,0,180},
- HealthText = {255,255,255,200},
- Job1 = {0,0,150,200},
- Job2 = {0,0,0,255},
- salary1 = {0,150,0,200},
- salary2 = {0,0,0,255}
- }
- for name, Colour in pairs(ConVars) do
- ConVars[name] = {}
- for num, rgb in SortedPairs(Colour) do
- local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
- table.insert(ConVars[name], CVar:GetInt())
- if not cvars.GetConVarCallbacks(name..num, false) then
- cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
- end
- end
- ConVars[name] = Color(unpack(ConVars[name]))
- end
- HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt()
- HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
- if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
- cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
- cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
- end
- end
- ReloadConVars()
- local function formatNumber(n)
- if not n then return "" end
- if n >= 1e14 then return tostring(n) end
- n = tostring(n)
- local sep = sep or ","
- local dp = string.find(n, "%.") or #n+1
- for i=dp-4, 1, -3 do
- n = n:sub(1, i) .. sep .. n:sub(i+1)
- end
- return n
- end
- local Scrw, Scrh, RelativeX, RelativeY
- /*---------------------------------------------------------------------------
- HUD Seperate Elements
- ---------------------------------------------------------------------------*/
- local licence = Material("boowman/licence.png")
- local function GunLicense()
- if localplayer:getDarkRPVar("HasGunlicense") then
- surface.SetMaterial(licence)
- surface.SetDrawColor(255, 255, 255, 255)
- surface.DrawTexturedRect(20,ScrH() - 85,150,50)
- end
- end
- local function Agenda()
- local DrawAgenda, AgendaManager = DarkRPAgendas[localplayer:Team()], localplayer:Team()
- if not DrawAgenda then
- for k,v in pairs(DarkRPAgendas) do
- if table.HasValue(v.Listeners or {}, localplayer:Team()) then
- DrawAgenda, AgendaManager = DarkRPAgendas[k], k
- break
- end
- end
- end
- if DrawAgenda then
- draw.RoundedBox(10, 10, 10, 460, 110, Color(0, 0, 0, 155))
- draw.RoundedBox(10, 12, 12, 456, 106, Color(51, 58, 51,100))
- draw.RoundedBox(10, 12, 12, 456, 20, Color(0, 0, 70, 100))
- draw.DrawText(DrawAgenda.Title, "DarkRPHUD1", 30, 12, Color(255,0,0,255),0)
- local AgendaText = {}
- for k,v in pairs(team.GetPlayers(AgendaManager)) do
- if not v.DarkRPVars then continue end
- table.insert(AgendaText, v:getDarkRPVar("agenda"))
- end
- local text = table.concat(AgendaText, "\n")
- text = text:gsub("//", "\n"):gsub("\\n", "\n")
- text = GAMEMODE:TextWrap(text, "DarkRPHUD1", 440)
- draw.DrawText(text, "DarkRPHUD1", 30, 35, Color(255,255,255,255),0)
- end
- end
- local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
- local function DrawVoiceChat()
- if localplayer.DRPIsTalking then
- local chbxX, chboxY = chat.GetChatBoxPos()
- local Rotating = math.sin(CurTime()*3)
- local backwards = 0
- if Rotating < 0 then
- Rotating = 1-(1+Rotating)
- backwards = 180
- end
- surface.SetTexture(VoiceChatTexture)
- surface.SetDrawColor(ConVars.Healthforeground)
- surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
- end
- end
- local function LockDown()
- local chbxX, chboxY = chat.GetChatBoxPos()
- if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
- local cin = (math.sin(CurTime()) + 1) / 2
- local chatBoxSize = math.floor(ScrH() / 4)
- draw.DrawText(DarkRP.getPhrase("lockdown_started"), "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
- end
- end
- local Arrested = function() end
- usermessage.Hook("GotArrested", function(msg)
- local StartArrested = CurTime()
- local ArrestedUntil = msg:ReadFloat()
- Arrested = function()
- if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then
- draw.DrawText(DarkRP.getPhrase("youre_arrested", math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, Color(255,255,255,255), 1)
- elseif not localplayer:getDarkRPVar("Arrested") then
- Arrested = function() end
- end
- end
- end)
- local AdminTell = function() end
- usermessage.Hook("AdminTell", function(msg)
- local Message = msg:ReadString()
- AdminTell = function()
- draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, Color(0, 0, 0, 200))
- draw.DrawText(DarkRP.getPhrase("listen_up"), "GModToolName", ScrW() / 2 + 10, 10, Color(255, 255, 255, 255), 1)
- draw.DrawText(Message, "ChatFont", ScrW() / 2 + 10, 80, Color(200, 30, 30, 255), 1)
- end
- timer.Simple(10, function()
- AdminTell = function() end
- end)
- end)
- /*---------------------------------------------------------------------------
- Drawing the HUD elements such as Health etc.
- ---------------------------------------------------------------------------*/
- surface.CreateFont( "SBPName", {
- font = "Arial",
- size = 20,
- weight = 700,
- antialias = true,
- shadow = true,
- } )
- surface.CreateFont( "SBPName2", {
- font = "Arial",
- size = 20,
- weight = 700,
- antialias = true,
- shadow = true,
- } )
- /*---------------------------------------------------------------------------
- Change HUD Colours
- ---------------------------------------------------------------------------*/
- local healthbg = Color(0,0,0,200)
- local armorbg = Color(0,0,0,200)
- local jobs = Color(0,0,0,200)
- local salr = Color(0,0,0,200)
- local mon = Color(0,0,0,200)
- local hpbar = Color(255,0,0,255)
- local arbar = Color(0,150,255,255)
- local function DrawHealth()
- LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}
- local ply = LocalPlayer()
- local HP,AR = ply:Health(),ply:Armor()
- local slujba = LocalPlayer().DarkRPVars.job or "Unemployed"
- local salar = formatNumber(LocalPlayer().DarkRPVars.salary) or "NONE"
- local bani = formatNumber(LocalPlayer().DarkRPVars.money) or "NONE"
- draw.RoundedBox(0,10,ScrH() - 30,200,25,healthbg)
- draw.RoundedBox(0,220,ScrH() - 30,200,25,armorbg)
- draw.RoundedBox(0,10,ScrH() - 60,200,25,jobs)
- draw.RoundedBox(0,10,ScrH() - 120,100,25,salr)
- draw.RoundedBox(0,10,ScrH() - 90,200,25,mon)
- //--Health
- draw.RoundedBox(0,14.5,ScrH() - 25,math.Clamp(HP,0,100)*1.9,15,hpbar)
- draw.DrawText(""..HP.."","SBPName",65,ScrH() - 27,Color(0,0,0,0),TEXT_ALIGN_CENTER)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawOutlinedRect(10,ScrH() - 30,200,25)
- //--Armor
- draw.RoundedBox(0,224.5,ScrH() - 25,math.Clamp(AR,0,100)*1.9,15,arbar)
- draw.DrawText("Armor: "..AR.."%","SBPName",275,ScrH() - 27,Color(0,0,0,0),TEXT_ALIGN_CENTER)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawOutlinedRect(220,ScrH() - 30,200,25)
- //--Money
- draw.DrawText("Wallet: "..bani.."","SBPName",15,ScrH() - 87,Color(255,255,255),TEXT_ALIGN_LEFT)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawOutlinedRect(10,ScrH() - 90,200,25)
- //--Job
- draw.DrawText(slujba,"SBPName",15,ScrH() - 57,Color(255,255,255),TEXT_ALIGN_LEFT)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawOutlinedRect(10,ScrH() - 60,200,25)
- //--Salary
- draw.DrawText("Salary: "..salar,"SBPName",15,ScrH() - 117,Color(255,255,255),TEXT_ALIGN_LEFT)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawOutlinedRect(10,ScrH() - 120,100,25)
- //--Licence
- if ply:getDarkRPVar("HasGunlicense") then
- surface.SetMaterial(licence)
- surface.SetDrawColor(255, 255, 255, 255)
- surface.DrawTexturedRect(20,ScrH() - 85,150,50)
- end
- end
- local function DrawHUD()
- localplayer = localplayer and IsValid(localplayer) and localplayer or LocalPlayer()
- if not IsValid(localplayer) then return end
- local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_HUD")
- if shouldDraw == false then return end
- Scrw, Scrh = ScrW(), ScrH()
- RelativeX, RelativeY = 0, Scrh
- DrawHealth()
- GunLicense()
- Agenda()
- DrawVoiceChat()
- LockDown()
- Arrested()
- AdminTell()
- end
- /*---------------------------------------------------------------------------
- Entity HUDPaint things
- ---------------------------------------------------------------------------*/
- plyMeta.drawPlayerInfo = plyMeta.drawPlayerInfo or function(self)
- local pos = self:EyePos()
- pos.z = pos.z + 10 -- The position we want is a bit above the position of the eyes
- pos = pos:ToScreen()
- if not self:getDarkRPVar("wanted") then
- -- Move the text up a few pixels to compensate for the height of the text
- pos.y = pos.y - 50
- end
- if GAMEMODE.Config.showname then
- local nick, plyTeam = self:Nick(), self:Team()
- draw.DrawNonParsedText(nick, "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
- draw.DrawNonParsedText(nick, "DarkRPHUD2", pos.x, pos.y, RPExtraTeams[plyTeam].color or team.GetColor(plyTeam) , 1)
- end
- if GAMEMODE.Config.showhealth then
- local health = DarkRP.getPhrase("health", self:Health())
- draw.DrawNonParsedText(health, "DarkRPHUD2", pos.x + 1, pos.y + 21, colors.black, 1)
- draw.DrawNonParsedText(health, "DarkRPHUD2", pos.x, pos.y + 20, colors.white1, 1)
- end
- if GAMEMODE.Config.showjob then
- local teamname = self:getDarkRPVar("job") or team.GetName(self:Team())
- draw.DrawNonParsedText(teamname, "DarkRPHUD2", pos.x + 1, pos.y + 41, colors.black, 1)
- draw.DrawNonParsedText(teamname, "DarkRPHUD2", pos.x, pos.y + 40, colors.white1, 1)
- end
- if self:getDarkRPVar("HasGunlicense") then
- surface.SetMaterial(Page)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
- end
- end
- -- Draw wanted information above a player's head
- -- This syntax allows for easy overriding
- plyMeta.drawWantedInfo = plyMeta.drawWantedInfo or function(self)
- if not self:Alive() then return end
- local pos = self:EyePos()
- if not pos:isInSight({localplayer, self}) then return end
- pos.z = pos.z + 10
- pos = pos:ToScreen()
- if GAMEMODE.Config.showname then
- draw.DrawNonParsedText(self:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
- draw.DrawNonParsedText(self:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(self:Team()), 1)
- end
- local wantedText = DarkRP.getPhrase("wanted", tostring(self:getDarkRPVar("wantedReason")))
- draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x, pos.y - 40, colors.white1, 1)
- draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x + 1, pos.y - 41, colors.red, 1)
- end
- /*---------------------------------------------------------------------------
- The Entity display: draw HUD information about entities
- ---------------------------------------------------------------------------*/
- local function DrawEntityDisplay()
- local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_EntityDisplay")
- if shouldDraw == false then return end
- local shootPos = localplayer:GetShootPos()
- local aimVec = localplayer:GetAimVector()
- for k, ply in pairs(player.GetAll()) do
- if not ply:Alive() then continue end
- local hisPos = ply:GetShootPos()
- if ply:getDarkRPVar("wanted") then DrawWantedInfo(ply) end
- if GAMEMODE.Config.globalshow and ply ~= localplayer then
- DrawPlayerInfo(ply)
- -- Draw when you're (almost) looking at him
- elseif not GAMEMODE.Config.globalshow and hisPos:Distance(shootPos) < 400 then
- local pos = hisPos - shootPos
- local unitPos = pos:GetNormalized()
- if unitPos:Dot(aimVec) > 0.95 then
- local trace = util.QuickTrace(shootPos, pos, localplayer)
- if trace.Hit and trace.Entity ~= ply then return end
- DrawPlayerInfo(ply)
- end
- end
- end
- local tr = localplayer:GetEyeTrace()
- if IsValid(tr.Entity) and tr.Entity:IsOwnable() and tr.Entity:GetPos():Distance(localplayer:GetPos()) < 200 then
- tr.Entity:DrawOwnableInfo()
- end
- end
- /*---------------------------------------------------------------------------
- Zombie display
- ---------------------------------------------------------------------------*/
- local function DrawZombieInfo()
- if not localplayer:getDarkRPVar("zombieToggle") then return end
- local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_ZombieInfo")
- if shouldDraw == false then return end
- for x=1, localplayer:getDarkRPVar("numPoints"), 1 do
- local zPoint = localplayer.DarkRPVars["zPoints".. x]
- if zPoint then
- zPoint = zPoint:ToScreen()
- draw.DrawText("Zombie Spawn (" .. x .. ")", "DarkRPHUD2", zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1)
- draw.DrawText("Zombie Spawn (" .. x .. ")", "DarkRPHUD2", zPoint.x + 1, zPoint.y - 21, Color(255, 0, 0, 255), 1)
- end
- end
- end
- /*---------------------------------------------------------------------------
- Actual HUDPaint hook
- ---------------------------------------------------------------------------*/
- function GM:HUDPaint()
- DrawHUD()
- DrawZombieInfo()
- DrawEntityDisplay()
- self.BaseClass:HUDPaint()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement