Tracing

Hey, I’m trying to make a function that determines whether you can see an other player or not, yet it doesn’t work - ideas?

function CanSeePlayer(ply)
local tracedata = {}
tracedata.start = LocalPlayer():GetPos()
tracedata.endpos = ply:GetPos()
tracedata.filter = LocalPlayer().Model
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
return trace.Entity == ply
end
return false
end

I think you can set the filter to just LocalPlayer()

You could use this :
[lua]
local tr = LocalPlayer():GetEyeTrace()
if tr.Entity and tr.Entity.IsValid and ValidEntity(tr.Entity) and tr.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 400 then
if tr.Entity:IsPlayer() then
DrawPlayerInfo(tr.Entity)
end
end
[/lua]

Originally from DarkRP to trace names of people if you see them but i’ve also seen it on the wiki.

Would that on work when im aiming at them?

[lua]function canSee( pl1, pl2 )
return util.GetPlayerTrace( pl1, pl1:EyePos() - pl2:EyePos() ).Entity == pl2;
end[/lua]

That might work?

Is this for a swep or script or gamemode? Be more specific in your question.

gamemode, i cant see how does it matter since it doesnt use hooks - though im pretty new, so correct me if im wrong - ill try Entoros’ version

-month later-
none worked, btw… forgot to post that, continued on other stuff meanwhile