1. Post #1
    Gold Member
    Ericson666's Avatar
    May 2011
    2,375 Posts
    Hi there, I've been trying to create a crappy Metal Gear-esque gamemode, and production has gone along fine... Until I came upon the issue of getting the alert working when a guard sees Snake.

    I know I have to use a trace, and I've tried scouring the Gmod Wiki mirrors (other trace related searches only bring up clientside aimbots), but I'm still somewhat confused. I believe I have to use this to conduct the trace, but then I have no idea what to do from there.

    function sight()
    	if traceRes.HitNonWorld then
    		sight = true
    	else
    		sight = false
    	end
    end
    
    pl=player.GetByID(1)
    traceRes=pl:GetEyeTrace()

    This is my coding for this part so far. As you can see, pretty lackluster. I need to make it so that sight only equals true if the guard see's Snake, who is on the opposite team (while ignoring the guard's teammates) but I haven't seen anything which discriminates based on team. Plus to add onto that, I need to make it so Snake can't use it, which makes it all the more worrying. Can anyone help me? It would be extremely appreciated!

  2. Post #2
    cis.joshb's Avatar
    January 2011
    1,245 Posts
    function Alert()
    	
    	for k, v in pairs(player.GetAll()) do
    		
    		if v:Team() == GUARD_TEAMNUMBER_HERE then
    			local tr = v:GetEyeTrace()
    			
    			if tr.Entity:GetClass() == "player" and tr.Entity:Team() == SNAKE_TEAMNUMBER_HERE then
    				-- do whatever you want for alert
    				
    			end
    			
    		end
    		
    	end
    	
    end
    
    hook.Add("Think", "Alert", Alert)
    
    Untested code. Tell me if it errors, or if you want it commented.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Lua Helper Lua Helper x 1 (list)

  3. Post #3
    Gold Member
    Ericson666's Avatar
    May 2011
    2,375 Posts
    Thank you VERY much for the response! As soon as I get a test ready, I'll report back with the results!