Am I using ScrH wrong?

So I’v been working on my hud and someone helped me yesterday with part of it but, I have my text in place with ScrH and ScrW but when I change resolutions to test, it gets all jumbled up. Basically it doesn’t scale to the resolution. I’m wondering if I’m using it wrong and if so how do I use it.


 
hook.Add( "HUDPaint", "drawsometext", function()
	surface.SetFont( "HUDFont" )
	surface.SetTextColor( 255, 216, 68, 255 )


	surface.SetTextPos( ScrH() * 0.28, ScrW() * 0.03 )
        local playerNick = LocalPlayer():Nick()
        surface.DrawText( playerNick )
        surface.SetTextPos( ScrH() * 0.2, ScrW() * 0.03)
	surface.DrawText( "Name:" )


	surface.SetTextPos( ScrH() * 0.28, ScrW() * 0.05 )
        local playerMoney = LocalPlayer():getDarkRPVar( "money" )
        surface.DrawText( DarkRP.formatMoney( playerMoney ) )
        surface.SetTextPos( ScrH() * 0.2, ScrW() * 0.05)
	surface.DrawText( "Money:" )
        
        surface.SetTextPos( ScrH() * 0.29, ScrW() * 0.07 )
        local playerSalary = LocalPlayer():getDarkRPVar( "salary" )
        surface.DrawText( DarkRP.formatMoney( playerSalary ) )
        surface.SetTextPos( ScrH() * 0.2, ScrW() * 0.07)
	surface.DrawText( "Salary:" )

        surface.SetTextPos( ScrH() * 0.26, ScrW() * 0.09 )
        local playerTeam = team.GetName( LocalPlayer():Team() )
        surface.DrawText( playerTeam ) 
        surface.SetTextPos( ScrH() * 0.2, ScrW() * 0.09)
	    surface.DrawText( "Job:" )
        
      if (LocalPlayer():GetActiveWeapon():Clip1() != -1) then

         surface.SetFont( "AmmoFont" )
         surface.SetTextPos( ScrH() * 1.28, ScrW() * 0.52)
         surface.SetTextColor( 190, 194, 68, 255 ) 
         surface.DrawText(LocalPlayer():GetActiveWeapon():Clip1() .. "/" .. LocalPlayer():GetAmmoCount (LocalPlayer():GetActiveWeapon(): GetPrimaryAmmoType()))

      end
        

end )

[editline]9th September 2017[/editline]

The code works perfectly… for 1920 x 1080 only.

Can you take 2 screenshot with both resolutions?

Sure, 1 sec

[editline]9th September 2017[/editline]

Picture #1, 1280 x 720 https://imgur.com/F3oDfET

Picture #2 1920 x 1080 https://imgur.com/MyWVqWA

You need to make the font and model panel size change too.

Also instead of using two strings for each line just use one.

How do I change font size in this code:



surface.CreateFont( "HUDFont", { font = "Lucida Console", size = 20, weight = 700 } )
surface.CreateFont( "AmmoFont", { font = "Lucida Console", size = 40, weight = 700 } )


I can’t change size = 40 to ScrH can I?

Use

ScreenScale

And, the model size uses ScrH and ScrW too.


 
hook.Add( "HUDPaint", "playerModel", function()
  local ply = LocalPlayer()
  local model = ply:GetModel()

  if !IsValid( ply ) then return end

  if !playerModel || !ispanel( playerModel ) then
    playerModel = vgui.Create( "DModelPanel" )
    playerModel:SetSize( 150, 150 )
    playerModel:SetPos( ScrH() * 0.03, ScrW() * 0.02 )
    playerModel:SetModel( model )
    playerModel.Model = model
    function playerModel:LayoutEntity( Entity ) return end
  end

  local headpos = playerModel.Entity:GetBonePosition( playerModel.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) )
    playerModel:SetLookAt( headpos )
    playerModel:SetCamPos( headpos-Vector( -15, 5, 0 ) )
    playerModel.Entity:SetEyeTarget( headpos-Vector( -15, 0, 0 ) )

  if ply:GetModel() != playerModel.Model then
    playerModel:SetModel( model )
    playerModel.Model = model
  end
end)


You are not scaling it size, only position


  playerModel:SetSize( 150, 150 ) 

Ahh I see

When I do,


 
surface.CreateFont( "HUDFont", { font = "Lucida Console", ScreenScale( 20 ), weight = 700 } )
surface.CreateFont( "AmmoFont", { font = "Lucida Console", ScreenScale( 40 ), weight = 700 } )


The text stays really small no matter what number I input.

Then make the number bigger

Also use the draw library instead

I made it 400 and it didn’t change.

[editline]9th September 2017[/editline]

Is there any benefits to draw library vs what I’m using?

The draw library uses the surface library internally.
Using the surface library directly (as you are) is a little bit faster, but it makes the code look complicated.
The surface library takes a lot of code to align text, so I’m starting to use it for text alignment.

I’d rather stick with what I have so I don’t need to re write everything I’ve done thus far.

I think the problem is you’re using the screen height first and the screen width second, when it should be the other way round:



surface.SetTextPos( ScrH() * 0.28, ScrW() * 0.03 ) -- this is in the wrong order


You have to use ScrW() for the X coordinate and ScrH() for the Y coordinate.

You’ll probably have to recalculate the percentages now, but it should scale properly.

I’ll switch them all around tomorrow but in the meantime, does anyone have a clue why the text stays small?

I think the text size issue might be because you already created the font before.
Maybe if you restart the game it’ll reset the font, so then you can set it to something bigger.

I’ll restart my game now

[editline]9th September 2017[/editline]

Nothing changed.

Wait, sorry, my mistake. The problem is this:

The ScreenScale bit needs to be equal to the font size.

Well, I was GOING to test it but my severs control panel went full retard on me.

By the way, I made your whole HUD into 2 DrawText calls.



surface.CreateFont( "HUDFont", { font = "Lucida Console", size = ScreenScale( 20 ), weight = 700 } )
surface.CreateFont( "AmmoFont", { font = "Lucida Console", size = ScreenScale( 40 ), weight = 700 } )

hook.Add( "HUDPaint", "DrawSomeText", function()

	local name = "Name: " .. LocalPlayer():Nick()
	local money = "Money: " .. DarkRP.formatMoney( LocalPlayer():getDarkRPVar( "money" ) )
	local salary = "Salary: " .. DarkRP.formatMoney( LocalPlayer():getDarkRPVar( "salary" ) )
	local job = "Job: " .. team.GetName( LocalPlayer():Team() )
	local str = name .. "
" .. money .. "
" .. salary .. "
" .. job
	draw.DrawText( str, "HUDFont", ScrH() * 0.2, ScrW() * 0.03, Color( 255, 216, 68 ) )

	if LocalPlayer():GetActiveWeapon():Clip1() != -1 then
		local ammo = LocalPlayer():GetActiveWeapon():Clip1() .. "/" .. LocalPlayer():GetAmmoCount( LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType() )
		draw.SimpleText( ammo, "AmmoFont", ScrH() * 1.28, ScrW() * 0.52, Color( 190, 194, 68 ) )
	end

end )


Now you only need 2 coordinates to position it.