playerinfo hud

I’m trying to figure out the best way of drawing an element to my hud like the default darkrp playerinfo hud (the one that is above a player). I found a 3d2d function snippet that allows me to use draw funcs above a head but there are a few issues I have ran into with this.

http://images.akamai.steamusercontent.com/ugc/96099157756599464/2C51ABAE6474D809D68DB3D53FDFFBE06B224F80/

http://images.akamai.steamusercontent.com/ugc/96099157756598927/4DD39EEE4B9E378D923BD04A10F52E861D4B1879/

First off, is the correct way to go about drawing a player info hud? Is there a better way of doing it?

The first screenshot is self explanatory, how could I make it so that players can’t see their own info, but still can see other players info.

For the second screenshot I am trying to add the blur effect like the rest of the hud to this as well.


local function DrawBlurRect(x, y, w, h, amount, heavyness)
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(blur)

	for i = 1, heavyness do
		blur:SetFloat("$blur", (i / 3) * (amount or 6))
		blur:Recompute()

		render.UpdateScreenEffectTexture()

		render.SetScissorRect(x, y, x + w, y + h, true)
			surface.DrawTexturedRect(0 * -1, 0 * -1, ScrW(), ScrH())
		render.SetScissorRect(0, 0, 0, 0, false)
	end
end

function plyinfohud()

	local ply = LocalPlayer()

	local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
	local Pos = HeadPos + Vector(0, 5, 40)

	local Ang = EyeAngles()
	Ang:RotateAroundAxis( Ang:Right(), 90 )
	Ang:RotateAroundAxis( Ang:Up(), -90 )

	cam.Start3D2D(Pos, Ang, 0.1)

		-- draw.RoundedBox(0,-100,-200,200,100,Color(255,255,255))
		DrawBlurRect( -100, -100, 200, 100, 5, 4 )
		draw.RoundedBox( 10, -100, 100, 200, 100, Color( 0, 0, 0, 175 ) )
		draw.SimpleText(ply:Nick(),"plyhud",0,150,Color(255,255,255),1,1)
	
	cam.End3D2D()

end

hook.Add("PostDrawOpaqueRenderables", "plyinfo", plyinfohud)

Could the reason it is not drawing possibly have something to do with the 2d/3d rendering stuff? I can’t see why because draw.box is 2d, but the 3d2d cam allows it to work. Thoughts??

Thanks in advance for any help!

:snip:
You were talking about the blur

[editline]10th January 2017[/editline]

To answer your other question, you could just use 2D for this if you want - all you need to do is find the player’s head position and then use

Vector:ToScreen to draw some 2D text in the 2D coordinates above it



local function plyinfohud()

	for _, ply in pairs(player.GetAll()) do

		if ply ~= LocalPlayer() then -- Don't draw our own name above our head

			local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
			local Pos = HeadPos:ToScreen()
			Pos.y = Pos.y - 50

			DrawBlurRect( Pos.x - 100, Pos.y - 50, 200, 100, 5, 4 )
			draw.RoundedBox( 10, Pos.x - 100, Pos.y - 50, 200, 100, Color( 0, 0, 0, 175 ) )
			draw.SimpleText( ply:Nick(), "plyhud", Pos.x, Pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )

		end
	end

end

hook.Add( "HUDPaint", "plyinfo", plyinfohud )


That code needs a bit of adjustment to make it look actually good but it should give you an idea - it’s a bit simpler this way

Also, you should really be using

surface.GetTextSize so you draw the box the actual size of the player’s name

Well yes of course, I only had that formatted just so I could understand how it all worked. Do you have insight on the blur function I am using and why it may not be drawing?

Maybe it only works in 2D or something? I tried testing it but you didn’t define the ‘blur’ variable that you’re using SetMaterial with, so it didn’t work. I just assumed you defined it yourself before somewhere

[editline]10th January 2017[/editline]

I’m sure you would’ve noticed if it wasn’t defined though, it spammed my console with errors. If you post what it is I could try testing it

[editline]10th January 2017[/editline]

Sorry, I misunderstood that you were asking about the blur originally

And I apologize, but could you go a bit more in depth about the Vector:ToScreen()? I am having a hard time understanding what you mean and what it does.

[editline]10th January 2017[/editline]

Here is the blur var


local blur = Material("pp/blurscreen")

You only need to use Vector:ToScreen() if you want to draw the HUD in 2D rather than having it 3D.

Vector:ToScreen() just gets a 3D vector (such as the 3D coordinates of a player’s head for example) and returns 2D x and y coordinates of where this is on the local player’s screen.

The reason you need to use this for 2D drawing is because any 2D drawing functions need x and y coordinates. For example, draw.SimpleText needs x and y coordinates of where to draw the text. You can’t give it a 3D location to draw the text because it draws in 2D

Hopefully this makes a bit of sense, but I’m not good at explaining.

[editline]11th January 2017[/editline]

I tested the blur function and it works well in 2D, but in 3D it gets a bit tricky because since the cam function kind of distorts 2D stuff that gets drawn into being 3D it offsets the blur a bit from the screen

So are you saying it can’t be done? Were you able to figure it out?

[editline]10th January 2017[/editline]

And how could I go about making a 2d hud that displays over a player?

It’s probably possible with this thing NeatNit made a while ago

if you want to try doing it in 2D I posted a working thing before



local blur = Material("pp/blurscreen")

local function DrawBlurRect(x, y, w, h, amount, heavyness)
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(blur)

	for i = 1, heavyness do
		blur:SetFloat("$blur", (i / 3) * (amount or 6))
		blur:Recompute()

		render.UpdateScreenEffectTexture()

		render.SetScissorRect(x, y, x + w, y + h, true)
			surface.DrawTexturedRect(0 * -1, 0 * -1, ScrW(), ScrH())
		render.SetScissorRect(0, 0, 0, 0, false)
	end
end

local function plyinfohud()

	for _, ply in pairs(player.GetAll()) do

		if ply ~= LocalPlayer() then -- Don't draw our own name above our head

			local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
			local Pos = HeadPos:ToScreen()
			Pos.y = Pos.y - 50

			DrawBlurRect( Pos.x - 100, Pos.y - 50, 200, 100, 5, 4 )
			draw.RoundedBox( 10, Pos.x - 100, Pos.y - 50, 200, 100, Color( 0, 0, 0, 175 ) )
			draw.SimpleText( ply:Nick(), "plyhud", Pos.x, Pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )

		end
	end

end

hook.Add( "HUDPaint", "plyinfo", plyinfohud )


When I plug that into my code, it doesn’t draw anything at all.

[editline]10th January 2017[/editline]

Nevermind, added


cam.Start2d 
draw.w/e
cam.End2d

[editline]10th January 2017[/editline]

Is there a way I could reduce the size of the box as a function of distance? So that the box remains the same size as players ran towards and away from eachother?

Here is why. I get it the position is off, I’m just figuring stuff out still.