cam2d3d

Hello, I have info drawn above a players head in my hud using cam2d3d and the PostPlayerDraw hook. There is a visual bug when looking at the actual drawn objects in front of any world props. Is there any work around for this? Here is a SS. This,

and here is my code,


function plyinfohud(ply)

	if ply == LocalPlayer() and GetViewEntity() == LocalPlayer() then return end
	if ply:GetPos():Distance(LocalPlayer():GetPos()) < 250 and ply:Alive() then

		local job = ply:getDarkRPVar("job")
		local teamcolor = team.GetColor(ply:Team())

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

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

		local x = -100
		local width = 200
		local height = 64
		surface.SetFont("STH_font_22")
		local jobWidth, jobHeight = surface.GetTextSize(job)
		local nick = ply:Nick()
		surface.SetFont("STH_font_22")
		local nickWidth, nickHeight = surface.GetTextSize(nick)
		stringSplit(nick, " ")

		function main(x, y, w, h)
			surface.SetDrawColor(40,40,40)
			surface.DrawRect(x, y, w, h)

			surface.SetDrawColor(0,0,0)
			surface.DrawOutlinedRect(x, y, w, h)
		end

		function nickInfo(x, y, w, h)
			surface.SetDrawColor(60,60,60)
			surface.DrawRect(x, y, w, h)

			surface.SetDrawColor(0,0,0)
			surface.DrawOutlinedRect(x, y, w, h)
		end
		
		function jobInfo(x, y, w, h)
			surface.SetDrawColor(60,60,60)
			surface.DrawRect(x, y, w, h)

			surface.SetDrawColor(0,0,0)
			surface.DrawOutlinedRect(x, y, w, h)
		end

		cam.Start3D2D(Pos, Ang, 0.1)

			if nickWidth > jobWidth then
				main((0-(nickWidth/2))-10, 0, nickWidth+20, 64)
				jobInfo(0-(nickWidth/2)-5, 34, nickWidth+10, 24)
				nickInfo(0-(nickWidth/2)-5, 5, nickWidth+10, 24)
			else
				main((0-(jobWidth/2))-10, 0, jobWidth+20, 64)
				jobInfo(0-(jobWidth/2)-5, 34, jobWidth+10, 24)
				nickInfo(0-(jobWidth/2)-5, 5, jobWidth+10, 24)
			end

			draw.SimpleText(job,"STH_font_22",0,34,teamcolor,1,0)
			draw.DrawText(nick,"STH_font_22",0,5,Color(255,255,255),1,0)

		cam.End3D2D()
	end
end

hook.Add("PostPlayerDraw", "plyinfohud", plyinfohud)

Try PostDrawOpaqueRenderables instead

Okay, I changed it, also made a loop to go through all players because the PostPlayerDraw returned ply,


function plyinfohud()
	for k, ply in pairs(player.GetAll()) do
		if ply == LocalPlayer() and GetViewEntity() == client then return end
		if ply:GetPos():Distance(client:GetPos()) < 250 and ply:Alive() then

			local nick = ply:Nick()
			local job = ply:getDarkRPVar("job")
			local teamcolor = team.GetColor(ply:Team())

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

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

			local x = -100
			local width = 200
			local height = 64

			surface.SetFont("STH_font_22")
			local jobWidth, jobHeight = surface.GetTextSize(job)

			surface.SetFont("STH_font_22")
			local nickWidth, nickHeight = surface.GetTextSize(nick)

			stringSplit(nick, " ")

			function main(x, y, w, h)
				surface.SetDrawColor(40,40,40)
				surface.DrawRect(x, y, w, h)

				surface.SetDrawColor(0,0,0)
				surface.DrawOutlinedRect(x, y, w, h)
			end

			function nickInfo(x, y, w, h)
				surface.SetDrawColor(60,60,60)
				surface.DrawRect(x, y, w, h)

				surface.SetDrawColor(0,0,0)
				surface.DrawOutlinedRect(x, y, w, h)
			end
			
			function jobInfo(x, y, w, h)
				surface.SetDrawColor(60,60,60)
				surface.DrawRect(x, y, w, h)

				surface.SetDrawColor(0,0,0)
				surface.DrawOutlinedRect(x, y, w, h)
			end

			cam.Start3D2D(Pos, Ang, 0.1)

				if nickWidth > jobWidth then
					main((0-(nickWidth/2))-10, 0, nickWidth+20, 64)
					jobInfo(0-(nickWidth/2)-5, 34, nickWidth+10, 24)
					nickInfo(0-(nickWidth/2)-5, 5, nickWidth+10, 24)
				else
					main((0-(jobWidth/2))-10, 0, jobWidth+20, 64)
					jobInfo(0-(jobWidth/2)-5, 34, jobWidth+10, 24)
					nickInfo(0-(jobWidth/2)-5, 5, jobWidth+10, 24)
				end

				draw.SimpleText(job, "STH_font_22", 0, 34, teamcolor, 1, 0)
				draw.DrawText(nick, "STH_font_22", 0, 5, Color(255,255,255), 1, 0)

			cam.End3D2D()
		end
	end
end

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

Now nothing is drawing at all, not getting any lua errors. Why wouldn’t it draw?

First, get those functions out of the hook: you are recreating functions every time it runs and it runs constantly

Secondly, I think you didn’t define “client” as it’s the only thing there that isn’t in the function. Have you defined it somewhere else?

Client is Localplayer()

[editline]16th February 2017[/editline]


function base(x, y, w, h)
	surface.SetDrawColor(40,40,40)
	surface.DrawRect(x, y, w, h)

	surface.SetDrawColor(0,0,0)
	surface.DrawOutlinedRect(x, y, w, h)
end

function nickInfo(x, y, w, h)
	surface.SetDrawColor(60,60,60)
	surface.DrawRect(x, y, w, h)

	surface.SetDrawColor(0,0,0)
	surface.DrawOutlinedRect(x, y, w, h)
end
			
function jobInfo(x, y, w, h)
	surface.SetDrawColor(60,60,60)
	surface.DrawRect(x, y, w, h)

	surface.SetDrawColor(0,0,0)
	surface.DrawOutlinedRect(x, y, w, h)
end

function plyinfohud()
	for k, ply in pairs(player.GetAll()) do
		print(ply)
		if ply == LocalPlayer() and GetViewEntity() == LocalPlayer() then return end
		if ply:GetPos():Distance(LocalPlayer():GetPos()) < 250 and ply:Alive() then

			local nick = ply:Nick()
			local job = ply:getDarkRPVar("job")
			local teamcolor = team.GetColor(ply:Team())

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

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

			local x = -100
			local width = 200
			local height = 64

			surface.SetFont("STH_font_22")
			local jobWidth, jobHeight = surface.GetTextSize(job)

			surface.SetFont("STH_font_22")

			local nickWidth, nickHeight = surface.GetTextSize(nick)

			cam.Start3D2D(Pos, Ang, 0.1)

				if nickWidth > jobWidth then
					base((0-(nickWidth/2))-10, 0, nickWidth+20, 64)
					jobInfo(0-(nickWidth/2)-5, 34, nickWidth+10, 24)
					nickInfo(0-(nickWidth/2)-5, 5, nickWidth+10, 24)
				else
					base((0-(jobWidth/2))-10, 0, jobWidth+20, 64)
					jobInfo(0-(jobWidth/2)-5, 34, jobWidth+10, 24)
					nickInfo(0-(jobWidth/2)-5, 5, jobWidth+10, 24)
				end

				draw.SimpleText(job, "STH_font_22", 0, 34, teamcolor, 1, 0)
				draw.DrawText(nick, "STH_font_22", 0, 5, Color(255,255,255), 1, 0)

			cam.End3D2D()
		end
	end
end

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

This still isn’t drawing anything, I have print(ply) right after the table loop to see if it counts bots as players. I did the same thing in a think hook and it does print the bots, but in this hook it doesn’t print the bots and that’s the reason it isn’t drawing. Why won’t it pick up the bots?

[editline]16th February 2017[/editline]

Actually got it working, just doesn’t draw over bots. Still same issue with it drawing behind world props