General > Developers Corner

Player Info fixed position

(1/1)

Suicidal Dog:
I am having an issue with my HUD I am trying to make the player info like name and health and other stuff

I can't seem to find a fix for the position of the bars on the side of the player, example:



Changes position depending on distance.



Heres the code of the DrawPlayerInfo()

--- Code: ---local function DrawPlayerInfo(ply)
local pos = ply:EyePos()

pos.z = pos.z -- The position we want is a bit above the position of the eyes
pos = pos:ToScreen()
pos.y = pos.y - 50 -- Move the text up a few pixels to compensate for the height of the text

local playername = ply:Nick()



if GAMEMODE.Config.showname and not ply:getDarkRPVar("wanted") then

local width, height = surface.GetTextSize( ply:Nick() )

draw.RoundedBox( 0, pos.x + 150, pos.y + 150, 300, 34, Color( 0, 0, 0, 200 ))
draw.RoundedBox( 0, pos.x + 145, pos.y + 150, 5, 34, team.GetColor( ply:Team() ))
surface.SetTextPos( pos.x + 155, pos.y + 153)
surface.SetFont( "open_sans_25b" )
surface.DrawText( playername )


surface.SetDrawColor( team.GetColor( ply:Team() ))
surface.DrawLine( pos.x + 150, pos.y + 153, pos.x + 446, pos.y + 153 )
surface.DrawLine( pos.x + 446, pos.y + 153, pos.x + 446, pos.y + 180 )
surface.DrawLine( pos.x + 446, pos.y + 180, pos.x + 150, pos.y + 180 )
end

if GAMEMODE.Config.showhealth and not ply:getDarkRPVar("wanted") then
draw.RoundedBox( 0, pos.x + 150, pos.y + 194, 150, 40, Color( 0, 0, 0, 200))
draw.RoundedBox( 0, pos.x + 145, pos.y + 194, 5, 40, Color( 200, 50, 50, 255 ))

draw.SimpleText( "Health: ", "open_sans_25b", pos.x + 155, pos.y + 199, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
draw.SimpleText( ply:Health(), "open_sans_25b", pos.x + 225, pos.y + 199, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )

surface.SetDrawColor( Color( 200, 50, 50, 255 ))
surface.DrawLine( pos.x + 150, pos.y + 197, pos.x + 296, pos.y + 197 )
surface.DrawLine( pos.x + 296, pos.y + 197, pos.x + 296, pos.y + 231 )
surface.DrawLine( pos.x + 150, pos.y + 230, pos.x + 296, pos.y + 230 )

end

end
--- End code ---


iViscosity:
-snip-


Edit: So are you saying you want the bars to be in a fixed position from the player? In that case you'd have to scale the distance based on the distance from you to them. Right now, the bars are being placed in a fixed location; they're not moving, but look like they are because of the increased size of the player. If you measure from the right end of the bar to the right end of the screen on both screenshots, you'd get the same value.


So what you need to do is find the distance between you and the target, then scale the x pos based on how close or far someone is. If that makes sense.

Navigation

[0] Message Index

Go to full version