# Jedi Knight Cog Script
#
# prl_doorswitch-delay.cog
# 00_DOORSWITCH.COG modified by Sylvicolus [PRL] 31 January 2002
#
# In this version each door opens and a bit after the previous one(s).
# Set time delay in variable: doorwait
# Then after sleeptime the doors start closing one by one.
#
# Up to 4 Doors handled by up to 4 switches.
# switch3 is shootable.
#
# This cog is not supported by LucasArts Entertainment Co.
symbols
message startup
message activated
message damaged
message arrived
message blocked
thing door0 linkid=1
thing door1 linkid=1
thing door2 linkid=1
thing door3 linkid=1
surface switch0 linkid=2
surface switch1 linkid=2
surface switch2 linkid=2
surface switch3 linkid=2 mask=0x448
flex movespeed=8.0
flex sleeptime=2.0
flex lightvalue=0.5
flex doorwait=1.0
sound onSound=set_hi2.wav local
sound offSound=lgclick1.wav local
sound locksound=df_door2-3.wav local
int doorsector local
int numdoors=0 local
int doorstatus=0 local
int movestatus=0 local
end
# ========================================================
code
startup:
player = jkGetLocalPlayer();
for (i=0; i<=3; i=i+1) if (door0[i] >= 0)
{
numDoors = numDoors + 1;
doorSector = GetThingSector(door0[i]);
SetSectorAdjoins(doorSector, 0);
SetSectorLight(doorSector, lightValue, 0.0);
}
return;
damaged: //for shootable switch
activated:
if (GetSenderId() == 1) //door
{
PlaySoundThing(locksound, GetThingPos(GetSenderRef()), 1, -1, -1, 0 );
}
else if (GetSenderId() == 2) //switch
{
call checkstatus;
if (movestatus == 0 && doorstatus == 0) // all doors closed
{
PlaySoundPos(onSound, SurfaceCenter(GetSenderRef()), 0.6, -1, -1, 0 );
call open_doors;
}
}
return;
arrived:
call checkstatus;
if (movestatus) return;
if (doorstatus == numdoors) // all doors open
{
sleep(sleeptime);
call close_doors;
}
else if (doorstatus == 0) // all doors closed
{
PlaySoundPos(offSound, SurfaceCenter(GetSenderRef()), 0.6, -1, -1, 0 );
for (i=0; i<=3; i=i+1) if (switch0[i] >= 0) setwallcel(switch0[i], 0);
for (i=0; i<=3; i=i+1) if (door0[i] >= 0)
{
doorSector = GetThingSector(door0[i]);
SetSectorAdjoins(doorSector, 0);
}
}
return;
blocked:
for (i=0; i<=3; i=i+1) if (door0[i] >= 0) movetoframe(door0[i], 1, movespeed);
return;
open_doors:
for (i=0; i<=3; i=i+1) if (switch0[i] >= 0) setwallcel(switch0[i], 1);
for (i=0; i<=3; i=i+1) if (door0[i] >= 0)
{
doorSector = GetThingSector(door0[i]);
SetSectorAdjoins(doorSector, 1);
movetoframe(door0[i], 1, movespeed);
sleep(doorwait);
}
return;
close_doors:
for (i=0; i<=3; i=i+1) if (door0[i] >= 0)
{
movetoframe(door0[i], 0, movespeed);
sleep(doorwait);
}
return;
checkstatus:
movestatus = 0;
for (i=0; i<=3; i=i+1) if (door0[i] >= 0)
{
movestatus = movestatus + ismoving(door0[i]);
}
doorstatus = 0;
for (i=0; i<=3; i=i+1) if (door0[i] >= 0)
{
doorstatus = doorstatus + getcurframe(door0[i]);
}
return;
end
|