I got small problem when i watch on player head that stays in front of world prop the text on Overhead hud just being not readable.(Look like the prop stays in front of player)
https://imgur.com/a/cSIiZ
The code:
local plyMeta = FindMetaTable("Player") plyMeta.drawPlayerInfo = plyMeta.drawPlayerInfo or function(self) return false end
local function hivehud_overhud(ply)
if (!IsValid(ply)) then return end
if (ply == LocalPlayer()) then return end
if (!ply:Alive()) then return end
local Distance = LocalPlayer():GetPos():Distance(ply:GetPos())
if (Distance < 512) then
local offset = Vector(0, 0, 23)
local ang = LocalPlayer():EyeAngles()
local pos = ply:EyePos() + offset + ang:Up()
ang:RotateAroundAxis(ang:Forward(), 90)
ang:RotateAroundAxis(ang:Right(), 90)
cam.Start3D2D(pos, Angle(0, ang.y, 90), 0.25)
local nick, plyTeam = ply:Nick(), ply:getDarkRPVar("job")
draw.DrawText(nick, "MHUD_18", 1, 2, Color(0,0,0,235), TEXT_ALIGN_CENTER)
draw.DrawText(nick, "MHUD_18", 0, 0, Color(255,255,255,255), TEXT_ALIGN_CENTER)
draw.DrawText(plyTeam, "MHUD_18", 1, 15, Color(0,0,0,235), TEXT_ALIGN_CENTER)
draw.DrawText(plyTeam, "MHUD_18", 0, 15, team.GetColor(ply:Team()), TEXT_ALIGN_CENTER)
draw.DrawText("HP:%"..ply:Health(), "MHUD_18", 1, 35, Color( 0, 0, 0, 235 ), TEXT_ALIGN_CENTER)
draw.DrawText("HP:%"..ply:Health(), "MHUD_18", 0, 35, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER)
if ply:getDarkRPVar("wanted") then
draw.DrawText("Wanted", "MHUD_18", 1, -16, Color( 0, 0, 0, 235 ), TEXT_ALIGN_CENTER)
draw.DrawText("Wanted", "MHUD_18", 0, -16, Color( 206, 62, 14, 255 ), TEXT_ALIGN_CENTER)
end
cam.End3D2D()
end
end
hook.Add("PostPlayerDraw", "hivehud_overhud", hivehud_overhud)
Try drawing it in a "PostDrawTranslucentRenderables" hook, there might be something better for it, but that might solve your issue.
But how properly to do it?
I tried but this isn't working
Put it in HUDPaint ?
Render Order
Tried but it isn't working. I still can't see text on player's head when player is on front of prop
You're lying. Post your code.
Here is the code:
local function hivehud_overhud(ply)
if (!IsValid(ply)) then return end
if (ply == LocalPlayer()) then return end
if (!ply:Alive()) then return end
local Distance = LocalPlayer():GetPos():Distance(ply:GetPos())
if (Distance < 512) then
local offset = Vector(0, 0, 23)
local ang = LocalPlayer():EyeAngles()
local pos = ply:EyePos() + offset + ang:Up()
local focus
local LastHasFocus
ang:RotateAroundAxis(ang:Forward(), 90)
ang:RotateAroundAxis(ang:Right(), 90)
cam.Start3D2D(pos, Angle(0, ang.y, 90), 0.25)
local nick, plyTeam = ply:Nick(), ply:getDarkRPVar("job")
surface.SetMaterial(Material("icon16/page_white.png"))
if LocalPlayer():getDarkRPVar("HasGunlicense") then
surface.SetDrawColor(255, 255, 255, 255)
else
surface.SetDrawColor(0,0,0,0)
end
surface.DrawTexturedRect(32, 0, 16, 16)
draw.DrawText(nick, "MHUD_18", 1, 2, Color(0,0,0,235), TEXT_ALIGN_CENTER)
draw.DrawText(nick, "MHUD_18", 0, 0, Color(255,255,255,255), TEXT_ALIGN_CENTER)
draw.DrawText(plyTeam, "MHUD_18", 1, 15, Color(0,0,0,235), TEXT_ALIGN_CENTER)
draw.DrawText(plyTeam, "MHUD_18", 0, 15, team.GetColor(ply:Team()), TEXT_ALIGN_CENTER)
if ply:getDarkRPVar("wanted") then
draw.DrawText("Wanted", "MHUD_18", 1, -16, Color( 0, 0, 0, 235 ), TEXT_ALIGN_CENTER)
draw.DrawText("Wanted", "MHUD_18", 0, -16, Color( 206, 62, 14, 255 ), TEXT_ALIGN_CENTER)
end
cam.End3D2D()
end
end
hook.Add("HUDPaint","HUD",hivehud_overhud)
Yes, prop_physics
Oh sorry, I didn't see you had a 3D2D. Try putting the 3D2D code within a Start3D. You also need to reconnect so the previous hook is destroyed.
Put cam3d2d into cam3d?
Try to loop through all the players in GM:PostDrawOpaqueRenderables
But how?
As other people suggested, try to use the GM:PostDrawTranslucentRenderables hook.
You could try to do something like this, I guess you can finish the rest up yourself. The GM:PostDrawTranslucentRenderables hook in the code underneath should theoretically work, but I haven't tested it.
local function hivehud_overhud(ply)
// Make some code to draw the stuff etc. in this.
end
hook.Add("PostDrawTranslucentRenderables", "hivehud_drawthatthingy", function()
local trace = LocalPlayer():GetEyeTrace()
local ent = trace.Entity
if not ent:IsPlayer() then return end
local dist = LocalPlayer():GetPos():DistToSqr(ent:GetPos())
if dist > 262144 then return end // We use DistToSqr, it returns a squared distance. If you take the square root of 262144, it is 512.
hivehud_overhud(ent)
end)
In theory, Vector:DistToSqr should be faster than using Vector:Distance, and it is not that hard to use so might aswell use it.
Sorry, you need to Log In to post a reply to this thread.