Hi, bassically i'm trying to make players usernames fit on my hud by changing the font to a smaller font if their name is over 20 characters. This is what i have so far but it isn't working. Could somebody fix please and tell me why it isn't working. Thanks in advance.
[code]
surface.CreateFont( "name", {
font = "Trebuchet24",
size = 48,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
} )
local PlayerName = LocalPlayer():Nick()
local PlayerNameSize = surface.GetTextSize(PlayerName)
if PlayerNameSize > 20 then
font = "Trebuchet24"
draw.DrawText( " "..PlayerName, font, 0 + 10, ScrH() - 75, Color(255, 255, 255, 255))
else
font = "name"
end
[/code]
you have to set a font for surface.GetTextSize to work correctly, but if you're only looking for character width, then you don't have to use surface.GetTextSize at all
[code]
local PlayerName = LocalPlayer():Nick()
local font = "Trebuchet24"
if #PlayerName > 20 then
font = "name"
end
draw.DrawText(PlayerName, font, 0 + 10, ScrH() - 75, Color(255, 255, 255, 255))
[/code]
Didn't you ask basicly the same question [URL="http://facepunch.com/showthread.php?t=1430479"]here[/URL] and someone showed you how to do it.
Sorry, you need to Log In to post a reply to this thread.