• Am I using ScrH wrong?
    22 replies, posted
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. [CODE] 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 )[/CODE] [editline]9th September 2017[/editline] The code works perfectly.... for 1920 x 1080 only.
Can you take 2 screenshot with both resolutions?
[QUOTE=gonzalolog;52665828]Can you take 2 screenshot with both resolutions?[/QUOTE] Sure, 1 sec [editline]9th September 2017[/editline] Picture #1, 1280 x 720 [url]https://imgur.com/F3oDfET[/url] Picture #2 1920 x 1080 [url]https://imgur.com/MyWVqWA[/url]
[QUOTE=collin4lizard;52665829]Sure, 1 sec [editline]9th September 2017[/editline] Picture #1, 1280 x 720 [url]https://imgur.com/F3oDfET[/url] Picture #2 1920 x 1080 [url]https://imgur.com/MyWVqWA[/url][/QUOTE] You need to make the font and model panel size change too. Also instead of using two strings for each line just use one.
[QUOTE=Kevlon;52665855]You need to make the font and model panel size change too.[/QUOTE] How do I change font size in this code: [CODE] surface.CreateFont( "HUDFont", { font = "Lucida Console", size = 20, weight = 700 } ) surface.CreateFont( "AmmoFont", { font = "Lucida Console", size = 40, weight = 700 } ) [/CODE] I can't change size = 40 to ScrH can I?
[QUOTE=collin4lizard;52665861]How do I change font size in this code: [CODE] surface.CreateFont( "HUDFont", { font = "Lucida Console", size = 20, weight = 700 } ) surface.CreateFont( "AmmoFont", { font = "Lucida Console", size = 40, weight = 700 } ) [/CODE] I can't change size = 40 to ScrH can I?[/QUOTE] Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScreenScale]ScreenScale[/url]
And, the model size uses ScrH and ScrW too. [CODE] 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) [/CODE]
You are not scaling it size, only position
[QUOTE=gonzalolog;52665885]You are not scaling it size, only position[/QUOTE] [CODE] playerModel:SetSize( 150, 150 ) [/CODE] Ahh I see When I do, [CODE] surface.CreateFont( "HUDFont", { font = "Lucida Console", ScreenScale( 20 ), weight = 700 } ) surface.CreateFont( "AmmoFont", { font = "Lucida Console", ScreenScale( 40 ), weight = 700 } ) [/CODE] The text stays really small no matter what number I input.
[QUOTE=collin4lizard;52665887][CODE] playerModel:SetSize( 150, 150 ) [/CODE] Ahh I see When I do, [CODE] surface.CreateFont( "HUDFont", { font = "Lucida Console", ScreenScale( 20 ), weight = 700 } ) surface.CreateFont( "AmmoFont", { font = "Lucida Console", ScreenScale( 40 ), weight = 700 } ) [/CODE] The text stays really small no matter what number I input.[/QUOTE] Then make the number bigger Also use the draw library instead
[QUOTE=Kevlon;52665905]Then make the number bigger[/QUOTE] I made it 400 and it didn't change. [editline]9th September 2017[/editline] [QUOTE=Kevlon;52665905] Also use the draw library instead[/QUOTE] Is there any benefits to draw library vs what I'm using?
[QUOTE=Kevlon;52665905]Also use the draw library instead[/QUOTE] [QUOTE=collin4lizard;52665907]Is there any benefits to draw library vs what I'm using?[/QUOTE] [URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/modules/draw.lua#L62-L100"]The draw library uses the surface library internally.[/URL] 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.
[QUOTE=MPan1;52665914]The draw library uses the surface library internally. Using the surface library directly is faster, but looks more complicated[/QUOTE] 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: [CODE] surface.SetTextPos( ScrH() * 0.28, ScrW() * 0.03 ) -- this is in the wrong order [/CODE] 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.
[QUOTE=MPan1;52665947]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: [CODE] surface.SetTextPos( ScrH() * 0.28, ScrW() * 0.03 ) -- this is in the wrong order [/CODE] 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.[/QUOTE] 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.
[QUOTE=MPan1;52665978]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. [/QUOTE] I'll restart my game now [editline]9th September 2017[/editline] Nothing changed.
Wait, sorry, my mistake. The problem is this: [QUOTE] surface.CreateFont( "HUDFont", { font = "Lucida Console", ScreenScale( 20 ), weight = 700 } ) surface.CreateFont( "AmmoFont", { font = "Lucida Console", ScreenScale( 40 ), weight = 700 } ) [/QUOTE] The ScreenScale bit needs to be equal to the font size. [QUOTE] surface.CreateFont( "HUDFont", { font = "Lucida Console", [B]size = [/B]ScreenScale( 20 ), weight = 700 } ) surface.CreateFont( "AmmoFont", { font = "Lucida Console", [B]size = [/B]ScreenScale( 40 ), weight = 700 } ) [/QUOTE]
[QUOTE=MPan1;52665987]Wait, sorry, my mistake. The problem is this: The ScreenScale bit needs to be equal to the font size.[/QUOTE] 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. [CODE] 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 .. "\n" .. money .. "\n" .. salary .. "\n" .. 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 ) [/CODE] Now you only need 2 coordinates to position it.
[QUOTE=MPan1;52666004]By the way, I made your whole HUD into 2 DrawText calls. [CODE] 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 .. "\n" .. money .. "\n" .. salary .. "\n" .. 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 ) [/CODE] Now you only need 2 coordinates to position it.[/QUOTE] Thank you but, are you that bored?
yes
It also isn't that hard to do either. Keep up learning, the more info you can absorb when your fresh will get rid of any bad habits
Sorry, you need to Log In to post a reply to this thread.