• Can you see check
    3 replies, posted
What is the code to check if a player can see something? For instance I have a lot of npc about with their names shown but I only want to show the NPC names that the player literally can see, not the ones behind walls etc. Thank you for the assistance. Example [code] local function DrawNPCInfo() for _, ent in pairs(ents.GetAll()) do if ValidEntity(ent) && ent:IsNPC() then //code needed to check if I can see end end end [/code]
[lua]function _R.Vector:IsInSight() ply = LocalPlayer() local trace = {} trace.start = ply:EyePos() trace.endpos = self trace.mask = -1 local TheTrace = util.TraceLine(trace) if TheTrace.Hit then return false else return true end end[/lua]
Thank you, i'll try this now. So giving it returns true or false means I can easily use this in an if statement.
[QUOTE=techtuts0;30937997] function _R.Vector:IsInSight() ply = LocalPlayer() local trace = {} trace.start = ply:EyePos() trace.endpos = self trace.mask = -1 local TheTrace = util.TraceLine(trace) if TheTrace.Hit then return false else return true endend[/QUOTE] Why dont you just [lua]function _R.Vector:IsInSight() ply = LocalPlayer() local trace = {} trace.start = ply:EyePos() trace.endpos = self trace.mask = -1 local TheTrace = util.TraceLine(trace) return not TheTrace.Hit end[/lua]
Sorry, you need to Log In to post a reply to this thread.