/---------------------------------------------------------------------------
HUD ConVars
---------------------------------------------------------------------------/
local ConVars = {}
local HUDWidth
local HUDHeight
local function ReloadConVars()
ConVars = {
background = {0,0,0,100},
Healthbackground = {0,0,0,200},
Healthforeground = {140,0,0,180},
HealthText = {255,255,255,200},
Job1 = {255,255,255,255},
Job2 = {0,0,0,255},
salary1 = {255,255,255,255},
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()
function formatNumber(n)
if (!n) then
return 0
end
if n >= 1e14 then return tostring(n) end
n = tostring(n)
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 function DrawInfo()
LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}
local Salary = LANGUAGE.salary … CUR … (LocalPlayer().DarkRPVars.salary or 0)
local JobWallet =
LANGUAGE.job .. (LocalPlayer().DarkRPVars.job or "") .. "
"…
LANGUAGE.wallet … CUR … (formatNumber(LocalPlayer().DarkRPVars.money) or 0)
draw.DrawText(Salary, "TargetID", RelativeX + 7, RelativeY - HUDHeight + 6, Color( 255, 255, 255 ), 0)
--draw.DrawText(Salary, "TargetID", RelativeX + 4, RelativeY - HUDHeight + 5, ConVars.salary2, 0)
surface.SetFont("TargetID")
local w, h = surface.GetTextSize(Salary)
draw.DrawText(JobWallet, "TargetID", RelativeX + 7, RelativeY - HUDHeight + h + 6, Color( 255, 255, 255 ), 0)
local mafia = "None"
if( LocalPlayer():GetNWString( "mafia" ) != nil and LocalPlayer():GetNWString( "mafia" ) != "") then
mafia = LocalPlayer():GetNWString( "mafia" )
end
draw.DrawText("Mafia: ".. mafia, "TargetID", RelativeX + 7, RelativeY - HUDHeight + h + 51, Color( 255, 255, 255 ), 0)
--draw.DrawText(JobWallet, "TargetID", RelativeX + 4, RelativeY - HUDHeight + h + 5, ConVars.Job2, 0)
end
local Page = surface.GetTextureID(“gui/silkicons/page”)
local function GunLicense()
if LocalPlayer().DarkRPVars.HasGunlicense then
local QuadTable = {}
QuadTable.texture = Page
QuadTable.color = Color( 255, 255, 255, 100 )
QuadTable.x = RelativeX + HUDWidth + 31
QuadTable.y = ScrH() - 32
QuadTable.w = 32
QuadTable.h = 32
draw.TexturedQuad(QuadTable)
end
end
local function JobHelp()
local Helps = {“Cop”, “Mayor”, “Admin”, “Boss”}
for k,v in pairs(Helps) do
if LocalPlayer().DarkRPVars["help"..v] then
draw.RoundedBox(10, 10, 10, 590, 194, Color(0, 0, 0, 255))
draw.RoundedBox(10, 12, 12, 586, 190, Color(51, 58, 51, 200))
draw.RoundedBox(10, 12, 12, 586, 20, Color(0, 0, 70, 200))
draw.DrawText(v.." Help", "ScoreboardText", 30, 12, Color(255,0,0,255),0)
draw.DrawText(string.format(LANGUAGE[v:lower().."help"], GetConVarNumber("jailtimer")), "ScoreboardText", 30, 35, Color(255,255,255,255),0)
end
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, 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, "ScoreboardText", 30, 12, Color(255,0,0,255),0)
local AgendaText = ""
for k,v in pairs(team.GetPlayers(AgendaManager)) do
AgendaText = AgendaText .. (v.DarkRPVars.agenda or "")
end
draw.DrawText(string.gsub(string.gsub(AgendaText, "//", "
"), "
", "
"), “ScoreboardText”, 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(LANGUAGE.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().DarkRPVars.Arrested then
draw.DrawText(string.format(LANGUAGE.youre_arrested, math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "ScoreboardText", ScrW()/2, ScrH() - ScrH()/12, Color(255,255,255,255), 1)
elseif not LocalPlayer().DarkRPVars.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, 255))
draw.DrawText(LANGUAGE.listen_up, "GModToolName", ScrW() / 2 + 10, 10, Color(255, 255, 255, 255), 1)
draw.DrawText(Message, "ChatFont", ScrW() / 2 + 10, 65, Color(200, 30, 30, 255), 1)
end
timer.Simple(10, function()
AdminTell = function() end
end)
end)
function DrawLevel()
local level = LocalPlayer():GetNWInt("level") or 0
surface.SetFont("TargetID")
local w, h = surface.GetTextSize( level )
--draw.DrawText( "Level: "..tostring( level ), "TargetID", ScrW()/2 - 60, 55, Color( 255, 255, 255 ), 0)
end
function DrawExpBar()
local level = LocalPlayer():GetNWInt("level") or 0;
local e = LocalPlayer():GetNWInt("experience") or 0;
local em = LocalPlayer():GetNWInt("maxexperience") or 0;
local ee = e / em or 0;
local ep = math.Round((e / em) * 100);
draw.RoundedBox( 4, ScrW()/2 - 130, 25, 300, 25, Color(0, 0, 0, 180) ) -- outer bar
if( ep >= 1 ) then
draw.RoundedBox( 4, ScrW()/2 - 130, 25, ( 300 ) * ee, 25, Color(0, 255, 0, 181) ) -- inner bar
end
draw.DrawText( "Level "..tostring( level ).." ("..tostring( ep ).."%)", "TargetID", ScrW()/2 - 50, 25, Color( 255, 255, 255 ), 0)
end
local Health = 0
local function DrawHealth()
local hp = 100;
if( LocalPlayer():GetNWInt( "extrahealth" ) > 0 ) then
hp = LocalPlayer():GetNWInt( "extrahealth" )
end
Health = math.min(hp, (Health == LocalPlayer():Health() and Health) or Lerp(0.1, Health, LocalPlayer():Health()))
local ex = hp;
if( hp > 100 ) then
ex = hp+100;
end
local ep = math.Round( LocalPlayer():Health() / ex * 100 );
local RelativeX = 0;
local RelativeY = ScrH() - 20;
local DrawHealth = Health / hp;
local Border = math.Min(6, math.pow(2, math.Round(3*DrawHealth)))
draw.RoundedBox(4, RelativeX + 4, RelativeY - 18, HUDWidth - 9, 12, Color(0, 0, 0, 180))
if( LocalPlayer():Health() > 0 ) then
draw.RoundedBox(4, RelativeX + 5, RelativeY - 17, (HUDWidth - 10) * DrawHealth, 10, Color(255, 0, 0, 181))
draw.DrawText(tostring( ep ).."%", "TargetID", RelativeX + 4 + (HUDWidth - 8)/2, RelativeY - 23, Color( 255, 255, 255 ), 1)
end
end
local Armor = 0
local function DrawArmor()
Armor = Lerp(0.1, 0, LocalPlayer():Armor())
local RelativeX = 0;
local RelativeY = ScrH() - 20;
local DrawArmor = Armor / 100;
local Border = math.Min(6, math.pow(2, math.Round(3*DrawArmor)))
draw.RoundedBox(4, RelativeX + 4, RelativeY + 2, HUDWidth - 9, 12, Color(0, 0, 0, 180))
if( LocalPlayer():Armor() > 0 ) then
draw.RoundedBox(4, RelativeX + 5, RelativeY + 1, (HUDWidth - 10) * DrawArmor, 10, Color(0, 0, 255, 181))
draw.DrawText(math.Max(0, math.Round(Armor)).."", "TargetID", RelativeX + 4 + (HUDWidth - 8)/2, RelativeY - 3, Color( 255, 255, 255 ), 1)
end
end
–weapon max clip sizes for half-life weapons
HLWeps = {}
HLWeps[ “weapon_smg1” ] = 45;
HLWeps[ “weapon_pistol” ] = 18;
HLWeps[ “weapon_357” ] = 6;
HLWeps[ “weapon_crowbar” ] = -1;
HLWeps[ “weapon_ar2” ] = 30;
–Ammo
function DrawAmmo()
if( LocalPlayer():Alive() && LocalPlayer():GetActiveWeapon() && LocalPlayer():GetActiveWeapon().Clip1 ) then
local wep = LocalPlayer():GetActiveWeapon();
local TitleColor = Color( 255, 255, 255, 255 );
local TextColor = Color( 255, 255, 255, 255 );
local BGColor = Color( 30, 30, 30, 255 );
local color = Color( 0, 0, 200, 255 );
local x = ScrW() - 215;
local y = ScrH() - 60;
local mag_left = wep:Clip1()
local mag_extra = LocalPlayer():GetAmmoCount( wep:GetPrimaryAmmoType() )
local clipsize = mag_left;
draw.RoundedBox( 4, x, y, 200, 50, Color( 0, 0, 0, math.Clamp( 255 - 95, 0, 255 ) ) );
--if the player is using a cs weapon then animate the ammo display
if( LocalPlayer():GetActiveWeapon():GetTable().Primary == nil ) then
if( HLWeps[ wep:GetClass() ] != nil ) then
clipsize = HLWeps[ wep:GetClass() ];
end
else
clipsize = LocalPlayer():GetActiveWeapon():GetTable().Primary.ClipSize;
end
if( mag_left >= 1 ) then
draw.RoundedBox( 4, x + 5, y + 5, 190 * ( mag_left / clipsize ), 40, BGColor );
draw.RoundedBox( 4, x + 7, y + 5, 186 * ( mag_left / clipsize ), 9, Color( 255, 255, 255, math.Clamp( 255 - 235, 0, 255 ) ) );
draw.RoundedBox( 4, x + 7, y + 30, 186 * ( mag_left / clipsize ), 15, Color( 0, 0, 0, math.Clamp( 255 - 175, 0, 255 ) ) );
end
local str = tostring( mag_left ) .."/".. tostring( mag_extra );
draw.DrawText( "Ammo", "TargetID", x + 8, y + 6, TitleColor, nil, nil );
draw.DrawText( str, "TargetID", x + 8, y + 28, TextColor, nil, nil );
end
end
/---------------------------------------------------------------------------
Drawing the HUD elements such as Health etc.
---------------------------------------------------------------------------/
local function DrawHUD()
Scrw, Scrh = ScrW(), ScrH()
RelativeX, RelativeY = 0, Scrh - 35
if( MenuOn != nil ) then
if( MenuOn == true ) then return end
end
--Background
draw.RoundedBox(6, 0, Scrh - HUDHeight, HUDWidth, HUDHeight, ConVars.background)
--draw.FancyBox( 0, Scrh - HUDHeight - 35, HUDWidth, HUDHeight - 10 )
DrawAmmo()
DrawHealth()
DrawArmor()
DrawInfo()
GunLicense()
--Agenda()
JobHelp()
DrawVoiceChat()
LockDown()
-- level / experience stuff
DrawLevel()
DrawExpBar()
Arrested()
AdminTell()
end
/---------------------------------------------------------------------------
Entity HUDPaint things
---------------------------------------------------------------------------/
local function DrawPlayerInfo(ply)
local pos = ply:EyePos()
pos.z = pos.z + 34
pos = pos:ToScreen()
if GetConVarNumber("nametag") == 1 then
if( ply:GetNWString("mafia") != "" and ply:GetNWString("mafia") != nil ) then
draw.DrawText(tostring( ply:GetNWString("mafia") ), "TargetID", pos.x + 1, pos.y - 25, Color(255, 0, 0, 255), 1)
end
draw.DrawText(ply:Nick() .." - Level: ".. tostring( ply:GetNWInt("level") ), "TargetID", pos.x + 1, pos.y + 1, Color(0, 0, 0, 255), 1)
draw.DrawText(ply:Nick() .." - Level: ".. tostring( ply:GetNWInt("level") ), "TargetID", pos.x, pos.y, team.GetColor(ply:Team()), 1)
draw.DrawText(LANGUAGE.health ..ply:Health(), "TargetID", pos.x + 1, pos.y + 21, Color(0, 0, 0, 255), 1)
draw.DrawText(LANGUAGE.health..ply:Health(), "TargetID", pos.x, pos.y + 20, Color(255,255,255,200), 1)
end
if GetConVarNumber("jobtag") == 1 then
draw.DrawText(ply.DarkRPVars.job or "", "TargetID", pos.x + 1, pos.y + 41, Color(0, 0, 0, 255), 1)
draw.DrawText(ply.DarkRPVars.job or "", "TargetID", pos.x, pos.y + 40, Color(255, 255, 255, 200), 1)
end
if ply.DarkRPVars.HasGunlicense then
surface.SetTexture(surface.GetTextureID("gui/silkicons/page"))
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
end
end
local function DrawWantedInfo(ply)
if not ply:Alive() then return end
local pos = ply:EyePos()
if not pos:RPIsInSight({LocalPlayer(), ply}) then return end
pos.z = pos.z + 14
pos = pos:ToScreen()
if GetConVarNumber("nametag") == 1 then
draw.DrawText(ply:Nick(), "TargetID", pos.x + 1, pos.y + 1, Color(0, 0, 0, 255), 1)
draw.DrawText(ply:Nick(), "TargetID", pos.x, pos.y, team.GetColor(ply:Team()), 1)
end
draw.DrawText(LANGUAGE.wanted.."
Reason: “…tostring(ply.DarkRPVars[“wantedReason”]), “TargetID”, pos.x, pos.y - 40, Color(255, 255, 255, 200), 1)
draw.DrawText(LANGUAGE.wanted…”
Reason: "…tostring(ply.DarkRPVars[“wantedReason”]), “TargetID”, pos.x + 1, pos.y - 41, Color(255, 0, 0, 255), 1)
end
/---------------------------------------------------------------------------
The Entity display: draw HUD information about entities
---------------------------------------------------------------------------/
local function DrawEntityDisplay()
for k, ply in pairs(player.GetAll()) do
if not ply:Alive() then continue end
ply.DarkRPVars = ply.DarkRPVars or {}
if ply.DarkRPVars.wanted then DrawWantedInfo(ply) end
if GetConVarNumber("globalshow") == 1 and ply ~= LocalPlayer() then DrawPlayerInfo(ply) end
end
local tr = LocalPlayer():GetEyeTrace()
if tr.Entity and tr.Entity.IsValid and ValidEntity(tr.Entity) and tr.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 400 then
if tr.Entity:IsPlayer() and not tobool(GetConVarNumber("globalshow")) then
DrawPlayerInfo(tr.Entity)
end
end
if 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().DarkRPVars.zombieToggle then return end
for x=1, LocalPlayer().DarkRPVars.numPoints, 1 do
local zPoint = LocalPlayer().DarkRPVars[“zPoints”… x]
if zPoint then
zPoint = zPoint:ToScreen()
draw.DrawText(“Zombie Spawn (” … x … “)”, “TargetID”, zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1)
draw.DrawText(“Zombie Spawn (” … x … “)”, “TargetID”, 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