Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
zzzornbringer

feel free to use: small script to open and close door with one button

Recommended Posts

this is just a small experiment. i wanted to have a door that you can open via a button and when it's opened, you can push the button to close it again.

 

here's the script:

 


#include "zcommon.acs"

int door1; //global variable

script 1 (void)
{
int delay1=35; //that's just to prevent spamming the button
switch (door1)
{
case 1:
door_close(1,32,0); //closes the door with tid 1,
door1=0; //you can basically put this to any value except 1, because we're using the default case
delay(delay1);
break;

default: //default action if neither of above number(s) is true. this is triggered the first time you push the button
door_open(1,32,0); //opens the door with tid 1
door1=1; //set door1 value to 1 so that case 1 gets triggered the next time the button is pushed
delay(delay1);
break;
}
}

Share this post


Link to post

You could make the script a lot simpler by using the Suspend function. Then you don't even need the global variable.

#include "zcommon.acs"

Script 1 (void)
{
	Door_Open(1, 32, 0);
	TagWait(1);
	
	Suspend;

	Door_Close(1, 32, 0);
	TagWait(1);
}

..or if you want a script that can be re-used by multiple different doors, it could be done like so:

Spoiler

#include "zcommon.acs"

world int 1:doorstate[]; //0=closed, 1=open, 2=busy

//Use with 84:ACS_ExecuteWithResult(1, tag, speed, wait)
Script 1 (int tag, int speed, int wait)
{
	switch(doorstate[tag])
	{
		case 0: //Door is closed
			doorstate[tag] = 2;
			Door_Open(tag, speed, 0);
			TagWait(tag); Delay(wait);
			doorstate[tag] = 1;
			break;

		case 1: //Door is open
			doorstate[tag] = 2;
			Door_Close(tag, speed, 0);
			TagWait(tag); Delay(wait);
			doorstate[tag] = 0;
			break;

		case 2: //Door is busy
		default: SetResultValue(0); //Prevent switch animation
	}
}

 

 

Share this post


Link to post
7 hours ago, TheMightyHeracross said:

I thought Doom doors did this by default?


EDIT: Hmm, apparently only in Doom format maps.

No, they don't, and especially not in Doom format maps. These scripts open the door and let it stay open infinitely, until the script is triggered again, where it closes  the door.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×