HUD halp

Hello, newb at lua here
I have tried adding a custom font to my gamemode. It’s placed in garrysmod/resource/fonts
Link to the font: http://www.4shared.com/zip/a0SvLuci/Crysis_Font.htm

the font’s file name is CRYSISB.ttf

function HUDHide( myhud )
	for k, v in pairs{"ChudHealth","CHudBattery"} do
		if myhud == v then return false end
	end
end
hook.Add("HUDShouldDraw","HUDHide",HUDHide)

function GM:HUDPaint()
	self.BaseClass:HUDPaint()
	local ply = LocalPlayer()
	local wep = LocalPlayer():GetActiveWeapon()
	local HP  = LocalPlayer():Health()
	local ARM = LocalPlayer():Armor()
	local AMMO = LocalPlayer():GetAmmoCount( wep:Clip1())
	
	//Health below
	
	surface.CreateFont( "Crysis",
					{
					font	= "CRYSISB",
					size	= 25,
					weight	= 400,
					antialias = true,
					shadow = true
			})
	surface.SetTextColor( 20, 180, 50, 255)
	surface.SetTextPos( 20, 20 )
	surface.SetFont( "Crysis" )
	surface.DrawText( "Health: "..HP)
	

end

Thanks

edit: Even putting this, it shows no difference in-game then when I put ScoreboardText in for CRYSISB. The “Health:” is the same font


(User was banned for this post ("Undescriptive thread title" - Gran PC))

I’m not sure of the issue, as I never use custom fonts, but let me just tell you: take out surface.CreateFont from HUDPaint. Your FPS is going to plummet, and it doesn’t need to be there.

But isn’t that what makes the font in the first place? Again ,lua nub here

Make sure your font type is a .ttf

Another note, fonts have to be an even number so instead of 25 try 24

You’re creating the font everytime the HUD is drawn, just put it outside of the HUDPaint hook and it should be fine. Have you put a resource folder in your gamemode/content folder? That could be the problem.

surface.CreateFont takes the name of the font, not the name of the file.
This should work:


surface.CreateFont( "CrysisHUDFont", {
	font 		= "Crysis"
        //Stuff
} )

[lua]function HUDHide( myhud )
for k, v in pairs{“ChudHealth”,“CHudBattery”} do
if myhud == v then return false end
end
end
hook.Add(“HUDShouldDraw”,“HUDHide”,HUDHide)

function GM:Initalize()
surface.CreateFont( “Crysis”,
{
font = “CRYSISB”,
size = 24,
weight = 400,
antialias = true,
shadow = true
})
end

function GM:HUDPaint()
self.BaseClass:HUDPaint()
local ply = LocalPlayer()
local wep = LocalPlayer():GetActiveWeapon()
local HP = LocalPlayer():Health()
local ARM = LocalPlayer():Armor()
local AMMO = LocalPlayer():GetAmmoCount( wep:Clip1())

surface.SetTextColor( 20, 180, 50, 255)
surface.SetTextPos( 20, 20 )
surface.SetFont( "Crysis" )
surface.DrawText( "Health: "..HP)

end[/lua]

I have not made a resource folder in my gamemode folder as this is my first gamemode. It’s a learning experience. I will test the code later when I am home. Thanks!

Bump, I get this:

[ERROR] gamemodes/tutorialgamemode/gamemode/cl_init.lua:39: 'Crysis' isn't a valid font

  1. SetFont - [C]:-1
   2. unknown - gamemodes/tutorialgamemode/gamemode/cl_init.lua:39

I have made a resource folder and it still doesn’t work.

TutorialGamemode/content/resource/CRYSISB.ttf

Move the surface.CreateFont out of the Initialize hook.