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.

Doors with Doom 3 logic

Postby DOOMGABR [RU] » Thu Nov 01, 2018 12:00 pm

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
DOOMGABR [RU]
 
Joined: 08 Jun 2016
Location: Russia

Re: Doors with Doom 3 logic

Postby Enjay » Thu Nov 01, 2018 1:55 pm

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.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: Doors with Doom 3 logic

Postby DOOMGABR [RU] » Thu Nov 01, 2018 2:32 pm

Yes, good thinking. How to realize this actor?
DOOMGABR [RU]
 
Joined: 08 Jun 2016
Location: Russia

Re: Doors with Doom 3 logic

Postby TheSeventh » Wed Nov 14, 2018 5:49 pm

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 allExpand view
#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.
You do not have the required permissions to view the files attached to this post.
TheSeventh
 
Joined: 24 Oct 2018
Location: +NOGRAVY

Re: Doors with Doom 3 logic

Postby Nerotrobe » Mon Jun 08, 2020 4:45 pm

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.
Nerotrobe
 
Joined: 04 Jun 2020
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Doors with Doom 3 logic

Postby Cherno » Mon Jun 08, 2020 5:12 pm

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 allExpand view
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;
   }
}
User avatar
Cherno
 
Joined: 06 Dec 2016


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests