Doors with Doom 3 logic

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
DOOMGABR [RU]
Posts: 97
Joined: Wed Jun 08, 2016 1:25 pm
Location: Russia
Contact:

Doors with Doom 3 logic

Post by DOOMGABR [RU] »

Hey! How to realize smart door opening/closing like in Doom 3? When player in range of door it must open and check player's presence in door's range. Door must close only after player is out of range and open again if player in door's range while it closing. I was trying using simple open/close lines, but thing is player can out of door's range while door is opening/closing.
old example:
https://imgur.com/a/bhWERd8
p.s.: sorry for terrible English
User avatar
Enjay
 
 
Posts: 26534
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Doors with Doom 3 logic

Post by Enjay »

I wonder if some sort of "motion sensor" actor could be possible? i.e. an invisible actor placed near the door that looks for the player; if the player is within a certain distance of the actor, it opens the door (via ACS or ZScript (if that can be done)), if the player moves out of that distance, the door can close.
DOOMGABR [RU]
Posts: 97
Joined: Wed Jun 08, 2016 1:25 pm
Location: Russia
Contact:

Re: Doors with Doom 3 logic

Post by DOOMGABR [RU] »

Yes, good thinking. How to realize this actor?
TheSeventh
Posts: 15
Joined: Wed Oct 24, 2018 9:04 am
Location: +NOGRAVY

Re: Doors with Doom 3 logic

Post by TheSeventh »

I just threw this together with an edit to the CheckProximity example from the wiki. I'm sure you could use A_LookEx and state jumps which trigger ACS_NamedExecute but I figured since you would have to resort to ACS anyway to alter the map I thought it was better to start there instead.

Tag 1 is the door sector and Tag 2 is the MapSpot which I placed in the doorframe but you could easily place it anywhere else and it should function appropriately.

Code: Select all

#include "zcommon.acs"

Script "AutomaticDoor" Enter
{
	if (CheckProximity(2,"DoomPlayer",256.0, 1) )//The 2 here is the mapspot
		{
		Door_Open(1, 60);//Open the door
		}
	else
	 	{
	 	Door_Close(1, 60);//And close it when the player isn't there.
	 	}
	delay(35);
	restart;
}
I'm not sure if it's good practice to reference "DoomPlayer" here or if it would be better to look for "PlayerPawn" or something like that but for vanilla doom this works and you could probably use a modded playerpawn name instead if you were using one.

The .zip is an example map I threw together to demonstrate the script.
Attachments
Example.zip
(1.51 KiB) Downloaded 29 times
Nerotrobe
Posts: 2
Joined: Thu Jun 04, 2020 12:11 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Doors with Doom 3 logic

Post by Nerotrobe »

I'm attempting to do something with CheckProcimity to see if the player is nearby I thought I used it wrong until I found this thread. The example provided by TheSeventh works flawlessly when I run his example.wad but if I rebuild his level or use his script in my level it always returns false for the proximity check. Running latest nightly GZDoom build.
User avatar
Cherno
Posts: 1311
Joined: Tue Dec 06, 2016 11:25 am

Re: Doors with Doom 3 logic

Post by Cherno »

It's certainly possible, I created a door like this for my Hired Guns TC. The door consists of the door itself, which is an actor, and a "blocker", which is the door's child and handles activation. So, when a player of monster collides with the blocker, the blocker will either reset the door's closing timer if it's open, or start the opening process (or reverse the closing process). There may be problems with hitscan attacks, I can't remember to be honest.

Here is the door blocker code.

Code: Select all

class HG_DoorBlocker : SwitchableDecoration
{
	HG_DoorBase door;
	bool doorWasBlocked;

	Default
	{
			radius 40;
			height 80;
	
			RenderStyle "None";
	
			+SOLID
			+NOGRAVITY
			
			
			Activation THINGSPEC_MonsterTrigger | THINGSPEC_Switch;
			+BUMPSPECIAL
			//+USESPECIAL
	}
	
	override bool cancollidewith (actor other, bool passive)
	{
		if(passive == true && other != null)
		{
			if(other.health > 0 && other.bSOLID == true && (PlayerPawn(other) != null || other.bISMONSTER == true))
			{
				if(door != null)
				{
					door.blocked = true;
					if(door.isOpen == false || door.closing == true)
					{
						door.Activate(other);
					}
				}
				
			}
		}
		
		return false;
	}
	
	int doorBlockTimer;
	
	override void Tick()
	{
		Super.Tick();
		if(door != null)
		{
			if(door.blocked == true)
			{
				if(doorBlockTimer < 4)
				{
					doorBlockTimer++;
					if(doorBlockTimer >= 4)
					{
						door.blocked = false;
						doorBlockTimer = 0;
					}
				}
				
			}
		}
	}
	
	/*
	override void Tick()
	{
		Super.Tick();
		if(master)
		{
			HG_DoorBase door = HG_DoorBase(master);
			if(door.isOpen == true)
			{
				//RadiusGive?
				if(CheckProximity("PlayerPawn", 45.0, 1, CPXF_ANCESTOR))
				{
					door.blocked = true;
					//A_Log("blocked");
				}
				else {
					door.blocked = false;
					//A_Log("not blocked");
				}
			}
		}
	}
	*/
	
	override void Activate(Actor activator)
	{
		if(activator != null)
		{
			if(abs(activator.pos.z - self.pos.z) > 80)
			{
				return;
			}
		}
		if(master)
		{
			master.Activate(activator);
		}
	}
	
	override void Deactivate(Actor activator)
	{
		Activate(activator);
	}

	States
	{
		Spawn:	
		FRAM A 1;
		Loop;
	}
}
Post Reply

Return to “Scripting”