Single camera for viewscreen -- prl_singlecam.cog
I developed this camera cog for use with one viewscreen (optional switch) and one camera. This is for single player only. If camera is destroyed then the view is from the "disabledcamera" which is a camera pointing at a surface with an animated mat of static. This mat is included in the download. April 2001

# Jedi Knight Cog Script - MOTS
#
# prl_singlecam.cog
# Sylvicolus [PRL] April 2001
#
# Modification of 00_unicam.cog with code from 00_securitycam.cog and other camera cogs.
# Single camera cog for single player game. 
# Responds to playeraction, activated by spacebar, player can fire.
# Camera switched off if player hit or moved.
# If camera is destroyed then the view is from the disabledCamera.
# Have disabledCamera thing looking at static animated mat.
#
# This cog is not supported by LucasArts Entertainment Co.

symbols

message	startup
message	activated
message	playeraction
message	pulse
message	killed

surface	ViewSwitch
surface	ScreenTrigger
thing	camera
thing	disabledCamera                   nolink
int	player                           local
int	old_camera                       local
int	active=0                         local
int	camdead=0                        local
int	startHealth=0.0                  local
vector	startPosition                    local
int	triggerSource                    local
int	dummy                            local
sound	SwitchOnSound=activate02.wav     local
sound	SwitchOffSound=deactivate04.wav  local
sound	camChangeSnd=beep2.wav           local

end

# ========================================================

code

startup:
	player = GetLocalPlayerThing();
	SetWallCel(ViewSwitch, 0);
	return;

activated: 
	if(GetCurWeapon(player) == 13) return; //can't use scope at same time
	if(active) return;
	active = 1;
	SetActorFlags(player, 0x80800000);
	StopThing(player);
	SetActionCog(GetSelfCog(), 0x7FFFFFFF); //make cog respond to playeraction
	startHealth = GetThingHealth(player);
	startPosition = GetThingPos(player);
	SetPulse(0.5);
	SetWallCel(ViewSwitch, 1);
	dummy = PlaySoundLocal(SwitchOnSound, 1.0, 0.0, 0);
	old_camera = GetCurrentCamera();
	SetCurrentCamera(0);
	call show_cam;
	return;

playeraction:
	if (GetParam(0) == 2.0)	// Activated
	{
		call stop_cam;
		ReturnEx(0.0);
	}
	else if (GetParam(0) == 3.0)	// Fire
	{
		ReturnEx(1.0); // Allow the player to fire...
	}
	else if (GetParam(0) == 14.0)	// Other Actions
	{
		ReturnEx(1.0);
	}
	else
	{
		ReturnEx(0.0);
	}
	return;

pulse:
	// check that the player didn't die
	if(GetThingHealth(player) < 1)
	{
		call stop_cam;
		return;
	}
	// If he took damage to health stop the camera
	if(GetThingHealth(player) < startHealth)
	{
		call stop_cam;
		return;
	}
	// If he changed position (blown by explosion, pushed, ...) stop the camera
	if(!VectorEqual(startPosition, GetThingPos(player)))
	{
		call stop_cam;
		return;
	}
	// check that the camera didn't die
	if(camdead)
	{
		SetCameraFocus(0, camera);
		return;
	}
	return;

show_cam:
	dummy = PlaySoundLocal(camChangeSnd, 1.0, 0.0, 0);
	SetCameraFocus(0, camera);
	return;

stop_cam:
	if(active)
	{
		SetCameraFocus(0, player);
		SetCurrentCamera(old_camera);
	}
	SetPulse(0);
	active = 0;
	SetWallCel(ViewSwitch,0);
	dummy = PlaySoundLocal(SwitchOffSound, 1.0, 0.0, 0);
	// Turn off control capture.
	SetActionCog(-1, 0);
	ClearActorFlags(player, 0x80800000);
	return;

killed:
	camera = disabledCamera;
	camdead = 1;
	return;

end