• Make two text move together.
    10 replies, posted
Hey guys, so i'm creating a hud, and i have some problem with the text. So, I am using to fonts, a big one and a small one. One for the name, and on for the job. They are in the same line like this. "ZorexD / Mayor" but, if the name is shorther, like "fag / Mayor" it stays in the same spot. I tried making both of the texts in the same text display string, but i need two different fonts for it. same as the money and the salary. Any help would be appreciated!
surface.SetFont surface.GetTextSize
?
DaWhalee means that you can get the width of the name and offset the job accordingly. (the width and the height are also returned from function draw.SimpleText() ) Something like this. https://files.facepunch.com/forum/upload/469093/4ce5a9c1-b549-4075-a4ae-2090d6c2b21c/hl2_2ba0lBa53s.jpg https://files.facepunch.com/forum/upload/469093/53eb19c8-ff4a-498e-a829-df66252861df/hl2_WZMv3nd6Gd.jpg
Could you tell me how do I use these commands?
To use surface.GetTextSize() you must set the font you need with surface.SetFont(). After that surface.GetTextSize() returns a vararg so you make something like that: local w, h = surface.GetTextSize(LocalPlayer():getDarkRPVar("rpname")) w - width h - height (NOTE: draw.SimpleText() returns the vararg by itself, so no need to use any other surface functions) So now you just add the name width to X coordinate of the job. Thats all.
    hook.Add( "HUDPaint", "HUDPaint_DrawABox", function() surface.SetTextColor( 255, 255, 255 ) -- Set text color surface.SetTextPos( 81, 955 ) -- Set text position, top left corner surface.SetFont( "1" ) -- Set the font surface.DrawText(client:Nick().." /") -- Draw the text     end )     local w, h = surface.GetTextSize(client:Nick()) draw.SimpleText(client:getDarkRPVar("job") or nil , "2", w+ 10,955,Color( 255,255,255,255),0) I tried this and it doesnt really work. did I do it right?     
Why did you move the job text out of hudpaint? Also as i told you can just get the text width and height from draw.SimpleText(), but hey that's just personal preference.
Should that be good?     local playername = LocalPlayer():Nick()     local w, h = surface.GetTextSize(playername)     hook.Add( "HUDPaint", "HUDPaint_DrawABox", function() surface.SetTextColor( 255, 255, 255 ) -- Set text color surface.SetTextPos( 81, 955 ) -- Set text position, top left corner surface.SetFont( "1" ) -- Set the font surface.DrawText(playername.." /") -- Draw the text draw.SimpleText(client:getDarkRPVar("job") or nil , "2", 81 + w + 10,957,Color( 255,255,255,255),0)     end )
Place local w, h after surface.SetFont and instead just playername give the function playername.. " /".
Okay now, thank you so much bro, I appreciate that so much! <3
Sorry, you need to Log In to post a reply to this thread.