• Checking if a player is behind a wall?
    12 replies, posted
I was just looking around Gmod Lua Wiki and I wanted to design some sort of heatvision, This is not for some kind of Wallhack. My question is, Is there anyway to show all targets that are not behind a wall of a players vision? Help much appreciated.
[lua] local tr = util.GetPlayerTrace( LocalPlayer(), (ply:EyePos() - LocalPlayer():EyePos()):Normalize() ) if tr.Entity == ply then -- There's a clear shot to the player else -- Something's blocking the trace end[/lua] [b][url=http://wiki.garrysmod.com/?title=Util.GetPlayerTrace]Util.GetPlayerTrace [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=Entoros;20760876]local tr = util.GetPlayerTrace( LocalPlayer(), (ply:EyePos() - LocalPlayer():EyePos()):Normalize() ) if tr.Entity == ply then -- There's a clear shot to the player else -- Something's blocking the trace end [B][URL="http://wiki.garrysmod.com/?title=Util.GetPlayerTrace"]Util.GetPlayerTrace [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B][/QUOTE] Thanks for the quick reply, Is 'ply' shared or only serverside, as it does come up with the error saying ply is a Nil value.
ply is nil, you need to get the references to the player objects yourself. In your case, you want to do this to all players, so you should loop through them. [lua]for _, ply in ipairs(player.GetAll()) do -- Code end[/lua]
[QUOTE=MakeR;20762318]ply is nil, you need to get the references to the player objects yourself. In your case, you want to do this to all players, so you should loop through them. for _, ply in ipairs(player.GetAll()) do -- Code end[/QUOTE] Thanks MakeR Ill give it a try and will post back in a second
ply is the player entity that could be behind a wall. It's not a function. [editline]07:58PM[/editline] I was 5 mins late? Wat
lol Yeah Unfortunately 5 mins late :P Ive just tried the script, Got no error messages but players are not being set the material, here is the code: [lua] function Heatvision() for _, ply in ipairs(player.GetAll()) do local tr = util.GetPlayerTrace( LocalPlayer(), (ply:EyePos() - LocalPlayer():EyePos()):Normalize() ) if tr.Entity == ply then tr.Entity:SetMaterial( "wall/living" ) else -- Something's blocking the trace end end end hook.Add("HUDPaint", "blaeah", Heatvision) [/lua]
Does the material materials/wall/living.vmt exist?
[QUOTE=esalaka;20762794]Does the material materials/wall/living.vmt exist?[/QUOTE] Yeah all correctly placed.
I'm not particularly sure why you're using HUDPaint - that might be the problem. Use "Think" instead (HUDPaint is run every frame and is generally used for drawing to the HUD, Think is run ever millisecond or so and is good for things like this. Or, you could use a timer). I've also had problems in the past with using SetColor and SetMaterial on players clientside in the past, but who knows.
Are there actually players behind the wall in the same visleaf? Also, first try just applying the material on all players (eg. only put ply:SetMaterial in the for-loop) and see if that's the problem.
[QUOTE=Entoros;20763044]I'm not particularly sure why you're using HUDPaint - that might be the problem. Use "Think" instead (HUDPaint is run every frame and is generally used for drawing to the HUD, Think is run ever millisecond or so and is good for things like this. Or, you could use a timer). I've also had problems in the past with using SetColor and SetMaterial on players clientside in the past, but who knows.[/QUOTE] Think is also run every frame.
Ok Thanks for the replys guys :D, Ill give them a try ASAP, Just need to go out for a couple of hours, Ill post back here when Ive tested the ideas.
Sorry, you need to Log In to post a reply to this thread.