ULX

Author Topic: Player Info fixed position  (Read 1634 times)

0 Members and 1 Guest are viewing this topic.

Offline Suicidal Dog

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Player Info fixed position
« on: May 13, 2017, 06:16:16 AM »
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: [Select]
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


« Last Edit: May 13, 2017, 06:18:12 AM by Suicidal Dog »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Player Info fixed position
« Reply #1 on: May 18, 2017, 07:40:36 AM »
-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.
« Last Edit: May 18, 2017, 07:43:10 AM by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.