void() camera_off = 
{
	self.cameraon = FALSE;
        msg_entity = self;
        WriteByte (MSG_ONE, SVC_SETVIEWPORT); 
        WriteEntity (MSG_ONE, self);
};

void() camera_on = 
{
	self.cameraon = TRUE;
	self.weaponmodel = "";
        msg_entity = self;
        WriteByte (MSG_ONE, SVC_SETVIEWPORT);
        WriteEntity (MSG_ONE, self.camera);
	makevectors (self.angles);
};

void() camera_spawn = 
{	// called at the end of PutClientInServer()
	if (!self.camera)
		self.camera = spawn();
        setmodel        (self.camera, "progs/null.spr");
	setsize		(self.camera, VEC_HULL_MIN, VEC_HULL_MAX);
	setorigin	(self.camera, self.origin);
	self.camera.view_ofs	= '0 0 22';
        self.camera.movetype    = MOVETYPE_NOCLIP;
        self.camera.solid       = SOLID_NOT;
        self.camera.health      = 150;
	self.camera.owner	= self;
};

void() camera_chase =
{
	local float c;
	local vector h;

	// called at the end of PlayerPostThink
	if (!self.camera)
		return;

	c = pointcontents (self.origin + '0 0 12');
        if (c == CONTENT_SKY || c == CONTENT_SOLID)
 		return;

	makevectors(self.v_angle);
	traceline (self.origin, self.origin - v_forward * self.camera.health, TRUE, self);

	if (trace_fraction < 1)
		trace_endpos = trace_endpos + v_forward * 16;
	
	self.camera.velocity = 10 * (trace_endpos - self.camera.origin);
};