Font into a gamemode?

Hey guys, Stupid question but Im making a gamemode but do not know how to add a font to the gamemode, Any ideas? Thanks

  1. Create “content” folder in your gamemode’s directory (gamemodes/MyGM).
  2. Create “resource” in it.
  3. Create “fonts” in this.
  4. Place your font file (e.g. “webdings.ttf”) in “fonts”.
  5. Don’t forget to create surface equivalent:

surface.CreateFont("Webdings", {font = "webdings", size = 20})

Thankyou so much <3, Will you marry me?

[editline]20th February 2015[/editline]

This did not acctually work


surface.CreateFont("VisleRPFontNot", {
	font = "vislerp", 
	size = 13, 
	weight = 500, 
	blursize = 0, 
	scanlines = 0, 
	antialias = true, 
	underline = false, 
	italic = false, 
	strikeout = false, 
	symbol = false, 
	rotary = false, 
	shadow = false, 
	additive = false, 
	outline = false, 
})

When ever I use the font it is just the defualt font :frowning: You know why?

If i recall, you have to call resource.AddFile or something to do with that.

I cant remember the library

Hmm, I tought just adding it to fastDL would work, Got any infomation on how I would do that?

As I said, i cant remeber much, But I know you have to load the font first, before you remake it with surface.CreateFont

I could be wrong.

I Will look it up but does anyone else have any suggestions?

OK, try to add resource, as Exploderguy suggested:


resource.AddSingleFile("gamemodes/MyGM/content/resource/fonts/vislerp.ttf")

It’s a shared method. So, you’re making gamemode - you needed to do it serverside to force resource to be loaded to client.

Could I just do this in the sever side file of my gamemode?

[editline]20th February 2015[/editline]

Edit-

Did not work, Still using the defualt dont and I dont know why :suicide:

Make sure you have typed right name of font. It works like a sharm for me also without resource.Add*.
E.g.:


surface.CreateFont("MyFont", {font = "SplinterWood", size = 24})

File “SplinterWood.ttf” is situated in gamemodes/MyGM/content/resource/fonts, works fine.

Hm… Yep, it’s very strange. :pwn:

The font name is correct, COuld you double type the name of the content folder directory, But imsure everything is right

[editline]20th February 2015[/editline]

I Have restarted multiple times, Here is the code I used to draw it


			draw.DrawText(v.text,"VisleRPFontNot",((ScrW()-28)-size)+v.localXPos,pos+10,Color(200,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_CENTER)


The font creation code


surface.CreateFont("VisleRPFontNot", {
	font = "vislerp", 
	size = 13, 
})

And directory of the font


"gamemodes/vislrp/content/resource/fonts"

oop… (wrong answer)

Yeh i know, But its correct, Trust me, i copy and pasted the font name

Can you please share your gamemode?

Which part, Or all of it?

This is the part that acctually draws the text(Ignor the messy code, Its mainly just proto


local _notifications = {}

local _types = {"error","info","other"}

surface.CreateFont("VisleRPFontNot", {
	font = "vislerp", 
	size = 13, 
})

local erroricon = Material( "icon16/exclamation.png", "smooth" )
local infoicon = Material( "icon16/star.png", "smooth" )
local othericon = Material( "icon16/check_on.png", "smooth" )

local _icons = {erroricon,infoicon,othericon}

local function drawNotifications()

	if(table.Count(_notifications)>0) then
		
		local pos = ScrH()-( ScrH()/4)

		for k,v in pairs(table.Reverse(_notifications)) do
			
			surface.SetFont("Default")
			local size = surface.GetTextSize(v.text)

			if(v.isRemoving==true) then
				
				v.localXPos = v.localXPos+(150*FrameTime())

			elseif(v.isEntering==true)then
				
				v.localXPos = v.localXPos - (600*FrameTime())

				if(v.localXPos<0)then
					v.localXPos=0
					v.isEntering = false
				end

			end

			draw.RoundedBox(0,((ScrW()-50)-size)+v.localXPos,pos,size+40,40,Color(0,0,0,120))
			draw.RoundedBox(0,((ScrW()-48)-size)+v.localXPos,pos+2,size+36,36,Color(40,40,40,120))
			draw.DrawText(v.text,"VisleRPFontNot",((ScrW()-28)-size)+v.localXPos,pos+10,Color(200,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_CENTER)

			print(tostring(v.icon))

			surface.SetDrawColor(Color(255,255,255,255))
			surface.SetMaterial( v.icon )
			surface.DrawTexturedRect(((ScrW()-45)-size)+v.localXPos,(pos+10),16,16);

			pos = pos - 45

		end

	end

end

-EDIT–

I Just saw what I did, Im a dumbass, Slap me silly with all them dumbs, But thanks for you help

The name of the font is in the black circle.

I do this in my init.lua file for my gamemodes:

resource.AddFile(“resource/fonts/customfontname.ttf”)

I think you’re trying to give the full directory of the gamemode resource when it’s already by default getting content from the gamemode; in other words you’re making it go to a directory that doesn’t exist.

I could be wrong but I’m fairly certain I’m not because the above method works fine for me on both my client and on my servers.

It’s not the name of the file that matters, it’s the actual name of the font in font viewer.

No I was replying to the guy who was pointing out a different name within the custom font structure not your reply; I was making my reply when you made yours haha.

[lua]
surface.CreateFont(“VisleRPFontNot”, {
font = “vislerp”,
size = 13,
})
[/lua]
Will look for a font with the name “vislerp”. However this:
[lua]
surface.CreateFont(“VisleRPFontNot”, {
font = “Roboto Cn”,
size = 13,
})
[/lua]
Will load roboto from your fonts folder.

[editline]20th February 2015[/editline]

Oh, lol