Showing Text above NPCs head

How can I make it so when I look at an NPC, It shows text right above their head? Its not 3d2d, its 2d. But its in the world.

Then you’d need to know where it is in 3D.
For starters you need to add some painting functions so we’ll need the **[Gamemode.HUDPaint

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.HUDPaint)** hook.
Then we’ll need to know what entity we’re looking at, so we need the **[Player.GetEyeTrace

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Player.GetEyeTrace)** and **[G.LocalPlayer

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=G.LocalPlayer)**. If you want this to only work on NPCs you’ll need this as well. **[Entity.IsNPC

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Entity.IsNPC)**
For the actual displaying of the information you’ll need **[Draw.DrawText

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Draw.DrawText)** and **[Vector.ToScreen

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Vector.ToScreen)**

[lua]hook.Add(“HUDPaint”, “ShowNPCHealthAboveHead”, function()
– Get the entity we’re looking at
local ent = LocalPlayer():GetEyeTrace().Entity
– check if it’s really an NPC
if ValidEntity(ent) and ent:IsNPC() then
– change the Vector in LocalToWorld to change
– where the text should appear in relation to the ent
local pos = ent:LocalToWorld(Vector(0, 0, 100):ToScreen()
– check we can actually see this part of the entity
if pos.visible then
– what info to draw
draw.DrawText(tostring(ent:Health()),
– what font to draw it in
“ScoreboardText”,
– where to draw it
pos.x, pos.y,
– what colour it must be
Color(255, 255, 255),
– how to align the text
ALIGN_CENTER
)
end
end
end)[/lua]

I tried doing this…

[lua]

hook.Add(“HUDPaint”, “Hud”, function()
– Get the entity we’re looking at
local ent = LocalPlayer():GetEyeTrace().Entity
– check if it’s really an NPC
if ValidEntity(ent) and ent:IsNPC() then
– change the Vector in LocalToWorld to change
– where the text should appear in relation to the ent
local pos = ent:LocalToWorld(Vector(0, 0, 100):ToScreen())
– check we can actually see this part of the entity
if pos.visible then
– what info to draw
draw.DrawText(tostring(ent:Health()),
– what font to draw it in
“ScoreboardText”,
– where to draw it
pos.x, pos.y,
– what colour it must be
Color(255, 255, 255),
– how to align the text
ALIGN_CENTER
)
end
end
end)
[/lua]

got this error

Hook ‘Hud’ Failed: nggrp1/gamemode/cl_init.lua:331: bad argument #1 to ‘LocalToWorld’ (Vector expected, got table)

local x,y = ent:LocalToWorld(ent:GetPos() + Vector(0,0,100)):ToScreen()

Close :l

Ahh, didn’t see it there…
Thanks!

How can you do it so the player has to be within a certain amount of units to see it?


if pl:GetPos():Distance(ent:GetPos()) < 500 then