Need help with my DarkRP HUD

Hello!

So I am currently making a HUD for my server. I have a box and inside that box is the persons name. And I was wondering on how I would make it so that the box is the same length as the persons same, and if they change their name it changed the length of the box so it fits the name.

Kind Regards

  • Riley

surface.GetTextSize

Could someone write out a code? I am fairly new to Lua and I just need some help to get me started.

There’s about 5 of them on the wiki.

Or you could try

draw.WordBox



surface.SetFont( "Trebuchet24" )

local message = "Hello World"
local width, height = surface.GetTextSize( message )

print( "Text width: " .. width .. ", text height: " .. height )


You would put the “name” string into the surface.GetTextSize function. This will return the width and height of the text from the font you use (your font is probably already set if your writing text though). Use these values to determine box size.

-Pro tip, store the screen width/height in variables ( ScrW() , ScrH() ), then also create another variable named something like “screenMin”. Set “screenMin” to whatever screen length is lowest, and use this to construct all your hud elements…just so your hud always looks nice on different resolutions. I then create box’s and such using values like screenMin*0.2

Cheers to all the people that helped. Thanks!