So I am trying to make it so player names are above their head w/o having to aim at people. Due to the fact that aiming at moving people is annoying.
[lua]
function SetupPixVis()
PixVis = util.GetPixelVisibleHandle()
end
hook.Add("Initialize", "SetupPixVis", SetupPixVis)
function drawplayernames()
for k, v in pairs(ents.GetAll()) do
if v:IsPlayer() or v:IsNPC() then
local visible = util.PixelVisible(v:GetPos(), 50, PixVis) -- Check if the pixel is visible
if visible && visible != 0 then -- if the ent is visible
local myposition = LocalPlayer():GetPos()
local targetposition = v:GetPos()
local targetdistance = myposition:Distance(targetposition)
if targetdistance <= 750 then
local pos = v:GetPos() + Vector(0,0,82.5)
pos = pos:ToScreen()
local name
if v:IsPlayer() then name = v:Nick() else name = v:GetClass() end
if v != LocalPlayer() then
surface.CreateFont ("DefaultFixedOutline", ScreenScale(15), 400, true, false, "playernames")
draw.SimpleTextOutlined(name, "playernames", pos.x, pos.y , Color(51,255,9,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,255))
end
end
end
end
end
end
hook.Add("HUDPaint", "drawplayernames", drawplayernames)
[/lua]
Here is what I have at the moment. However, it gets all the entities and the first one it gets it only uses that. So if that first entity isn't visible every other NPC or Player names do not show.
I need help finding a better way to find out if an entity is visible or not, and has to be client-side. Without using a trace based on player's aim.
If you use the handy function [b][url=http://wiki.garrysmod.com/?title=Vector.ToScreen]Vector.ToScreen [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], it gives a value of "visible" that tells you if the position is on the screen.
[QUOTE=Entoros;24174784]If you use the handy function [b][url=http://wiki.garrysmod.com/?title=Vector.ToScreen]Vector.ToScreen [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], it gives a value of "visible" that tells you if the position is on the screen.[/QUOTE]
I've tried a few different attempts but still I cannot make it work. Could you give me an example of making Vector.ToScreen return "visible"?
[lua]for _,v in pairs(player.GetAll()) do
local screen_pos = v:GetPos():ToScreen();
print(v:Name() .. (screen_pos.visible and "is" or "is not") .. " visible.");
end[/lua]
ToScreen returns a table, of which "visible" is the key to a boolean of whether the position is visible on the screen. The example above lists all the players and says whether their position is visible on the screen.
After testing that out I found out that if I look at the player/NPC through a wall it still says they're visible. Which is giving me results I do not want. I do not want to be able to see names through walls.
Then you have to perform a trace from your EyePos() to the target's EyePos() and checking if the world is hit.
Evolve ( and CGAM , my admin mod ) does this prety well. use that code
Thanks a lot for the quick replies. I tried the trace between Eyepos and it works perfectly. Thanks for the assistance all 3 of you.
Sorry, you need to Log In to post a reply to this thread.