Custom Gamemode - Not Hiding Default HUD

So I fixed the default HUD elements not being hidden. However, I have no clue why adding things to the HUD isn’t working. The following is the code I have.



--
-- Take all of the default HUD elements below and hide them.
--
local HiddenElements = {
	CHudHealth,
	CHudBattery,
	CHudSuitPower
}

function GM:HUDShouldDraw(name)
	for k, v in pairs(HiddenElements) do
		if (name == v) then
			return false
		end
	end
end

--
-- Add custom things to the HUD.
--
local function DrawHUD()
	surface.SetDrawColor(255, 255, 255, 255)
	surface.DrawRect(0, 0, ScrW(), 25)
end

function GM:HUDPaint()	
	DrawHUD()
end


There is absolutely nothing on my HUD, except for the default elements I did not hide. I’ve already tried hook.Add. However, I have no clue what I’m doing wrong. Can someone help me?

Rather than overriding the functions entirely, try using hooks, e.g.



function GM:HUDPaint()	
	DrawHUD()
end


Could be something like



hook.Add( 'HUDPaint', 'DrawMyHUD', DrawHUD )


[editline]1st May 2016[/editline]

Try this code:



--
-- Take all of the default HUD elements below and hide them.
--
local HiddenElements = {
	['CHudHealth'] = true,
	['CHudBattery'] = true,
	['CHudSuitPower'] = true
}

hook.Add( 'HUDShouldDraw', 'NoDrawStuff', function(name)
	if HiddenElements[name] then return false end
end)

--
-- Add custom things to the HUD.
--
local function DrawHUD()
	surface.SetDrawColor(255, 255, 255, 255)
	surface.DrawRect(0, 0, ScrW(), 25)
end

hook.Add( 'HUDPaint', 'DrawMyHUD', DrawHUD )


Not sure if it’d work or not, but it’s a bit better than overriding the base function

[editline]1st May 2016[/editline]

Wait, didn’t notice you said it was a custom gamemode… goddamn it… well, I don’t really know the problem then :frowning:

Yeah, I’m so confused. There’s no errors being displayed at all.

(Off-Topic)

Aren’t you the alternative account of “Percipience”

This is an extremely long shot, but try adding



surface.SetAlphaMultiplier( 1 )


To the top of your code… maybe the problem could be that some other addon is setting the alpha to 0?

I’ll be honest, yes. I created this account yesterday. I do not want anything to do with that account. I have a bad reputation on that account, as well as the fact that I do not want to be known as “Percipience”. I made the account a while back.

[editline]30th April 2016[/editline]

Nope, didn’t work. I have no clue what’s going on here.

I have no addons, by the way.

Try using the code I posted before - I just tested it and it seems to work for me

It does work. I really appreciate it, mate. I was a little confused before. I have the code below.



--
-- Take all of the default HUD elements below and hide them.
--
local HiddenElements = {
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudSuitPower"] = true
}

local function HideHUD(name)
	if (HiddenElements[name]) then return false end
end
hook.Add("HUDShouldDraw", "HideHUD", HideHUD)

--
-- Add custom things to the HUD.
--
local function DrawHUD()
	surface.SetDrawColor(40, 40, 40, 200)
	surface.DrawRect(0, 0, ScrW(), 25)
end
hook.Add("HUDPaint", "DrawMyHUD", DrawHUD)