Pivity

SizetoContents()

Last read Never
#1

So, the creator of mhEssentials hasn't responded to my ticket since April, never responded to me. I was wondering you I could get the HUD to be SizeToContents instead of a set size. Here is an example:

local function drawSection( icon, name )

if ( !mats[ icon ] ) then

mats[ icon ] = Material( icon )

end


surface.SetDrawColor( 255, 255, 255 )

surface.SetMaterial( mats[ icon ] )

surface.DrawTexturedRect( position_x + 1, position_y + 1, 16, 16 )


draw.RoundedBox( 0, position_x + 0, position_y, 394, 19, black )

draw.SimpleText( name, "TargetID", position_x + 27, position_y + 1, color_white )


surface.SetDrawColor( black )

surface.DrawOutlinedRect( position_x + 0, position_y, 394, 19 )


position_y = position_y + 25

end

It's set to the size 394 wide & 19 high. I want it to just fit the contents. For example, if my job was 'Citizen' the bar would be the correct size to fit it in. But if I set my job title to 'Extra long job title xd' the bar would extend its width to fit the text.

#2

http://wiki.garrysmod.com/page/surface/GetTextSize

Winner x 2
#3
ByZERO SUGARat 8th of September 2018 20:24:30
http://wiki.garrysmod.com/page/surface/GetTextSize

[ERROR] addons/exodushud/lua/autorun/hud.lua:89: bad argument #1 to 'GetTextSize' (string expected, got nil)

  1. GetTextSize - [C]:-1
  2. drawSection - addons/exodushud/lua/autorun/hud.lua:89 3. v - addons/exodushud/lua/autorun/hud.lua:728 4. unknown - lua/includes/modules/hook.lua:84
draw.SimpleText( name, "TargetID", position_x + 27, position_y + 1, color_white )

draw.RoundedBox( 0, position_x + 0, position_y, surface.GetTextSize( job ), black )

Optimistic x 1
#4

are you even reading what you're sending us

fucking hell

Dumb x 3Funny x 2
#5
By[L²:RP] Vimptoat 9th of September 2018 14:53:41
[ERROR] addons/exodushud/lua/autorun/hud.lua:89: bad argument #1 to 'GetTextSize' (string expected, got nil)GetTextSize - [C]:-1drawSection - addons/exodushud/lua/autorun/hud.lua:893. v - addons/exodushud/lua/autorun/hud.lua:7284. unknown - lua/includes/modules/hook.lua:84draw.SimpleText( name, "TargetID", position_x + 27, position_y + 1, color_white ) draw.RoundedBox( 0, position_x + 0, position_y, surface.GetTextSize( job ), black )
  1. witty is your job variable nil? first deal with that, gettextsize doesnt work with ill input its even telling you that it expect string but you giev it nil
  2. surface.GetTextSize returns 2 values, you give it string input and it spits back the width and height of the text while taking into consideration last font that you set with surface.SetFont this function is in draw.SimpleText so you should be fine IF your job string is displayed with the same font you were drawing the name because you just set it with drawsimpletext while otherwise youd need to first add surface.SetFont("yourfont") and then adding local textW,textH = surface.GetTextSize( job ) before draw rounded box. then just replace your box width attempt with textW and it should be fine
draw.SimpleText( name, "TargetID", position_x + 27, position_y + 1, color_white )
surface.SetFont("yourfont") -- if your job font is different then "TargetID" otherwise omit this line
local textW,textH = surface.GetTextSize( job )

draw.RoundedBox( 0,position_x + 0, position_y, textW,textH,black )

Winner x 2
#6

I believe the call for job name in DarkRP is "LocalPlayer():getDarkRPVar("job")" if that helps any.

Friendly x 1
#7

Basically to be sure it works on any gamemode you can also use team.GetName(LocalPlayer():Team()).

Winner x 1Friendly x 1
Users viewing this thread
Nobody