Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Doubledoor elevator cog
Doubledoor elevator cog
2008-07-22, 9:51 AM #1
I need a cog that controls double doors and an elevator. The floor that the elevator is present at will have its doors open until someone presses the switch in the elevator or the call button on another floor. Once pressed just like a normal elevator in real life, the doors shut and the elevator travels to the other floor and the doors on that floor only open. The doors on the previous floor/s remain closed.

Below I will post the current cog that I have been using to control a single elevator with 1 door on each floor, 2 elevator shaft switches and 1 switch on the opposite side of each door.

My cog knowledge is very small. I know this is probably simple for many but if someone could help me out, I just need the additional code added so that I can have double doors on each floor rather than just a single door.

Code will be in my next post.
2008-07-22, 9:51 AM #2
Code:
# Jedi Knight Cog Script
#
# 2 stop elevator with door and call functions, kludged to work with
# concave 4x4 lift.
# Written By DS
# This COG controls an elevator and two doors between
# 2 stops (0 and 1). The elevator's stop on startup should
# be floor 0.

# doug0 and doug1 are call buttons for each floor.
# They should be outside the elevator. Move0 and Move1 are
# buttons that will move the elevator to the next floor. They
# should be inside the elevator. Door0 and Door1 are the doors
# for each floor. Both doors should be closed, this script will
# open door0 at startup.
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

symbols
message         startup
message         arrived
message         activated

thing           Elev            linkid=6
thing           door0           linkid=11
thing           door1           linkid=12
thing           crate           nolink
thing                 crate2              nolink

surface         doug0           linkid=0
surface         doug1           linkid=1
surface         move0           linkid=5
surface         move1           linkid=5

flex            elev_speed=4.0
flex            door_speed=4.0
int             movestatus=0               local
sound                 wav0=beep1.wav
end

## Code Section
# There are 5 steps this script performs. They are:
#  0  Waiting for a trigger
#  1  Closing the open door
#  2  Moving elevator to the next floor
#  3  Opening the door
#  4  Resetting the switches and repeat

# The variable Movestatus is used in order to keep track of
# what step the COG is currently on.

## Code Section
# =================================================================================================

code

# .................................................................................................

startup:
   #open door at startup and disable adjoins
   movetoframe(door0,1,door_speed);
   attachthingtothing(crate, elev);
    attachthingtothing(crate2,elev);
   setthingattachflags(crate,8);
    setthingattachflags(crate2,8);
   sectoradjoins(getthingsector(door1), 0);
   return;

# .................................................................................................

activated:
   if (GetSenderRef()==Elev) Return;
   if (movestatus==0)
        {
    PlaySoundPos(wav0, SurfaceCenter(doug0), 1.0, -1, -1, 0);    
    PlaySoundPos(wav0, SurfaceCenter(doug1), 1.0, -1, -1, 0);
    PlaySoundPos(wav0, SurfaceCenter(move0), 1.0, -1, -1, 0);
    PlaySoundPos(wav0, SurfaceCenter(move1), 1.0, -1, -1, 0);
   if (getsenderid()<2) call callfloor;
   else if (getsenderid()==5) call closedoor;
   }
   return;

# .................................................................................................

arrived:
   #This handles switching from one step to the next.
   if (movestatus==3) call opendoor;
   else if (movestatus==2) call move_elev;
   else if (movestatus==4) call resetstatus;
   return;

# .................................................................................................

callfloor:
   #Calls the elevator to the other floor.
   if (getsenderid()!=getcurframe(elev))call closedoor;
   return;

# .................................................................................................

closedoor:
   if (getcurframe(elev)==0) movetoframe(door0,0,door_speed);
   else if (getcurframe(elev)==1) movetoframe(door1,0,door_speed);
        setwallcel(doug0,1);
        setwallcel(doug1,1);
   setwallcel(move0,1);
   setwallcel(move1,1);
   movestatus=2;
   return;

# .................................................................................................

opendoor:
   if (getcurframe(elev)==0)
      {
      sectoradjoins(getthingsector(door0), 1);
      movetoframe(door0,1,door_speed);
      }
   else if (getcurframe(elev)==1)
      {
      sectoradjoins(getthingsector(door1), 1);
      movetoframe(door1,1,door_speed);
      }
   movestatus=4;
   return;

# .................................................................................................

resetstatus:
        setwallcel(doug0,0);
        setwallcel(doug1,0);
   setwallcel(move0,0);
   setwallcel(move1,0);
   movestatus=0;
   return;

# .................................................................................................

move_elev:
   if (getcurframe(elev)==0)
      {
      sectoradjoins(getthingsector(door0), 0);
      movetoframe(elev,1,elev_speed);
      }
   else if (getcurframe(elev)==1)
      {
      sectoradjoins(getthingsector(door1), 0);
      movetoframe(elev,0,elev_speed);
      }
   movestatus=3;
   return;
end


[Edit: code tags]
2008-07-25, 6:59 AM #3
Hi

I was going to leave this for a less-rusty cogger, but they don't seem to be piping up.

I've added in support for double doors, I made a quick level and checked it worked, but let me know. The doors are now door0/door0_2 and door1/door1_2. I've commented the small changes, it's well worth your while to learn cog.

GHORG

Code:
# Jedi Knight Cog Script
#
# 2 stop elevator with door and call functions, kludged to work with
# concave 4x4 lift.
# Written By DS
# This COG controls an elevator and two doors between
# 2 stops (0 and 1). The elevator's stop on startup should
# be floor 0.

# doug0 and doug1 are call buttons for each floor.
# They should be outside the elevator. Move0 and Move1 are
# buttons that will move the elevator to the next floor. They
# should be inside the elevator. Door0 and Door1 are the doors
# for each floor. Both doors should be closed, this script will
# open door0 at startup.
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

symbols
message         startup
message         arrived
message         activated

thing           Elev            linkid=6
thing           door0           linkid=11
thing		door0_2		nolink
thing           door1           linkid=12
thing		door1_2		nolink
thing           crate           nolink
thing                 crate2              nolink

surface         doug0           linkid=0
surface         doug1           linkid=1
surface         move0           linkid=5
surface         move1           linkid=5

flex            elev_speed=4.0
flex            door_speed=4.0
int             movestatus=0               local
sound                 wav0=beep1.wav
end

## Code Section
# There are 5 steps this script performs. They are:
#  0  Waiting for a trigger
#  1  Closing the open door
#  2  Moving elevator to the next floor
#  3  Opening the door
#  4  Resetting the switches and repeat

# The variable Movestatus is used in order to keep track of
# what step the COG is currently on.

## Code Section
# =================================================================================================

code

# .................................................................................................

startup:
   #open door at startup and disable adjoins
   movetoframe(door0,1,door_speed);
   movetoframe(door0_2,1,door_speed);
// door0_2 opened as well

   attachthingtothing(crate, elev);
    attachthingtothing(crate2,elev);
   setthingattachflags(crate,8);
    setthingattachflags(crate2,8);
   sectoradjoins(getthingsector(door1), 0);
   return;

# .................................................................................................

activated:
   if (GetSenderRef()==Elev) Return;
   if (movestatus==0)
        {
    PlaySoundPos(wav0, SurfaceCenter(doug0), 1.0, -1, -1, 0);    
    PlaySoundPos(wav0, SurfaceCenter(doug1), 1.0, -1, -1, 0);
    PlaySoundPos(wav0, SurfaceCenter(move0), 1.0, -1, -1, 0);
    PlaySoundPos(wav0, SurfaceCenter(move1), 1.0, -1, -1, 0);
   if (getsenderid()<2) call callfloor;
   else if (getsenderid()==5) call closedoor;
   }
   return;

# .................................................................................................

arrived:
   #This handles switching from one step to the next.
   if (movestatus==3) call opendoor;
   else if (movestatus==2) call move_elev;
   else if (movestatus==4) call resetstatus;
   return;

# .................................................................................................

callfloor:
   #Calls the elevator to the other floor.
   if (getsenderid()!=getcurframe(elev))call closedoor;
   return;

# .................................................................................................

closedoor:
   if (getcurframe(elev)==0)
	{
	movetoframe(door0,0,door_speed);
	movetoframe(door0_2,0,door_speed);
	}
   else if (getcurframe(elev)==1)
	{
	movetoframe(door1,0,door_speed);
	movetoframe(door1_2,0,door_speed);
	}
        setwallcel(doug0,1);
        setwallcel(doug1,1);
   setwallcel(move0,1);
   setwallcel(move1,1);
   movestatus=2;
   return;

# .................................................................................................

opendoor:
   if (getcurframe(elev)==0)
      {
      sectoradjoins(getthingsector(door0), 1);
      movetoframe(door0,1,door_speed);
      movetoframe(door0_2,1,door_speed);
// this part changed, door0_2 opened as well
      }
   else if (getcurframe(elev)==1)
      {
      sectoradjoins(getthingsector(door1), 1);
      movetoframe(door1,1,door_speed);
      movetoframe(door1_2,1,door_speed);
// this part changed, door1_2 opened as well
      }
   movestatus=4;
   return;

# .................................................................................................

resetstatus:
        setwallcel(doug0,0);
        setwallcel(doug1,0);
   setwallcel(move0,0);
   setwallcel(move1,0);
   movestatus=0;
   return;

# .................................................................................................

move_elev:
   if (getcurframe(elev)==0)
      {
      sectoradjoins(getthingsector(door0), 0);
      movetoframe(elev,1,elev_speed);
      }
   else if (getcurframe(elev)==1)
      {
      sectoradjoins(getthingsector(door1), 0);
      movetoframe(elev,0,elev_speed);
      }
   movestatus=3;
   return;
end
2008-07-26, 11:05 AM #4
If you had posted on jkhub.net, I would have helped. Requesting help on massassi will only get you help from out-dated or retired JK editors.

:)

↑ Up to the top!