Making custom HUD toggleable.

Hello! I’ve been working on modifying an old variant of TTT, call “TTT: Hitman Modification”. The varaint comes with a custom hud, however if you add it it will be the default hud and no one can switch to the one they prefer.
I was wondering what would I need to do in order to make the custom HUD toggleable (My guess would be something to do with cvars.)

Here is the code for the custom hud



if !SERVER then

local initlang = false
local margin = 10
local dr = draw
local math = math

local width = 300
local height = 20

local barcorner = surface.GetTextureID( "gui/corner8" )

-- Round status consts, those dont seem to be accessable globally
local ROUND_WAIT   = 1
local ROUND_PREP   = 2
local ROUND_ACTIVE = 3
local ROUND_POST   = 4

local ROLE_INNOCENT  = 0
local ROLE_TRAITOR   = 1
local ROLE_DETECTIVE = 2
local ROLE_NONE = ROLE_INNOCENT

local roundstate_string = {
   [ROUND_WAIT]   = "round_wait",
   [ROUND_PREP]   = "round_prep",
   [ROUND_ACTIVE] = "round_active",
   [ROUND_POST]   = "round_post"
};

surface.CreateFont("Hitman",   {font = "Marlett",
                                    size = 24,
                                    weight = 750})

local col_active = {
   tip = {
      [ROLE_INNOCENT]  = Color(55, 170, 50, 255),
      [ROLE_TRAITOR]   = Color(180, 50, 40, 255),
      [ROLE_DETECTIVE] = Color(50, 60, 180, 255)
   },

   bg = Color(20, 20, 20, 250),

   text_empty = Color(200, 20, 20, 255),
   text = Color(255, 255, 255, 255),

   shadow = 255
};

local col_dark = {
   tip = {
      [ROLE_INNOCENT]  = Color(60, 160, 50, 155),
      [ROLE_TRAITOR]   = Color(160, 50, 60, 155),
      [ROLE_DETECTIVE] = Color(50, 60, 160, 155),
   },

   bg = Color(20, 20, 20, 200),

   text_empty = Color(200, 20, 20, 100),
   text = Color(255, 255, 255, 100),

   shadow = 100
};

local function OverrideHUD()
    initlang = true
    local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", "TTTInfoPanel","TTTWSwitch"}
    function GAMEMODE:HUDShouldDraw(name)
       for k, v in pairs(hud) do
          if name == v then return false end
       end
       return true
    end
end
hook.Add("Initialize", "OverrideHUD", OverrideHUD)

local function HitmanInfoPaint()
   local client = LocalPlayer()
   if !initlang or client:Team() == TEAM_SPEC or client:Alive() == 0 then return end
   local L = LANG.GetUnsafeLanguageTable()

   local color = Color(128,128,128)
   if client:GetRole() == ROLE_TRAITOR then color = Color(128, 0, 0) end
   local round_state = GAMEMODE.round_state

   local width = 150
   local height = 90

   local x = ScrW() - margin - width
   local y = ScrH() - margin - height

   --DrawBg(x, y, width, height, client)

   local bar_height = 25
   local bar_width = width - (margin*2)

   -- Draw health
   local health = math.max(0, client:Health())
   local health_y = y + margin

   --PaintBar(x + margin, health_y, bar_width, bar_height, health_colors, health/100)

   ShadowedText(SimplisticHealthbar(health), "Hitman", x+margin, health_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)

   -- Draw ammo
   if client:GetActiveWeapon().Primary then
      local ammo_clip, ammo_max, ammo_inv = GetAmmo(client)
      if ammo_clip != -1 then
         local ammo_y = health_y + bar_height + margin
         --PaintBar(x+margin, ammo_y, bar_width, bar_height, ammo_colors, ammo_clip/ammo_max)
         local text = string.format("%i + %02i", ammo_clip, ammo_inv)

         ShadowedText(ammo_clip, "Hitman", x+margin, ammo_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
         ShadowedText(ammo_inv, "Hitman", x+bar_width, ammo_y, color, TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)
      end
   end
   if !sb_visible then return end
   -- Draw traitor state

   local traitor_y = y - 30
   local text = nil
   if round_state == ROUND_ACTIVE then
      text = L[ client:GetRoleStringRaw() ]
   else
      text = L[ roundstate_string[round_state] ]
   end

   --ShadowedText(text, "TraitorState", x + margin + 73, traitor_y, COLOR_WHITE, TEXT_ALIGN_CENTER)
   dr.SimpleText(text, "TimeLeft", ScrW()/2 - 50, 5, color, TEXT_ALIGN_RIGHT)

   -- Draw round time

   local is_haste = HasteMode() and round_state == ROUND_ACTIVE
   local is_traitor = client:IsActiveTraitor()

   local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()

   local text
   local font = "TimeLeft"
   local rx = x + margin + 170
   local ry = traitor_y + 3

   -- Time displays differently depending on whether haste mode is on,
   -- whether the player is traitor or not, and whether it is overtime.
   if is_haste then
      local hastetime = GetGlobalFloat("ttt_haste_end", 0) - CurTime()
      if hastetime < 0 then
         if (not is_traitor) or (math.ceil(CurTime()) % 7 <= 2) then
            -- innocent or blinking "overtime"
            text = L.overtime
            font = "Trebuchet18"

            -- need to hack the position a little because of the font switch
            ry = ry + 5
            rx = rx - 3
         else
            -- traitor and not blinking "overtime" right now, so standard endtime display
            text  = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
            color = COLOR_RED
         end
      else
         -- still in starting period
         local t = hastetime
         if is_traitor and math.ceil(CurTime()) % 6 < 2 then
            t = endtime
            color = COLOR_RED
         end
         text = util.SimpleTime(math.max(0, t), "%02i:%02i")
      end
   else
      -- bog standard time when haste mode is off (or round not active)
      text = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
   end

   --ShadowedText(text, font, rx, ry, color)
   dr.SimpleText(text, font, ScrW()/2, 5, color, TEXT_ALIGN_CENTER)

   if is_haste then
      dr.SimpleText(L.hastemode, "TabLarge", ScrW()/2, 25, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
   end

end
hook.Add("HUDPaint", "HitmanInfoPaint", HitmanInfoPaint)

local function HitmanWeaponSwitch()
   if not WSWITCH.Show then return end

   local weps = WSWITCH.WeaponCache

   local x = ScrW() - width - margin*2
   local y = margin

   local col = col_dark
   for k, wep in pairs(weps) do
      if WSWITCH.Selected == k then
         col = col_active
      else
         col = col_dark
      end

      DrawBarBg(x, y, width, height, col)
      if not WSWITCH:DrawWeapon(x, y, col, wep) then

         WSWITCH:UpdateWeaponCache()
         return
      end

      y = y + height + margin
   end
end
hook.Add("HUDPaint", "HitmanWeaponSwitch", HitmanWeaponSwitch)

local function DisplayHitlistHUD()
    client = LocalPlayer()
    if hitman_targetname and client:Alive() and client:IsTraitor() then
        --Target announcer
        draw.SimpleText("Kill " .. hitman_targetname, "HealthAmmo", ScrW()/2, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        if sb_visible then
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", 5, ScrH() - 40, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

            draw.SimpleText("Killed Bystanders: " .. hitman_civkills, "HealthAmmo", 5, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        end
    end
end
hook.Remove("DisplayHitlistHUD")
hook.Add("HUDPaint", "DisplayHitlistHUD", DisplayHitlistHUD)

function SimplisticHealthbar(health)
    if health > 100 then health = 100 end
    maxhealthbars = 25
    local temp = ""
    for i = 1,(health/100)*maxhealthbars do
        temp = temp .. "|"
    end
    return temp
end

function ShadowedText(text, font, x, y, color, xalign, yalign)
   dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign)
   dr.SimpleText(text, font, x, y, color, xalign, yalign)
end

function DrawBarBg(x, y, w, h, col)
   local rx = math.Round(x - 4)
   local ry = math.Round(y - (h / 2)-4)
   local rw = math.Round(w + 9)
   local rh = math.Round(h + 8)

   local b = 8 --bordersize
   local bh = b / 2

   local role = LocalPlayer():GetRole() or ROLE_INNOCENT

   local c = col.bg

   -- Draw the colour tip
   surface.SetTexture(barcorner)

   surface.SetDrawColor(c.r, c.g, c.b, c.a)
   --surface.DrawTexturedRectRotated( rx + bh , ry + bh, b, b, 0 )
   --surface.DrawTexturedRectRotated( rx + bh , ry + rh -bh, b, b, 90 )
   --surface.DrawRect( rx, ry+b, b, rh-b*2 )
   surface.DrawRect( rx, ry, h, rh )

   -- Draw the remainder
   -- Could just draw a full roundedrect bg and overdraw it with the tip, but
   -- I don't have to do the hard work here anymore anyway
   c = col.bg
   surface.SetDrawColor(c.r, c.g, c.b, c.a)

   surface.DrawRect( rx+b+h-4, ry,  rw,  rh )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + rh - bh, b, b, 180 )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + bh, b, b, 270 )
   --surface.DrawRect( rx+rw-b,  ry+b,  b,  rh-b*2 )

end

function GetAmmo(ply)
   local weap = ply:GetActiveWeapon()
   if not weap or not ply:Alive() then return -1 end

   local ammo_inv = weap:Ammo1() or 0
   local ammo_clip = weap:Clip1() or 0
   local ammo_max = weap.Primary.ClipSize or 0

   return ammo_clip, ammo_max, ammo_inv
end

hook.Add("ScoreboardShow", "sb_visible_true", function() sb_visible = true end)
hook.Add("ScoreboardHide", "sb_visible_false", function() sb_visible = false end)

end


I’ve been tinkering around with cvars but with no success, can anyone help?

The goal is to make the custom hud default at 0, but if you want to try the hitman hud you would type something like “hitman_hud 1” into console.

Setup this https://wiki.garrysmod.com/page/Global/CreateConVar at the beginning of the file, with the default = 0 and in your code, before it draws the hud part, check it with https://wiki.garrysmod.com/page/Global/GetConVar and https://wiki.garrysmod.com/page/ConVar/GetBool

It did’t work sadly, it gave me this error:


 
[ERROR] lua/autorun/hitman_custom_hud.lua:5: bad argument #1 to 'GetConVar' (string expected, got nil)
  1. GetConVar - [C]:-1
   2. unknown - lua/autorun/hitman_custom_hud.lua:5


Here is the revised code I did based on your suggestions



CreateConVar( "hitman_hud", "0", "1073741824", "If this command is enabled, you will see the custom hitman hud" )

if !SERVER then

GetConVar( hitman_hud )
ConVar:GetBool()

local initlang = false
local margin = 10
local dr = draw
local math = math

local width = 300
local height = 20

local barcorner = surface.GetTextureID( "gui/corner8" )

-- Round status consts, those dont seem to be accessable globally
local ROUND_WAIT   = 1
local ROUND_PREP   = 2
local ROUND_ACTIVE = 3
local ROUND_POST   = 4

local ROLE_INNOCENT  = 0
local ROLE_TRAITOR   = 1
local ROLE_DETECTIVE = 2
local ROLE_NONE = ROLE_INNOCENT

local roundstate_string = {
   [ROUND_WAIT]   = "round_wait",
   [ROUND_PREP]   = "round_prep",
   [ROUND_ACTIVE] = "round_active",
   [ROUND_POST]   = "round_post"
};

surface.CreateFont("Hitman",   {font = "Marlett",
                                    size = 24,
                                    weight = 750})

local col_active = {
   tip = {
      [ROLE_INNOCENT]  = Color(55, 170, 50, 255),
      [ROLE_TRAITOR]   = Color(180, 50, 40, 255),
      [ROLE_DETECTIVE] = Color(50, 60, 180, 255)
   },

   bg = Color(20, 20, 20, 250),

   text_empty = Color(200, 20, 20, 255),
   text = Color(255, 255, 255, 255),

   shadow = 255
};

local col_dark = {
   tip = {
      [ROLE_INNOCENT]  = Color(60, 160, 50, 155),
      [ROLE_TRAITOR]   = Color(160, 50, 60, 155),
      [ROLE_DETECTIVE] = Color(50, 60, 160, 155),
   },

   bg = Color(20, 20, 20, 200),

   text_empty = Color(200, 20, 20, 100),
   text = Color(255, 255, 255, 100),

   shadow = 100
};

local function OverrideHUD()
    initlang = true
    local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", "TTTInfoPanel","TTTWSwitch"}
    function GAMEMODE:HUDShouldDraw(name)
       for k, v in pairs(hud) do
          if name == v then return false end
       end
       return true
    end
end
hook.Add("Initialize", "OverrideHUD", OverrideHUD)

local function HitmanInfoPaint()
   local client = LocalPlayer()
   if !initlang or client:Team() == TEAM_SPEC or client:Alive() == 0 then return end
   local L = LANG.GetUnsafeLanguageTable()

   local color = Color(128,128,128)
   if client:GetRole() == ROLE_TRAITOR then color = Color(128, 0, 0) end
   local round_state = GAMEMODE.round_state

   local width = 150
   local height = 90

   local x = ScrW() - margin - width
   local y = ScrH() - margin - height

   --DrawBg(x, y, width, height, client)

   local bar_height = 25
   local bar_width = width - (margin*2)

   -- Draw health
   local health = math.max(0, client:Health())
   local health_y = y + margin

   --PaintBar(x + margin, health_y, bar_width, bar_height, health_colors, health/100)

   ShadowedText(SimplisticHealthbar(health), "Hitman", x+margin, health_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)

   -- Draw ammo
   if client:GetActiveWeapon().Primary then
      local ammo_clip, ammo_max, ammo_inv = GetAmmo(client)
      if ammo_clip != -1 then
         local ammo_y = health_y + bar_height + margin
         --PaintBar(x+margin, ammo_y, bar_width, bar_height, ammo_colors, ammo_clip/ammo_max)
         local text = string.format("%i + %02i", ammo_clip, ammo_inv)

         ShadowedText(ammo_clip, "Hitman", x+margin, ammo_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
         ShadowedText(ammo_inv, "Hitman", x+bar_width, ammo_y, color, TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)
      end
   end
   if !sb_visible then return end
   -- Draw traitor state

   local traitor_y = y - 30
   local text = nil
   if round_state == ROUND_ACTIVE then
      text = L[ client:GetRoleStringRaw() ]
   else
      text = L[ roundstate_string[round_state] ]
   end

   --ShadowedText(text, "TraitorState", x + margin + 73, traitor_y, COLOR_WHITE, TEXT_ALIGN_CENTER)
   dr.SimpleText(text, "TimeLeft", ScrW()/2 - 50, 5, color, TEXT_ALIGN_RIGHT)

   -- Draw round time

   local is_haste = HasteMode() and round_state == ROUND_ACTIVE
   local is_traitor = client:IsActiveTraitor()

   local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()

   local text
   local font = "TimeLeft"
   local rx = x + margin + 170
   local ry = traitor_y + 3

   -- Time displays differently depending on whether haste mode is on,
   -- whether the player is traitor or not, and whether it is overtime.
   if is_haste then
      local hastetime = GetGlobalFloat("ttt_haste_end", 0) - CurTime()
      if hastetime < 0 then
         if (not is_traitor) or (math.ceil(CurTime()) % 7 <= 2) then
            -- innocent or blinking "overtime"
            text = L.overtime
            font = "Trebuchet18"

            -- need to hack the position a little because of the font switch
            ry = ry + 5
            rx = rx - 3
         else
            -- traitor and not blinking "overtime" right now, so standard endtime display
            text  = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
            color = COLOR_RED
         end
      else
         -- still in starting period
         local t = hastetime
         if is_traitor and math.ceil(CurTime()) % 6 < 2 then
            t = endtime
            color = COLOR_RED
         end
         text = util.SimpleTime(math.max(0, t), "%02i:%02i")
      end
   else
      -- bog standard time when haste mode is off (or round not active)
      text = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
   end

   --ShadowedText(text, font, rx, ry, color)
   dr.SimpleText(text, font, ScrW()/2, 5, color, TEXT_ALIGN_CENTER)

   if is_haste then
      dr.SimpleText(L.hastemode, "TabLarge", ScrW()/2, 25, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
   end

end
hook.Add("HUDPaint", "HitmanInfoPaint", HitmanInfoPaint)

local function HitmanWeaponSwitch()
   if not WSWITCH.Show then return end

   local weps = WSWITCH.WeaponCache

   local x = ScrW() - width - margin*2
   local y = margin

   local col = col_dark
   for k, wep in pairs(weps) do
      if WSWITCH.Selected == k then
         col = col_active
      else
         col = col_dark
      end

      DrawBarBg(x, y, width, height, col)
      if not WSWITCH:DrawWeapon(x, y, col, wep) then

         WSWITCH:UpdateWeaponCache()
         return
      end

      y = y + height + margin
   end
end
hook.Add("HUDPaint", "HitmanWeaponSwitch", HitmanWeaponSwitch)

local function DisplayHitlistHUD()
    client = LocalPlayer()
    if hitman_targetname and client:Alive() and client:IsTraitor() then
        --Target announcer
        draw.SimpleText("Kill " .. hitman_targetname, "HealthAmmo", ScrW()/2, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        if sb_visible then
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", 5, ScrH() - 40, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

            draw.SimpleText("Killed Bystanders: " .. hitman_civkills, "HealthAmmo", 5, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        end
    end
end
hook.Remove("DisplayHitlistHUD")
hook.Add("HUDPaint", "DisplayHitlistHUD", DisplayHitlistHUD)

function SimplisticHealthbar(health)
    if health > 100 then health = 100 end
    maxhealthbars = 25
    local temp = ""
    for i = 1,(health/100)*maxhealthbars do
        temp = temp .. "|"
    end
    return temp
end

function ShadowedText(text, font, x, y, color, xalign, yalign)
   dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign)
   dr.SimpleText(text, font, x, y, color, xalign, yalign)
end

function DrawBarBg(x, y, w, h, col)
   local rx = math.Round(x - 4)
   local ry = math.Round(y - (h / 2)-4)
   local rw = math.Round(w + 9)
   local rh = math.Round(h + 8)

   local b = 8 --bordersize
   local bh = b / 2

   local role = LocalPlayer():GetRole() or ROLE_INNOCENT

   local c = col.bg

   -- Draw the colour tip
   surface.SetTexture(barcorner)

   surface.SetDrawColor(c.r, c.g, c.b, c.a)
   --surface.DrawTexturedRectRotated( rx + bh , ry + bh, b, b, 0 )
   --surface.DrawTexturedRectRotated( rx + bh , ry + rh -bh, b, b, 90 )
   --surface.DrawRect( rx, ry+b, b, rh-b*2 )
   surface.DrawRect( rx, ry, h, rh )

   -- Draw the remainder
   -- Could just draw a full roundedrect bg and overdraw it with the tip, but
   -- I don't have to do the hard work here anymore anyway
   c = col.bg
   surface.SetDrawColor(c.r, c.g, c.b, c.a)

   surface.DrawRect( rx+b+h-4, ry,  rw,  rh )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + rh - bh, b, b, 180 )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + bh, b, b, 270 )
   --surface.DrawRect( rx+rw-b,  ry+b,  b,  rh-b*2 )

end

function GetAmmo(ply)
   local weap = ply:GetActiveWeapon()
   if not weap or not ply:Alive() then return -1 end

   local ammo_inv = weap:Ammo1() or 0
   local ammo_clip = weap:Clip1() or 0
   local ammo_max = weap.Primary.ClipSize or 0

   return ammo_clip, ammo_max, ammo_inv
end

hook.Add("ScoreboardShow", "sb_visible_true", function() sb_visible = true end)
hook.Add("ScoreboardHide", "sb_visible_false", function() sb_visible = false end)

end


Instead of CreateConVar, use CreateClientConVar. Then, add the following code


if GetConVarNumber("hitman_hud") < 1 then return end

That should not draw the hud for anyone who has the hitman_hud set below 1

That almost did it, however a person has to wait until the map changes to get the custom hud to show. It doesn’t change the moment you change the value from 0 to 1 and visa versa. Any fix?

here is the updated code:



CreateClientConVar( "hitman_hud", "0", true, false, "This will enable the hitman custom HUD" )

if GetConVarNumber("hitman_hud") < 1 then return end

if !SERVER then

local initlang = false
local margin = 10
local dr = draw
local math = math

local width = 300
local height = 20

local barcorner = surface.GetTextureID( "gui/corner8" )

-- Round status consts, those dont seem to be accessable globally
local ROUND_WAIT   = 1
local ROUND_PREP   = 2
local ROUND_ACTIVE = 3
local ROUND_POST   = 4

local ROLE_INNOCENT  = 0
local ROLE_TRAITOR   = 1
local ROLE_DETECTIVE = 2
local ROLE_NONE = ROLE_INNOCENT

local roundstate_string = {
   [ROUND_WAIT]   = "round_wait",
   [ROUND_PREP]   = "round_prep",
   [ROUND_ACTIVE] = "round_active",
   [ROUND_POST]   = "round_post"
};

surface.CreateFont("Hitman",   {font = "Marlett",
                                    size = 24,
                                    weight = 750})

local col_active = {
   tip = {
      [ROLE_INNOCENT]  = Color(55, 170, 50, 255),
      [ROLE_TRAITOR]   = Color(180, 50, 40, 255),
      [ROLE_DETECTIVE] = Color(50, 60, 180, 255)
   },

   bg = Color(20, 20, 20, 250),

   text_empty = Color(200, 20, 20, 255),
   text = Color(255, 255, 255, 255),

   shadow = 255
};

local col_dark = {
   tip = {
      [ROLE_INNOCENT]  = Color(60, 160, 50, 155),
      [ROLE_TRAITOR]   = Color(160, 50, 60, 155),
      [ROLE_DETECTIVE] = Color(50, 60, 160, 155),
   },

   bg = Color(20, 20, 20, 200),

   text_empty = Color(200, 20, 20, 100),
   text = Color(255, 255, 255, 100),

   shadow = 100
};

local function OverrideHUD()
    initlang = true
    local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", "TTTInfoPanel","TTTWSwitch"}
    function GAMEMODE:HUDShouldDraw(name)
       for k, v in pairs(hud) do
          if name == v then return false end
       end
       return true
    end
end
hook.Add("Initialize", "OverrideHUD", OverrideHUD)

local function HitmanInfoPaint()
   local client = LocalPlayer()
   if !initlang or client:Team() == TEAM_SPEC or client:Alive() == 0 then return end
   local L = LANG.GetUnsafeLanguageTable()

   local color = Color(128,128,128)
   if client:GetRole() == ROLE_TRAITOR then color = Color(128, 0, 0) end
   local round_state = GAMEMODE.round_state

   local width = 150
   local height = 90

   local x = ScrW() - margin - width
   local y = ScrH() - margin - height

   --DrawBg(x, y, width, height, client)

   local bar_height = 25
   local bar_width = width - (margin*2)

   -- Draw health
   local health = math.max(0, client:Health())
   local health_y = y + margin

   --PaintBar(x + margin, health_y, bar_width, bar_height, health_colors, health/100)

   ShadowedText(SimplisticHealthbar(health), "Hitman", x+margin, health_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)

   -- Draw ammo
   if client:GetActiveWeapon().Primary then
      local ammo_clip, ammo_max, ammo_inv = GetAmmo(client)
      if ammo_clip != -1 then
         local ammo_y = health_y + bar_height + margin
         --PaintBar(x+margin, ammo_y, bar_width, bar_height, ammo_colors, ammo_clip/ammo_max)
         local text = string.format("%i + %02i", ammo_clip, ammo_inv)

         ShadowedText(ammo_clip, "Hitman", x+margin, ammo_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
         ShadowedText(ammo_inv, "Hitman", x+bar_width, ammo_y, color, TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)
      end
   end
   if !sb_visible then return end
   -- Draw traitor state

   local traitor_y = y - 30
   local text = nil
   if round_state == ROUND_ACTIVE then
      text = L[ client:GetRoleStringRaw() ]
   else
      text = L[ roundstate_string[round_state] ]
   end

   --ShadowedText(text, "TraitorState", x + margin + 73, traitor_y, COLOR_WHITE, TEXT_ALIGN_CENTER)
   dr.SimpleText(text, "TimeLeft", ScrW()/2 - 50, 5, color, TEXT_ALIGN_RIGHT)

   -- Draw round time

   local is_haste = HasteMode() and round_state == ROUND_ACTIVE
   local is_traitor = client:IsActiveTraitor()

   local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()

   local text
   local font = "TimeLeft"
   local rx = x + margin + 170
   local ry = traitor_y + 3

   -- Time displays differently depending on whether haste mode is on,
   -- whether the player is traitor or not, and whether it is overtime.
   if is_haste then
      local hastetime = GetGlobalFloat("ttt_haste_end", 0) - CurTime()
      if hastetime < 0 then
         if (not is_traitor) or (math.ceil(CurTime()) % 7 <= 2) then
            -- innocent or blinking "overtime"
            text = L.overtime
            font = "Trebuchet18"

            -- need to hack the position a little because of the font switch
            ry = ry + 5
            rx = rx - 3
         else
            -- traitor and not blinking "overtime" right now, so standard endtime display
            text  = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
            color = COLOR_RED
         end
      else
         -- still in starting period
         local t = hastetime
         if is_traitor and math.ceil(CurTime()) % 6 < 2 then
            t = endtime
            color = COLOR_RED
         end
         text = util.SimpleTime(math.max(0, t), "%02i:%02i")
      end
   else
      -- bog standard time when haste mode is off (or round not active)
      text = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
   end

   --ShadowedText(text, font, rx, ry, color)
   dr.SimpleText(text, font, ScrW()/2, 5, color, TEXT_ALIGN_CENTER)

   if is_haste then
      dr.SimpleText(L.hastemode, "TabLarge", ScrW()/2, 25, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
   end

end
hook.Add("HUDPaint", "HitmanInfoPaint", HitmanInfoPaint)

local function HitmanWeaponSwitch()
   if not WSWITCH.Show then return end

   local weps = WSWITCH.WeaponCache

   local x = ScrW() - width - margin*2
   local y = margin

   local col = col_dark
   for k, wep in pairs(weps) do
      if WSWITCH.Selected == k then
         col = col_active
      else
         col = col_dark
      end

      DrawBarBg(x, y, width, height, col)
      if not WSWITCH:DrawWeapon(x, y, col, wep) then

         WSWITCH:UpdateWeaponCache()
         return
      end

      y = y + height + margin
   end
end
hook.Add("HUDPaint", "HitmanWeaponSwitch", HitmanWeaponSwitch)

local function DisplayHitlistHUD()
    client = LocalPlayer()
    if hitman_targetname and client:Alive() and client:IsTraitor() then
        --Target announcer
        draw.SimpleText("Kill " .. hitman_targetname, "HealthAmmo", ScrW()/2, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        if sb_visible then
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", 5, ScrH() - 40, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

            draw.SimpleText("Killed Bystanders: " .. hitman_civkills, "HealthAmmo", 5, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        end
    end
end
hook.Remove("DisplayHitlistHUD")
hook.Add("HUDPaint", "DisplayHitlistHUD", DisplayHitlistHUD)

function SimplisticHealthbar(health)
    if health > 100 then health = 100 end
    maxhealthbars = 25
    local temp = ""
    for i = 1,(health/100)*maxhealthbars do
        temp = temp .. "|"
    end
    return temp
end

function ShadowedText(text, font, x, y, color, xalign, yalign)
   dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign)
   dr.SimpleText(text, font, x, y, color, xalign, yalign)
end

function DrawBarBg(x, y, w, h, col)
   local rx = math.Round(x - 4)
   local ry = math.Round(y - (h / 2)-4)
   local rw = math.Round(w + 9)
   local rh = math.Round(h + 8)

   local b = 8 --bordersize
   local bh = b / 2

   local role = LocalPlayer():GetRole() or ROLE_INNOCENT

   local c = col.bg

   -- Draw the colour tip
   surface.SetTexture(barcorner)

   surface.SetDrawColor(c.r, c.g, c.b, c.a)
   --surface.DrawTexturedRectRotated( rx + bh , ry + bh, b, b, 0 )
   --surface.DrawTexturedRectRotated( rx + bh , ry + rh -bh, b, b, 90 )
   --surface.DrawRect( rx, ry+b, b, rh-b*2 )
   surface.DrawRect( rx, ry, h, rh )

   -- Draw the remainder
   -- Could just draw a full roundedrect bg and overdraw it with the tip, but
   -- I don't have to do the hard work here anymore anyway
   c = col.bg
   surface.SetDrawColor(c.r, c.g, c.b, c.a)

   surface.DrawRect( rx+b+h-4, ry,  rw,  rh )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + rh - bh, b, b, 180 )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + bh, b, b, 270 )
   --surface.DrawRect( rx+rw-b,  ry+b,  b,  rh-b*2 )

end

function GetAmmo(ply)
   local weap = ply:GetActiveWeapon()
   if not weap or not ply:Alive() then return -1 end

   local ammo_inv = weap:Ammo1() or 0
   local ammo_clip = weap:Clip1() or 0
   local ammo_max = weap.Primary.ClipSize or 0

   return ammo_clip, ammo_max, ammo_inv
end

hook.Add("ScoreboardShow", "sb_visible_true", function() sb_visible = true end)
hook.Add("ScoreboardHide", "sb_visible_false", function() sb_visible = false end)

end


Shitty example. but it works for me.




MyHud = 1

if MyHud == 1 then
	hook.Add( "HUDPaint", "HUDPaint_DrawABox", function()
		draw.RoundedBox( 0, 0, 0, 128, 128, Color( 0, 0, 0, 128 ) )
	end )
end

concommand.Add( "myhud_on", function( ply, cmd, args )
	MyHud = 1
end )

concommand.Add( "myhud_off", function( ply, cmd, args )
	MyHud = 0
end )


I’ll try it

EDIT: Wait where would I put that in the code I have?

You wouldn’t it’s just an example of how to toggle. ( A shitty way )

And your code would go under then if MyHud == 1

You do realize that with this solution, the hud will never turn off.

It didn’t work. Is there a way to reinitialize the script once a client has changed “hitman_hud 0” to “hitman_hud 1” and visa versa?

He’d have to be checking if MyHud or hitman_hud or whatever was equivalent to 1 inside the HUDPaint hook.

Try this:


CreateClientConVar( "hitman_hud", "0", true, false )

--if GetConVarNumber("hitman_hud") < 1 then return end -- needs to be inside a function otherwise it wont get refreshed. Moved that for you :)

if !SERVER then

local initlang = false
local margin = 10
local dr = draw
local math = math

local width = 300
local height = 20

local barcorner = surface.GetTextureID( "gui/corner8" )

-- Round status consts, those dont seem to be accessable globally
local ROUND_WAIT   = 1
local ROUND_PREP   = 2
local ROUND_ACTIVE = 3
local ROUND_POST   = 4

local ROLE_INNOCENT  = 0
local ROLE_TRAITOR   = 1
local ROLE_DETECTIVE = 2
local ROLE_NONE = ROLE_INNOCENT

local roundstate_string = {
   [ROUND_WAIT]   = "round_wait",
   [ROUND_PREP]   = "round_prep",
   [ROUND_ACTIVE] = "round_active",
   [ROUND_POST]   = "round_post"
};

surface.CreateFont("Hitman",   {font = "Marlett",
                                    size = 24,
                                    weight = 750})

local col_active = {
   tip = {
      [ROLE_INNOCENT]  = Color(55, 170, 50, 255),
      [ROLE_TRAITOR]   = Color(180, 50, 40, 255),
      [ROLE_DETECTIVE] = Color(50, 60, 180, 255)
   },

   bg = Color(20, 20, 20, 250),

   text_empty = Color(200, 20, 20, 255),
   text = Color(255, 255, 255, 255),

   shadow = 255
};

local col_dark = {
   tip = {
      [ROLE_INNOCENT]  = Color(60, 160, 50, 155),
      [ROLE_TRAITOR]   = Color(160, 50, 60, 155),
      [ROLE_DETECTIVE] = Color(50, 60, 160, 155),
   },

   bg = Color(20, 20, 20, 200),

   text_empty = Color(200, 20, 20, 100),
   text = Color(255, 255, 255, 100),

   shadow = 100
};

local function OverrideHUD()
    initlang = true
    local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", "TTTInfoPanel","TTTWSwitch"}
    function GAMEMODE:HUDShouldDraw(name)
       for k, v in pairs(hud) do
          if name == v then return false end
       end
       return true
    end
end
hook.Add("Initialize", "OverrideHUD", OverrideHUD)

local function HitmanInfoPaint()
if GetConVarNumber("hitman_hud") < 1 then return end
   local client = LocalPlayer()
   if !initlang or client:Team() == TEAM_SPEC or client:Alive() == 0 then return end
   local L = LANG.GetUnsafeLanguageTable()

   local color = Color(128,128,128)
   if client:GetRole() == ROLE_TRAITOR then color = Color(128, 0, 0) end
   local round_state = GAMEMODE.round_state

   local width = 150
   local height = 90

   local x = ScrW() - margin - width
   local y = ScrH() - margin - height

   --DrawBg(x, y, width, height, client)

   local bar_height = 25
   local bar_width = width - (margin*2)

   -- Draw health
   local health = math.max(0, client:Health())
   local health_y = y + margin

   --PaintBar(x + margin, health_y, bar_width, bar_height, health_colors, health/100)

   ShadowedText(SimplisticHealthbar(health), "Hitman", x+margin, health_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)

   -- Draw ammo
   if client:GetActiveWeapon().Primary then
      local ammo_clip, ammo_max, ammo_inv = GetAmmo(client)
      if ammo_clip != -1 then
         local ammo_y = health_y + bar_height + margin
         --PaintBar(x+margin, ammo_y, bar_width, bar_height, ammo_colors, ammo_clip/ammo_max)
         local text = string.format("%i + %02i", ammo_clip, ammo_inv)

         ShadowedText(ammo_clip, "Hitman", x+margin, ammo_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
         ShadowedText(ammo_inv, "Hitman", x+bar_width, ammo_y, color, TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)
      end
   end
   if !sb_visible then return end
   -- Draw traitor state

   local traitor_y = y - 30
   local text = nil
   if round_state == ROUND_ACTIVE then
      text = L[ client:GetRoleStringRaw() ]
   else
      text = L[ roundstate_string[round_state] ]
   end

   --ShadowedText(text, "TraitorState", x + margin + 73, traitor_y, COLOR_WHITE, TEXT_ALIGN_CENTER)
   dr.SimpleText(text, "TimeLeft", ScrW()/2 - 50, 5, color, TEXT_ALIGN_RIGHT)

   -- Draw round time

   local is_haste = HasteMode() and round_state == ROUND_ACTIVE
   local is_traitor = client:IsActiveTraitor()

   local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()

   local text
   local font = "TimeLeft"
   local rx = x + margin + 170
   local ry = traitor_y + 3

   -- Time displays differently depending on whether haste mode is on,
   -- whether the player is traitor or not, and whether it is overtime.
   if is_haste then
      local hastetime = GetGlobalFloat("ttt_haste_end", 0) - CurTime()
      if hastetime < 0 then
         if (not is_traitor) or (math.ceil(CurTime()) % 7 <= 2) then
            -- innocent or blinking "overtime"
            text = L.overtime
            font = "Trebuchet18"

            -- need to hack the position a little because of the font switch
            ry = ry + 5
            rx = rx - 3
         else
            -- traitor and not blinking "overtime" right now, so standard endtime display
            text  = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
            color = COLOR_RED
         end
      else
         -- still in starting period
         local t = hastetime
         if is_traitor and math.ceil(CurTime()) % 6 < 2 then
            t = endtime
            color = COLOR_RED
         end
         text = util.SimpleTime(math.max(0, t), "%02i:%02i")
      end
   else
      -- bog standard time when haste mode is off (or round not active)
      text = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
   end

   --ShadowedText(text, font, rx, ry, color)
   dr.SimpleText(text, font, ScrW()/2, 5, color, TEXT_ALIGN_CENTER)

   if is_haste then
      dr.SimpleText(L.hastemode, "TabLarge", ScrW()/2, 25, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
   end

end
hook.Add("HUDPaint", "HitmanInfoPaint", HitmanInfoPaint)

local function HitmanWeaponSwitch()
if GetConVarNumber("hitman_hud") < 1 then return end
   if not WSWITCH.Show then return end

   local weps = WSWITCH.WeaponCache

   local x = ScrW() - width - margin*2
   local y = margin

   local col = col_dark
   for k, wep in pairs(weps) do
      if WSWITCH.Selected == k then
         col = col_active
      else
         col = col_dark
      end

      DrawBarBg(x, y, width, height, col)
      if not WSWITCH:DrawWeapon(x, y, col, wep) then

         WSWITCH:UpdateWeaponCache()
         return
      end

      y = y + height + margin
   end
end
hook.Add("HUDPaint", "HitmanWeaponSwitch", HitmanWeaponSwitch)

local function DisplayHitlistHUD()
if GetConVarNumber("hitman_hud") < 1 then return end
    client = LocalPlayer()
    if hitman_targetname and client:Alive() and client:IsTraitor() then
        --Target announcer
        draw.SimpleText("Kill " .. hitman_targetname, "HealthAmmo", ScrW()/2, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        if sb_visible then
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", 5, ScrH() - 40, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

            draw.SimpleText("Killed Bystanders: " .. hitman_civkills, "HealthAmmo", 5, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        end
    end
end
hook.Remove("DisplayHitlistHUD")
hook.Add("HUDPaint", "DisplayHitlistHUD", DisplayHitlistHUD)

function SimplisticHealthbar(health)
if GetConVarNumber("hitman_hud") < 1 then return end
    if health > 100 then health = 100 end
    maxhealthbars = 25
    local temp = ""
    for i = 1,(health/100)*maxhealthbars do
        temp = temp .. "|"
    end
    return temp
end

function ShadowedText(text, font, x, y, color, xalign, yalign)
   dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign)
   dr.SimpleText(text, font, x, y, color, xalign, yalign)
end

function DrawBarBg(x, y, w, h, col)
   local rx = math.Round(x - 4)
   local ry = math.Round(y - (h / 2)-4)
   local rw = math.Round(w + 9)
   local rh = math.Round(h + 8)

   local b = 8 --bordersize
   local bh = b / 2

   local role = LocalPlayer():GetRole() or ROLE_INNOCENT

   local c = col.bg

   -- Draw the colour tip
   surface.SetTexture(barcorner)

   surface.SetDrawColor(c.r, c.g, c.b, c.a)
   --surface.DrawTexturedRectRotated( rx + bh , ry + bh, b, b, 0 )
   --surface.DrawTexturedRectRotated( rx + bh , ry + rh -bh, b, b, 90 )
   --surface.DrawRect( rx, ry+b, b, rh-b*2 )
   surface.DrawRect( rx, ry, h, rh )

   -- Draw the remainder
   -- Could just draw a full roundedrect bg and overdraw it with the tip, but
   -- I don't have to do the hard work here anymore anyway
   c = col.bg
   surface.SetDrawColor(c.r, c.g, c.b, c.a)

   surface.DrawRect( rx+b+h-4, ry,  rw,  rh )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + rh - bh, b, b, 180 )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + bh, b, b, 270 )
   --surface.DrawRect( rx+rw-b,  ry+b,  b,  rh-b*2 )

end

function GetAmmo(ply)
   local weap = ply:GetActiveWeapon()
   if not weap or not ply:Alive() then return -1 end

   local ammo_inv = weap:Ammo1() or 0
   local ammo_clip = weap:Clip1() or 0
   local ammo_max = weap.Primary.ClipSize or 0

   return ammo_clip, ammo_max, ammo_inv
end

hook.Add("ScoreboardShow", "sb_visible_true", function() sb_visible = true end)
hook.Add("ScoreboardHide", "sb_visible_false", function() sb_visible = false end)

end

It should be working now. Should :slight_smile:

How would I achieve this? What would I put in the hooks?

EDIT: I’m going to try the code above real quick!

[editline]27th July 2016[/editline]

Very close yet so far :frowning: The hud goes blank when I type “hitman_hud 0”

Okay, edited it a bit more. It should now draw the default TTT hud if Hitman hud is disabled. Edited this on facepunch, but syntax should be fine


CreateClientConVar( "hitman_hud", "0", true, false )

--if GetConVarNumber("hitman_hud") < 1 then return end -- needs to be inside a function otherwise it wont get refreshed. Moved that for you :)

if !SERVER then

local initlang = false
local margin = 10
local dr = draw
local math = math

local width = 300
local height = 20

local barcorner = surface.GetTextureID( "gui/corner8" )

-- Round status consts, those dont seem to be accessable globally
local ROUND_WAIT   = 1
local ROUND_PREP   = 2
local ROUND_ACTIVE = 3
local ROUND_POST   = 4

local ROLE_INNOCENT  = 0
local ROLE_TRAITOR   = 1
local ROLE_DETECTIVE = 2
local ROLE_NONE = ROLE_INNOCENT

local roundstate_string = {
   [ROUND_WAIT]   = "round_wait",
   [ROUND_PREP]   = "round_prep",
   [ROUND_ACTIVE] = "round_active",
   [ROUND_POST]   = "round_post"
};

surface.CreateFont("Hitman",   {font = "Marlett",
                                    size = 24,
                                    weight = 750})

local col_active = {
   tip = {
      [ROLE_INNOCENT]  = Color(55, 170, 50, 255),
      [ROLE_TRAITOR]   = Color(180, 50, 40, 255),
      [ROLE_DETECTIVE] = Color(50, 60, 180, 255)
   },

   bg = Color(20, 20, 20, 250),

   text_empty = Color(200, 20, 20, 255),
   text = Color(255, 255, 255, 255),

   shadow = 255
};

local col_dark = {
   tip = {
      [ROLE_INNOCENT]  = Color(60, 160, 50, 155),
      [ROLE_TRAITOR]   = Color(160, 50, 60, 155),
      [ROLE_DETECTIVE] = Color(50, 60, 160, 155),
   },

   bg = Color(20, 20, 20, 200),

   text_empty = Color(200, 20, 20, 100),
   text = Color(255, 255, 255, 100),

   shadow = 100
};

local function OverrideHUD()
    initlang = true
    local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}
    local hud_ttt = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo", "TTTInfoPanel","TTTWSwitch"}
    local hud_to_hide = {}
    if GetConVarNumber("hitman_hud") > 0 then
        hud_to_hide = hud_ttt
    else
        hud_to_hide = hud
    end
    function GAMEMODE:HUDShouldDraw(name)
       for k, v in pairs(hud_to_hide) do
          if name == v then return false end
       end
       return true
    end
end
hook.Add("Initialize", "OverrideHUD", OverrideHUD)

local function HitmanInfoPaint()
if GetConVarNumber("hitman_hud") < 1 then return end
   local client = LocalPlayer()
   if !initlang or client:Team() == TEAM_SPEC or client:Alive() == 0 then return end
   local L = LANG.GetUnsafeLanguageTable()

   local color = Color(128,128,128)
   if client:GetRole() == ROLE_TRAITOR then color = Color(128, 0, 0) end
   local round_state = GAMEMODE.round_state

   local width = 150
   local height = 90

   local x = ScrW() - margin - width
   local y = ScrH() - margin - height

   --DrawBg(x, y, width, height, client)

   local bar_height = 25
   local bar_width = width - (margin*2)

   -- Draw health
   local health = math.max(0, client:Health())
   local health_y = y + margin

   --PaintBar(x + margin, health_y, bar_width, bar_height, health_colors, health/100)

   ShadowedText(SimplisticHealthbar(health), "Hitman", x+margin, health_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)

   -- Draw ammo
   if client:GetActiveWeapon().Primary then
      local ammo_clip, ammo_max, ammo_inv = GetAmmo(client)
      if ammo_clip != -1 then
         local ammo_y = health_y + bar_height + margin
         --PaintBar(x+margin, ammo_y, bar_width, bar_height, ammo_colors, ammo_clip/ammo_max)
         local text = string.format("%i + %02i", ammo_clip, ammo_inv)

         ShadowedText(ammo_clip, "Hitman", x+margin, ammo_y, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
         ShadowedText(ammo_inv, "Hitman", x+bar_width, ammo_y, color, TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT)
      end
   end
   if !sb_visible then return end
   -- Draw traitor state

   local traitor_y = y - 30
   local text = nil
   if round_state == ROUND_ACTIVE then
      text = L[ client:GetRoleStringRaw() ]
   else
      text = L[ roundstate_string[round_state] ]
   end

   --ShadowedText(text, "TraitorState", x + margin + 73, traitor_y, COLOR_WHITE, TEXT_ALIGN_CENTER)
   dr.SimpleText(text, "TimeLeft", ScrW()/2 - 50, 5, color, TEXT_ALIGN_RIGHT)

   -- Draw round time

   local is_haste = HasteMode() and round_state == ROUND_ACTIVE
   local is_traitor = client:IsActiveTraitor()

   local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()

   local text
   local font = "TimeLeft"
   local rx = x + margin + 170
   local ry = traitor_y + 3

   -- Time displays differently depending on whether haste mode is on,
   -- whether the player is traitor or not, and whether it is overtime.
   if is_haste then
      local hastetime = GetGlobalFloat("ttt_haste_end", 0) - CurTime()
      if hastetime < 0 then
         if (not is_traitor) or (math.ceil(CurTime()) % 7 <= 2) then
            -- innocent or blinking "overtime"
            text = L.overtime
            font = "Trebuchet18"

            -- need to hack the position a little because of the font switch
            ry = ry + 5
            rx = rx - 3
         else
            -- traitor and not blinking "overtime" right now, so standard endtime display
            text  = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
            color = COLOR_RED
         end
      else
         -- still in starting period
         local t = hastetime
         if is_traitor and math.ceil(CurTime()) % 6 < 2 then
            t = endtime
            color = COLOR_RED
         end
         text = util.SimpleTime(math.max(0, t), "%02i:%02i")
      end
   else
      -- bog standard time when haste mode is off (or round not active)
      text = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
   end

   --ShadowedText(text, font, rx, ry, color)
   dr.SimpleText(text, font, ScrW()/2, 5, color, TEXT_ALIGN_CENTER)

   if is_haste then
      dr.SimpleText(L.hastemode, "TabLarge", ScrW()/2, 25, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
   end

end
hook.Add("HUDPaint", "HitmanInfoPaint", HitmanInfoPaint)

local function HitmanWeaponSwitch()
if GetConVarNumber("hitman_hud") < 1 then return end
   if not WSWITCH.Show then return end

   local weps = WSWITCH.WeaponCache

   local x = ScrW() - width - margin*2
   local y = margin

   local col = col_dark
   for k, wep in pairs(weps) do
      if WSWITCH.Selected == k then
         col = col_active
      else
         col = col_dark
      end

      DrawBarBg(x, y, width, height, col)
      if not WSWITCH:DrawWeapon(x, y, col, wep) then

         WSWITCH:UpdateWeaponCache()
         return
      end

      y = y + height + margin
   end
end
hook.Add("HUDPaint", "HitmanWeaponSwitch", HitmanWeaponSwitch)

local function DisplayHitlistHUD()
if GetConVarNumber("hitman_hud") < 1 then return end
    client = LocalPlayer()
    if hitman_targetname and client:Alive() and client:IsTraitor() then
        --Target announcer
        draw.SimpleText("Kill " .. hitman_targetname, "HealthAmmo", ScrW()/2, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        if sb_visible then
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", 5, ScrH() - 40, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

            draw.SimpleText("Killed Bystanders: " .. hitman_civkills, "HealthAmmo", 5, ScrH() - 20, Color(128, 0, 0), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
        end
    end
end
hook.Remove("DisplayHitlistHUD")
hook.Add("HUDPaint", "DisplayHitlistHUD", DisplayHitlistHUD)

function SimplisticHealthbar(health)
if GetConVarNumber("hitman_hud") < 1 then return end
    if health > 100 then health = 100 end
    maxhealthbars = 25
    local temp = ""
    for i = 1,(health/100)*maxhealthbars do
        temp = temp .. "|"
    end
    return temp
end

function ShadowedText(text, font, x, y, color, xalign, yalign)
   dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign)
   dr.SimpleText(text, font, x, y, color, xalign, yalign)
end

function DrawBarBg(x, y, w, h, col)
   local rx = math.Round(x - 4)
   local ry = math.Round(y - (h / 2)-4)
   local rw = math.Round(w + 9)
   local rh = math.Round(h + 8)

   local b = 8 --bordersize
   local bh = b / 2

   local role = LocalPlayer():GetRole() or ROLE_INNOCENT

   local c = col.bg

   -- Draw the colour tip
   surface.SetTexture(barcorner)

   surface.SetDrawColor(c.r, c.g, c.b, c.a)
   --surface.DrawTexturedRectRotated( rx + bh , ry + bh, b, b, 0 )
   --surface.DrawTexturedRectRotated( rx + bh , ry + rh -bh, b, b, 90 )
   --surface.DrawRect( rx, ry+b, b, rh-b*2 )
   surface.DrawRect( rx, ry, h, rh )

   -- Draw the remainder
   -- Could just draw a full roundedrect bg and overdraw it with the tip, but
   -- I don't have to do the hard work here anymore anyway
   c = col.bg
   surface.SetDrawColor(c.r, c.g, c.b, c.a)

   surface.DrawRect( rx+b+h-4, ry,  rw,  rh )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + rh - bh, b, b, 180 )
   --surface.DrawTexturedRectRotated( rx + rw - bh , ry + bh, b, b, 270 )
   --surface.DrawRect( rx+rw-b,  ry+b,  b,  rh-b*2 )

end

function GetAmmo(ply)
   local weap = ply:GetActiveWeapon()
   if not weap or not ply:Alive() then return -1 end

   local ammo_inv = weap:Ammo1() or 0
   local ammo_clip = weap:Clip1() or 0
   local ammo_max = weap.Primary.ClipSize or 0

   return ammo_clip, ammo_max, ammo_inv
end

hook.Add("ScoreboardShow", "sb_visible_true", function() sb_visible = true end)
hook.Add("ScoreboardHide", "sb_visible_false", function() sb_visible = false end)

end

Ok I forgot something :speechless: This is the code that makes the non custom HUD



if SERVER then

    local math = math
    util.AddNetworkString( "TTT_Radar_Hitman" )

    hitman_target_pool = {}
    hitman_targets = {}
    hitman_killed_targets = {}
    hitman_killed_civs = {}

    CreateConVar("hitman_punishment", 1)

    --Set up the initial tables and give each T a target
    function InitHitman()
        hitman_targets = {}
        hitman_killed_civs = {}
        for _, ply in pairs(GetTraitors()) do
            SetPlayerHitman(ply)
        end
    end
    hook.Add("TTTBeginRound", "InitHitman", InitHitman)

    --Create table with all living innocents
    function GetTargetPool()
        local hitman_target_pool = {}
        for _, ply in pairs(player.GetAll()) do
            if not ply:IsTraitor() and ply:Alive() and not ply:IsSpec() and not GetAssignedHitman(ply) then table.insert(hitman_target_pool, ply) end
        end
        return hitman_target_pool
    end

    --Select Target and inform player
    function SetTraitorTarget(traitor)
        if #GetTargetPool() > 0 then
            local pick = table.Random(GetTargetPool())
            hitman_targets[traitor:Nick()] = pick:Nick()
            umsg.Start("hitman_newtarget", traitor)
            umsg.String(pick:Nick())
            umsg.End()
        else
            hitman_targets[traitor:Nick()] = nil
            umsg.Start("hitman_notarget", traitor)
            umsg.End()
        end
    end


    --Needed for Death- and Disconnectevents
    function GetAssignedHitman(target_ply)
        for _, ply in pairs(GetTraitors()) do
            if hitman_targets[ply:Nick()] == target_ply:Nick() then
                return ply
            end
        end
    end
    --Clean pool, when a player dies or leaves
    local function CheckDeadPlayer(victim, weapon, killer)
        --Determining if a hitman needs to be punished
        if killer:IsPlayer() then
            if killer:Nick() != victim:Nick() and killer:IsTraitor() then
                if GetAssignedHitman(victim) then
                    if GetAssignedHitman(victim):Nick() == killer:Nick() then AwardHitman(killer)
                    else PunishHitman(killer)
                    end
                else PunishHitman(killer)
                end
            end
        end
        --Disabling the TargetText client-side
        ReassignTarget(victim)
    end
    hook.Add( "PlayerDeath", "CheckDeadPlayer", CheckDeadPlayer)

    local function CheckDisconnectedPlayer(ply)
        ReassignTarget(ply)
    end
    hook.Add("PlayerDisconnected", "CheckDisconnectedPlayer", CheckDisconnectedPlayer)

    function ReassignTarget(ply)
        --Add Target back to pool
        if ply:IsTraitor() then
            hitman_targets[ply:Nick()] = nil
            umsg.Start("hitman_notarget", ply)
            umsg.End()
            --Check if a Traitor is without a target
            local assigned = false
            for _, v in pairs(GetTraitors()) do
                if !assigned and v:Alive() and ply != v and not hitman_targets[v:Nick()] then
                    SetTraitorTarget(v)
                    assigned = true
                end
            end
        else
            if GetAssignedHitman(ply) then
                SetTraitorTarget(GetAssignedHitman(ply))
            end
        end
    end

    function AwardHitman(ply)
        SetKilledTargets(ply, 1 + hitman_killed_targets[ply:Nick()])
    end

    function PunishHitman(ply)
        SetKilledCivs(ply, 1 + hitman_killed_civs[ply:Nick()])

        if hitman_killed_targets[ply:Nick()] < hitman_killed_civs[ply:Nick()] then
            local punishment = GetConVar("hitman_punishment"):GetInt()
            if punishment == 1 then
                PunishReveal(ply)
            elseif punishment == 2 then
                ply:Kill()
            end
            umsg.Start("hitman_disappointed", ply)
            umsg.Short(punishment)
            umsg.End()
        end
    end

    function PunishReveal(ply)
        for _, v in pairs(player.GetAll()) do
            if v:Nick() ~= ply:Nick() then
                umsg.Start("hitman_reveal", v)
                umsg.String(ply:Nick())
                umsg.End()
            end
        end
    end

    function SetPlayerHitman(ply)
        SetTraitorTarget(ply)
        SetKilledCivs(ply, 0)
        SetKilledTargets(ply, 0)
        umsg.Start("hitman_hitman", ply)
        umsg.End()
    end

    function SetKilledCivs(ply, score)
        hitman_killed_civs[ply:Nick()] = score
        umsg.Start("hitman_killed_civs", ply)
        umsg.Short(score)
        umsg.End()
    end

    function SetKilledTargets(ply, score)
        hitman_killed_targets[ply:Nick()] = score
        umsg.Start("hitman_killed_targets", ply)
        umsg.Short(score)
        umsg.End()
    end

    function DisableAllTargets()
        umsg.Start("hitman_notarget")
        umsg.End()
    end
    hook.Add("TTTPrepareRound", "Reset1", DisableAllTargets)
    hook.Add("TTTEndRound", "Reset2", DisableAllTargets)
    --Sleeper Hitman Hook
    hook.Add("SleeperHitman", "onSleeper", function(ply) SetPlayerHitman(ply) end)

    --For Debugging Purposes, will be removed on release
    function PrintTargets()
        print("Targets")
        for _, ply in pairs(GetTraitors()) do
            if hitman_targets[ply:Nick()] then print(ply:Nick() .. " ; " .. hitman_targets[ply:Nick()]) end
        end
    end
    concommand.Add("hitman_print_targets", PrintTargets)

    function PrintPool()
        print("Potential Targets")
        for _, ply in pairs(GetTargetPool()) do
            print(ply:Nick())
        end
    end
    concommand.Add("hitman_print_pool", PrintPool)

    local chargetime = 30

    function RadarScan(ply, cmd, args)
       if IsValid(ply) and ply:IsTerror() then
          if ply:HasEquipmentItem(EQUIP_RADAR) then

             if ply.radar_charge > CurTime() then
                LANG.Msg(ply, "radar_charging")
                return
             end

             if ply:IsTraitor() then
                 chargetime = 1
             else
                 chargetime = 30
             end

             ply.radar_charge =  CurTime() + chargetime

             local scan_ents = player.GetAll()
             table.Add(scan_ents, ents.FindByClass("ttt_decoy"))

             local targets = {}
             for k, p in pairs(scan_ents) do
                if ply:IsTraitor() then
                    if GetAssignedHitman(p) != nil then
                       if GetAssignedHitman(p):Nick() != ply:Nick() then continue end
                    else continue
                    end
                end

                if ply == p or (not IsValid(p)) then continue end

                if p:IsPlayer() then
                   if not p:IsTerror() then continue end
                   if p:GetNWBool("disguised", false) and (not ply:IsTraitor()) then continue end
                end

                local pos = p:LocalToWorld(p:OBBCenter())

                -- Round off, easier to send and inaccuracy does not matter
                pos.x = math.Round(pos.x)
                pos.y = math.Round(pos.y)
                pos.z = math.Round(pos.z)

                local role = p:IsPlayer() and p:GetRole() or -1

                if not p:IsPlayer() then
                   -- Decoys appear as innocents for non-traitors
                   if not ply:IsTraitor() then
                      role = ROLE_INNOCENT
                   end
                elseif role != ROLE_INNOCENT and role != ply:GetRole() then
                   -- Detectives/Traitors can see who has their role, but not who
                   -- has the opposite role.
                   role = ROLE_INNOCENT
                end

                table.insert(targets, {role=role, pos=pos})
             end

             net.Start("TTT_Radar_Hitman")
                net.WriteUInt(#targets, 8)
                net.WriteBit(ply:IsTraitor())
                for k, tgt in pairs(targets) do
                   net.WriteUInt(tgt.role, 2)

                   net.WriteInt(tgt.pos.x, 32)
                   net.WriteInt(tgt.pos.y, 32)
                   net.WriteInt(tgt.pos.z, 32)
                end
             net.Send(ply)

          else
             LANG.Msg(ply, "radar_not_owned")
          end
       end
    end

    hook.Add("Initialize", "OverrideRadar", function() concommand.Add("ttt_radar_scan", RadarScan) end)

else -- Client

    hitman_targetname = ""
    hitman_targetkills = 0
    hitman_civkills = 0

    local revealed = false

    --for painting
    local x = 270
    local y = ScrH() - 130

    local w = 250
    local h = 120

    usermessage.Hook( "hitman_newtarget", function(um) hitman_targetname = um:ReadString() end)
    usermessage.Hook( "hitman_notarget", function(um) hitman_targetname = nil end)

    local function DisplayHitlistHUD()
        if hitman_targetname and LocalPlayer():Alive() and LocalPlayer():IsTraitor() then
            --basic box
            draw.RoundedBox(8, x, y, w, h, Color(0, 0, 10, 200))
            draw.RoundedBox(8, x, y, w, 30, Color(200, 25, 25, 200))

            --Didn't mind using BadKings ShadowedText. For some reason stuff doesn't properly import. Got to clean up the bloody code at some point anyway.
            -- 26th June 2015: Still haven't, should get my lazy ass to do it some day
            -- 18th October 2015: lmao I'll never do this part properly, will I? Well doesn't matter really, atleast the rest of the code gets de-garbaged

            --Target announcer
            draw.SimpleText(hitman_targetname, "TraitorState", x + 12, y+2, Color(0, 0, 0, 255))
            draw.SimpleText(hitman_targetname, "TraitorState", x + 10, y, Color(255, 255, 255, 255))
            --Stats
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", x + 12, y +42, Color(0, 0, 0, 255))
            draw.SimpleText("Killed Targets: " .. hitman_targetkills, "HealthAmmo", x + 10, y +40, Color(255, 255, 255, 255))

            draw.SimpleText("Killed Civilians: " .. hitman_civkills, "HealthAmmo", x + 12, y + 62, Color(0, 0, 0, 255))
            draw.SimpleText("Killed Civilians: " .. hitman_civkills, "HealthAmmo", x + 10, y + 60, Color(255, 255, 255, 255))
        end
    end
    hook.Add("HUDPaint", "DisplayHitlistHUD", DisplayHitlistHUD);
    --Fetch stats
    usermessage.Hook( "hitman_killed_targets", function(um) hitman_targetkills = um:ReadShort() end)
    usermessage.Hook( "hitman_killed_civs", function(um) hitman_civkills = um:ReadShort() end)

    local function SetTraitor(um)
        if um:ReadBool() then chat.AddText(Color(255, 0, 0), "You are a hitman, hired by a mysterious employer who wants a range of people dead. Avoid killing anyone other than the target or your employer will be ... unsatisfied.") end
        revealed = false
    end
    usermessage.Hook( "hitman_hitman", SetTraitor )

    local function Disappointed(um)
        local punishment = um:ReadShort()
        if punishment == 2 then
            chat.AddText(Color(255, 0, 0), "Your employer is very disappointed of your work and decided to activate the killswitch")
        elseif punishment == 1 and !revealed then
            chat.AddText(Color(255, 0, 0), "As a result of breaking the contract with your employer he decided to blow your cover with an anonymous phone call.")
        end
        revealed = true
    end
    usermessage.Hook( "hitman_disappointed", Disappointed )

    local function RevealHitman(um)
        chat.AddText(Color(0, 255, 0), "You receive a phonecall from an unknown number. As you accept the call you hear an old man saying: \"", Color(255, 0, 0), um:ReadString(), Color(0, 255, 0), " is a hired killer! Kill him before he has the chance to murder someone innocent!\" ")
    end
    usermessage.Hook( "hitman_reveal", RevealHitman )

    local function ReceiveRadarScan()
       local num_targets = net.ReadUInt(8)
       local hitmanscan = net.ReadBit() == 1

       if hitmanscan then
          RADAR.duration = 1
       else
          RADAR.duration = 30
       end

       RADAR.targets = {}
       for i=1, num_targets do
          local r = net.ReadUInt(2)

          local pos = Vector()
          pos.x = net.ReadInt(32)
          pos.y = net.ReadInt(32)
          pos.z = net.ReadInt(32)

          table.insert(RADAR.targets, {role=r, pos=pos})
       end

       RADAR.enable = true
       RADAR.endtime = CurTime() + RADAR.duration

       timer.Create("radartimeout", RADAR.duration + 1, 1,
                    function() RADAR:Timeout() end)
    end
    net.Receive("TTT_Radar_Hitman", ReceiveRadarScan)

end


I’m not sure how to make this HUD come up when the custom hud is set to 0, because right now when the custom hud is set to 0 no HUD shows at all.