• [HELP] Hovering names going through walls.
    8 replies, posted
So im using this name above head script from nucleotic in my gamemode. [CODE] function HoveringNames() for _, target in pairs(player.GetAll()) do if target:Alive() and target != LocalPlayer() then local targetPos = target:GetPos() + Vector(0,0,84) local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40) local targetScreenpos = targetPos:ToScreen() draw.SimpleText(target:Nick(), "Trebuchet18", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(200,25,25,200), TEXT_ALIGN_CENTER) end end end hook.Add("HUDPaint", "HoveringNames", HoveringNames) [/CODE] It goes through walls and I don't know how to fix it.. I believe I would have to use 3d2d text but I don't really know how to do it. Also Ik I'm sorry for being a copy/paster
if target:Alive() and target !=LocalPlayer and LocalPlayer():Visible(target) then
[QUOTE=GbrosMC;51280294]if target:Alive() and target !=LocalPlayer and LocalPlayer():Visible(target) then[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Visible]Entity:Visible[/url] Visible is serverside only.
[QUOTE=TFA;51280299][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Visible]Entity:Visible[/url] Visible is serverside only.[/QUOTE] Then he should just use 2d3d :^)
[code] local lply local tpos local tracedata = {} local traceres local minsvec = Vector(-5,-5,-5) local maxsvec = Vector(5,5,5) local function LocalPlayerCanSee(ent1) if !IsValid(lply) then lply=LocalPlayer() return end tpos = ent1.GetShootPos and ent1:GetShootPos() or ent1:GetPos() tpos = ( tpos + ent1:GetPos() )/2 tracedata.start = lply:GetShootPos() tracedata.endpos = tpos tracedata.mins = minsvec tracedata.maxs = maxsvec tracedata.filter = { lply, lply:GetActiveWeapon(), ent1.GetActiveWeapon and ent1:GetActiveWeapon() } traceres = util.TraceHull(tracedata) if traceres.Entity == ent1 then return true else return false end end [/code] You can use this for your visibility check.
So I would do this after that [CODE] function HoveringNames() if LocalPlayerCanSee = true then for _, target in pairs(player.GetAll()) do if target:Alive() and target != LocalPlayer() then local targetPos = target:GetPos() + Vector(0,0,84) local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40) local targetScreenpos = targetPos:ToScreen() draw.SimpleText(target:Nick(), "Trebuchet18", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(200,25,25,200), TEXT_ALIGN_CENTER) end end end end hook.Add("HUDPaint", "HoveringNames", HoveringNames) [/CODE]
[QUOTE=MLPG;51280510]-broken code-[/QUOTE] Not quite. LocalPlayerCanSee is a function; it takes an argument of a Player ( or other entity ) and returns if they're visible. Working code is as such: [code] local targetPos local targetScreenpos local function HoveringNames() for _, target in pairs(player.GetAll()) do if target:Alive() and target != lply and LocalPlayerCanSee(target) then targetPos = target:GetShootPos() + Vector(0,0,16) targetScreenpos = targetPos:ToScreen() draw.SimpleText(target:Nick(), "Trebuchet18", targetScreenpos.x, targetScreenpos.y, Color(200,25,25,200), TEXT_ALIGN_CENTER) end end end hook.Add("HUDPaint", "HoveringNames", HoveringNames) [/code]
Thx worked like a charm!
[QUOTE=MLPG;51280990]Thx worked like a charm![/QUOTE] Make sure to mark your thread as solved if you don't need any more help.
Sorry, you need to Log In to post a reply to this thread.