I am creating a gamemode for learning purposes, and I have started working on the HUD. I just have a question about the HUDShouldDraw hook. My code is currently working, but I would just like an explanation:
(Current working code)
local hideHUD = {
["CHudHealth"] = true,
["CHudBattery"] = true,
["CHudAmmo"] = true,
["CHudSecondaryAmmo"] = true
}
-- Hooks --
function GM:HUDShouldDraw(name)
if (hideHUD[name]) then
return false
else
return self.BaseClass.HUDShouldDraw(self, name)
end
end
function GM:HUDPaint()
DrawHUD()
end
If I take out this:
else
return self.BaseClass.HUDShouldDraw(self, name)
The HUD no longer displays. However, if I use hook.Add for HUDShouldDraw (which I read you shouldn't do for gamemodes), I don't need that last else part. Could someone explain why this is and what that last part does exactly?
If you use GM: to add hooks you override the base gamemodes function for that, which probably enables the HUD. when you do the base class thing, you explicitly call the base gamemodes function, thus restoring the original.
Thanks for that, the first question makes more sense. For the second, I understand that ply is just a variable, at the top of the file I defined local ply = LocalPlayer(). Why does using ply return Alive as nil though, even if I defined ply?
You can't use LocalPlayer before GM/InitPostEntity, it even notes this on its wiki page.
Ohhhh that makes sense. Thank you!
Sorry, you need to Log In to post a reply to this thread.