Name above head

Yeah i am trying to do the whole thing with the players name above there head when you look at them.

I have been looking around and can’t find anything

[lua]
local function PlayerName(ply)
if not ply:Alive() then return end

local spot = ply:Eyespot()

spot.z = spot.z + 15
spot = spot:ToScreen()

	draw.DrawText(ply:Nick(), "TargetID", spot.x + 1, spot.y + 1, Color(0, 0, 0, 255), 1)
	draw.DrawText(ply:Nick(), "TargetID", spot.x, spot.y, Color(0, 0, 0, 255), 1)

end
[/lua]

Don’t see why that shouldn’t work.

An addition to his code up there ^

[lua]hook.Add(“HUDPaint”, “player_info_name_draw”, function()
local ent = LocalPlayer():GetEyeTrace().Entity
if ent != nil and ValidEntity(ent) and ent:IsPlayer() then
PlayerName(ent)
end
end)[/lua]

That will draw text above the player you look at using zzaacckk’s function.

Alright so in my cl_init.lua file i now have this

[lua]
local function PlayerName(ply)
if not ply:Alive() then return end

local spot = ply:Eyespot()  

spot.z = spot.z + 15  
spot = spot:ToScreen()  

    draw.DrawText(ply:Nick(), "TargetID", spot.x + 1, spot.y + 1, Color(0, 0, 0, 255), 1)  
    draw.DrawText(ply:Nick(), "TargetID", spot.x, spot.y, Color(0, 0, 0, 255), 1)  

end
hook.Add(“HUDPaint”, “player_info_name_draw”, PlayerName)
local ent = LocalPlayer():GetEyeTrace().Entity
if ent != nil and ValidEntity(ent) and ent:IsPlayer() then
PlayerName(ent)
end
end
[/lua]

I get a error on this line

[lua]
local ent = LocalPlayer():GetEyeTrace().Entity
[/lua]

It’s fine.

Well, not fine, since it’s probably being ran before LocalPlayer is valid. What’s it doing there?

In fact, whole code is messed up

[lua]
local function PlayerName()
local ent = LocalPlayer():GetEyeTrace().Entity
if !ent or !ValidEntity(ent) or !ent:IsPlayer() then return end

  if(!ent:Alive()) then return end

local spot = ent:EyePos()  

spot.z = spot.z + 15 
spot = spot:ToScreen()  

    draw.DrawText(ent:Nick(), "TargetID", spot.x + 1, spot.y + 1, Color(0, 0, 0, 255), 1)  
    draw.DrawText(ent:Nick(), "TargetID", spot.x, spot.y, Color(0, 0, 0, 255), 1)  

end
hook.Add(“HUDPaint”, “player_info_name_draw”, PlayerName)[/lua]

cl_init.lua is clientside.

So replace ply with LocalPlayer

It works :slight_smile: Thank you!

One more question, how do i remove the default one?

Default what? You need to be more explicit when asking questions.

When you holder your cross hair over a player where ever you aim it will show there name and health in yellow text. I want to remove that

[lua]function GAMEMODE:HUDDrawTargetID()
return false
end[/lua]

All i had to do was change GAMEMODE to GM, Thank you :slight_smile: