Openable and closable swinging doors

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Openable and closable swinging doors

Post by cocka »

Hello!

I've created a special swinging door which opens and won't budge until you press the use button on either side of the door to close it. This can be easily achieved by the following script:

Code: Select all

int allapot;
script 5 (int polyid, int speed)
{
if(allapot == 0)
   {
   polywait(polyid);
   delay(3);
   Polyobj_OR_RotateRight(polyid, -speed, 60);
   allapot = 1;
   }
else
   {
   polywait(polyid);
   delay(3);
   Polyobj_OR_RotateRight(polyid, speed, 60);
   allapot = 0;
   }
}
Though, this script works for only one door correctly. Once you have two or more doors with different polyids and you open either of the doors, the integer allapot remains 1, and as a result the other closed door opens in the opposite direction. This is undesirable.

I'd like to have several swinging doors working correctly (as I mentioned in the first sentence) around the map but I don't know how to write a script which can be used as an universal one and doesn't mess up the opening directions of the doors and cause the door to move into the wall repeatedly. Do you have any suggestions for this?
Blue Shadow
Posts: 5040
Joined: Sun Nov 14, 2010 12:59 am

Re: Openable and closable swinging doors

Post by Blue Shadow »

Made some changes to your script...

Code: Select all

#define SWINGING_DOORS 10 // Maximum number of swinging doors. Make sure its greater than or equal to the number of swinging doors you're using. If you're using fewer doors than that number then no change is required.

bool allapot[SWINGING_DOORS]; // An array that will hold each door "status" in its elements

script 5 (int polyid, int speed)
{
  // "polyid" is utilized to identify the doors when checking on their status, i.e, polyid of 1 is swinging door #1
  if(!allapot[polyid - 1])
  {
    polywait(polyid);
    delay(3);
    Polyobj_OR_RotateRight(polyid, -speed, 60);
    allapot[polyid - 1] = TRUE;
  }

  else
  {
    polywait(polyid);
    delay(3);
    Polyobj_OR_RotateRight(polyid, speed, 60);
    allapot[polyid - 1] = FALSE;
  }
}
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Openable and closable swinging doors

Post by cocka »

Thank you very much! I'm going to try this new one of course. :)
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Openable and closable swinging doors

Post by cocka »

There are two doors on the map with polyid 5 and polyid 49, so I had to change the value to 49. bool is just an integer type with values 0 and 1, isn't it?

Just to clarify the meaning of the script:

allapot[SWINGING_DOORS] means that you have an array called allapot, and the number of elements in the array is equal to (in this case) 10. The elements in the array consist of ten zeros and the indices run from 0-9.

Is this: if(!allapot[polyid - 1]) the same as if(allapot[polyid -1] == 0) ?

[polyid - 1] Does this refer to the index variable for the polyid?
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Openable and closable swinging doors

Post by FDARI »

You are correct on all points.
The script expects you to work with a range of up to (in this case) 10 polyids in sequence. The "-1" translates polyids in the range 1-10 to array indices in the range 0-9. (I know I'm being obvious.)
If you want to support a higher range of consecutive polyids instead, I recommend defining a constant to identify the lowest polyid. Minor change:

Code: Select all

#define SWINGING_DOORS 10 // Maximum number of swinging doors. Make sure its greater than or equal to the number of swinging doors you're using. If you're using fewer doors than that number then no change is required.
#define SWINGING_DOORS_FIRST 1 // first swinging door in a set of consecutive polyids

bool allapot[SWINGING_DOORS]; // An array that will hold each door "status" in its elements

script 5 (int polyid, int speed)
{
  // "polyid" is utilized to identify the doors when checking on their status, i.e, polyid of (SWINGING_DOORS_FIRST) is swinging door #1
  if(!allapot[polyid - SWINGING_DOORS_FIRST])
  {
    polywait(polyid);
    delay(3);
    Polyobj_OR_RotateRight(polyid, -speed, 60);
    allapot[polyid - SWINGING_DOORS_FIRST] = TRUE;
  }

  else
  {
    polywait(polyid);
    delay(3);
    Polyobj_OR_RotateRight(polyid, speed, 60);
    allapot[polyid - SWINGING_DOORS_FIRST] = FALSE;
  }
}
(If you want to use the array with polyids 49-58 you just change one line: #define SWINGING_DOORS_FIRST 49)
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Openable and closable swinging doors

Post by cocka »

Thank you for your help. :)
Locked

Return to “Editing (Archive)”