Help with Custom map entities and triggers

I am attempting to change a Viewangle networked variable of a player that enters a trigger, but I cannot seem to get any results.

the trigger’s output is connected to the entity’s input of “Activate.”

entity code:



ENT.Type = "point"
ENT.Base = "base_point"

ENT.viewang = Angle(60,90,0)

function ENT:Initialize()
	print("Viewcahnger ready")//to determine if the entity actually works, remove this when done
end

function ENT:KeyValue(k,v)
	if k == "sight_angle" then
		local ang = string.Explode( " ",v )
		self.viewang = Angle(ang[1],ang[2],ang[3])
	end	
end

function ENT:AcceptInput(name, activator, caller, data)
	if name == "Activate" then
		if IsValid(activator) and activator:IsPlayer() then
			if activator.GetNWAngle != self.viewang then
				activator.SetNWAngle(self.viewang)
				print(string(self.viewang))
			end
		end
	end	
end


and the .fgd code is here:


@include "base.fgd"

@PointClass base(Targetname, Origin, Angles) = trigger_MCViewAngles : "MCViewAngles"
[
	sight_angle(string) : "View Pitch, Yaw, Roll" : "60 90 0" : "Sets the player's view while in the trigger."
	
	// Inputs
	
	input Activate(void) : "ACTIVATE THE VIEW CHANGE"
	
]

I don’t think you have to edit any .fgd files. Use http://wiki.garrysmod.com/?title=ENT.StartTouch and do a check if the entity that triggered is a player then set the players variable as you wish. In hammer set it up like you normally if it where a trigger then name it your entities name.

First of all, use lua tags instead of code tags, they are a lot more readable.

Okay, so you have several mistakes in that code. First, you have this:

[lua]if activator.GetNWAngle != self.viewang then[/lua]

This simply does not make sense, because GetNWAngle is a function and you are NOT calling it (and thus comparing a function with an angle, which will most likely not work).

[lua]activator.GetNWAngle()[/lua]

That’s how you would call it, although this is still incorrect because when you call a function that way, Lua can’t know which entity you are talking about. You have to put “:” instead of “.”, just like when you wrote activator:IsPlayer().

[lua]activator:GetNWAngle()[/lua]

And that’s STILL incorrect because the game doesn’t know WHICH networked angle you are talking about. Networked vars are meant to share custom data from the server to all clients, so obviously, every networked variable has a name. Let’s say you want to check the “Viewangle” networked var, you would do this.

[lua]activator:GetNWAngle(“Viewangle”)[/lua]

The same applies for this line:

[lua]activator.SetNWAngle(self.viewang)[/lua]

You would change it to this:

[lua]activator:SetNWAngle(“Viewangle”, self.viewang)[/lua]

Keep in mind that networked vars do not have any meaning if you don’t give them any. They are just like any variable, changing them does nothing if you don’t use them anywhere. I suspect you actually wanted to change the player’s view angle, then you should use EyeAngles() and SetEyeAngles() instead.

[lua]function ENT:AcceptInput(name, activator, caller, data)
if name == “Activate” then
if IsValid(activator) and activator:IsPlayer() then
if activator:EyeAngles() != self.viewang then
activator:SetEyeAngles(self.viewang)
print(string(self.viewang))
end
end
end
end[/lua]

i’m not exactly setting the eye angles, but you did help me get it working. Thanks