Door needs key to open -- prl_keydoor.cog
This is a cog for one door that needs a key to open. There are no switches and AI can always open door. There are two voice sounds played the first and second time the door is activated without the key. Replace these with other wavs as desired or delete them (and the print(); statements) from the cog. Example wavs are given below for Kyle and Mara Jade. 22 July 2001

# Jedi Knight Cog Script - MOTS
#
# prl_keydoor.cog
# Sylvicolus [PRL] 28 FEB 2002
#
# Use 0 for Red Key
# Use 1 for Blue Key
# Use 2 for Yellow Key
#
# Door opened with a key, no switch.
# AI can always open door.
# Two voice lines are spoken by player.
# Examples for "locked" and "I need a key"
# kk60026.wav and kk60021.wav
# kk60027.wav and kk60020.wav
# mj61027.wav and mj61021.wav
# mj61026.wav and mj61020.wav
#
# This cog is not supported by LucasArts Entertainment Co.


symbols

message	startup
message	activate
message	touched
message	arrived
message	blocked
message	timer

thing	door0	linkid=0 mask=0x405
flex	movespeed=3.0
flex	sleeptime=2.0
flex	lightvalue=0.7
int	key=2
sound	sayfirst=kk60026.wav	desc=Locked
sound	saysecond=kk60021.wav	desc=I_need_a_key
sound	doorclick=lvrclik2.wav
int	say=1		local
sector	doorsector	local
int	player		local
flex	lasttime=-1	local
flex	curtime=-1	local

end

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

code

startup:
	doorsector = GetThingSector(door0);
	SectorAdjoins(doorsector, 0);
	SectorLight(doorsector, lightvalue, 0.0); // add some light to door sector
	player = jkGetLocalPlayer();
	return;

touched:
	if (GetSourceRef() == player) return; //AI can activate doors with touch
activate:
	if ((GetInv(player, 46 + key) == 1.0) || (GetSourceRef() != player))  
	{        // if player has the needed key or enemy triggers door
		if(IsThingMoving(door0)) return;
		if(GetCurFrame(door0) == 0)
		{      // door is at frame 0
			SectorAdjoins(doorsector, 1);
			MoveToFrame(door0, 1, movespeed);
			if (GetSourceRef() == player)
			{  // show the key icon for 2 seconds
				SetInvActivated(player, 46 + key, 1); 
				SetTimerEx(2, 1, 0, 0);
			}
		}
	}
	else
	{
		sleep(0.5);
		PlaySoundThing(doorclick, door0, 1.0, -1, -1, 0);
		curtime = GetLevelTime();
		if( (lasttime == -1) || (curtime - lasttime > 15) )
		{
			sleep(1.0);
			if (say==1)
			{
				PlaySoundThing(sayfirst, player, 1.0, -1, -1, 0);
				print("locked");
				say=2;
			} 
			else
			{
				PlaySoundThing(saysecond, player, 1.0, -1, -1, 0);
				print("I need a key");
				say=1;
				lasttime = curtime;
			}
		}
	}
	return;

arrived:
	if(IsThingMoving(door0)) return;
	if(GetCurFrame(door0) == 1)       // door is at frame 1
	{
		sleep(sleeptime);
		MoveToFrame(door0, 0, movespeed);
	}
	else if(GetCurFrame(door0) == 0)	// door is at frame 0
	{
		sectoradjoins(doorsector, 0);
	}
	return;

blocked:
	MoveToFrame(door0, 1, movespeed);
	return;

timer:	// Remove the key icon
	SetInvActivated(player, 46 + key, 0);
	return;

end