Scripting a monster that only moves when out of sight

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.

Scripting a monster that only moves when out of sight

Postby Hidden Hands » Wed Oct 07, 2020 8:22 pm

Can this be done? When observed I want the monster to stay frozen on the spot. The gargoyles in my hell map are going to work that way, only moving about the map when they are not being observed (similar to Weeping Angel's. Can it be done? If so, how?

Thanks in advance.
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby Cherno » Wed Oct 07, 2020 10:33 pm

No problem with ZScript, with things like CheckIfInTargetLOS, DeltaAngle & AngleTo.
Last edited by Cherno on Thu Oct 08, 2020 9:57 am, edited 1 time in total.
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: Scripting a monster that only moves when out of sight

Postby doomplayer » Thu Oct 08, 2020 8:55 am

you can do something like this:

Code: Select allExpand view

Class newzombie : zombieman replaces zombieman {
   
   Default{
      
      ActiveSound "";
      SeeSound "";
   }

   States{
     Spawn:
      TNT1 A 0;
      POSS A 1 A_LookEx(LOF_NOSOUNDCHECK|LOF_NOJUMP);
      POSS A 0 A_JumpIfTargetInLOS("Spawn2");
      POSS A 1 A_Wander();
      goto Spawn;
      
      Spawn2:
         POSS A 1 A_Jumpif(!CheckIfInTargetLOS(120,0,0,0), "See");
      Goto Spawn;
      
      See:
         POSS B 1 A_Wander();
      Goto Spawn;
      
      Pain:
         POSS G 3 A_Pain;
      goto Spawn;
      
   }

}
doomplayer
 
Joined: 11 Oct 2019

Re: Scripting a monster that only moves when out of sight

Postby Hidden Hands » Fri Oct 09, 2020 2:25 pm

Wow nice thank you! I'll try this out a little later.
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby Hidden Hands » Sun Oct 11, 2020 2:51 pm

doomplayer wrote:you can do something like this:

Code: Select allExpand view

Class newzombie : zombieman replaces zombieman {
   
   Default{
      
      ActiveSound "";
      SeeSound "";
   }

   States{
     Spawn:
      TNT1 A 0;
      POSS A 1 A_LookEx(LOF_NOSOUNDCHECK|LOF_NOJUMP);
      POSS A 0 A_JumpIfTargetInLOS("Spawn2");
      POSS A 1 A_Wander();
      goto Spawn;
      
      Spawn2:
         POSS A 1 A_Jumpif(!CheckIfInTargetLOS(120,0,0,0), "See");
      Goto Spawn;
      
      See:
         POSS B 1 A_Wander();
      Goto Spawn;
      
      Pain:
         POSS G 3 A_Pain;
      goto Spawn;
      
   }

}

Ok, I'm about to try this out now. Where exactly should I put my code? Should I make a zscript lump in the PK3 or does this go somewhere else? When I put my code in zscript, it just doesn't boot up. It says 3 errors no warnings zscript. Any help please?

EDIT: I've attached a screenshot of my fatal error. Please help?
You do not have the required permissions to view the files attached to this post.
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby SanyaWaffles » Sun Oct 11, 2020 4:23 pm

Can't troubleshoot a screenshot easily.

It looks like you'e not inheriting from actor though.
User avatar
SanyaWaffles
Wouldn't be an epic gamer if I didn't commit a few war crimes.
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Scripting a monster that only moves when out of sight

Postby Hidden Hands » Sun Oct 11, 2020 5:35 pm

SanyaWaffles wrote:Can't troubleshoot a screenshot easily.

It looks like you'e not inheriting from actor though.


Ah. Could it be because I type it like this:
Code: Select allExpand view
petrifiedgargoyle : petrogoyle replaces revenant


???
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby SanyaWaffles » Sun Oct 11, 2020 7:41 pm

Can you post your entire code and not just a screenshot. As I said, I cannot debug just a screenshot and I certainly cannot troubleshoot a snippet.
User avatar
SanyaWaffles
Wouldn't be an epic gamer if I didn't commit a few war crimes.
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Scripting a monster that only moves when out of sight

Postby Hidden Hands » Mon Oct 12, 2020 9:17 am

Hi I was just about to paste my code but the monster seems to be working now. I just have a couple of questions.

1. So far, the monster does not attack. It moves when out of sight, but is of no threat. How would i code into it so that it can attack when your back is turned? It needs to be able to attack only when not being observed.

2. When I place these in a map, because they replace the Revenant, I have to choose Revanant from the builder. How can I give it it's own name and selection from GZDoom builder? It's easy to do with DECORATE monsters but how would I do this with a zscript monster?

3. I am using a few of these gargoyles to be jumpscare traps. I've placed two outside the church in my level 09 as decoration, and chose dormant flags for them. They are supposed to trigger to active when the player crosses a linedef that runs an ACS script that wakes them up. Problem is, when I set them with a dormant flag, they are invisible. What could be causing this?

Thanks in advance.
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby Varden Tillingspear » Mon Oct 12, 2020 10:04 am

1. I assume it's because the monster uses A_Wander() instead of A_Chase().
Try replacing them with A_Chase.

2. You have to add them in MAPINFO: https://zdoom.org/wiki/MAPINFO/Editor_number_definition

3. It could be because the first frame in the Spawn state is TNT1. Try replacing it with a sprite.

Granted, I am looking at the code doomplayer posted.
Please post your code if it was changed if this doesn't work.
Varden Tillingspear
 

Re: Scripting a monster that only moves when out of sight

Postby MFG38 » Mon Oct 12, 2020 10:52 am

Hidden Hands wrote:1. So far, the monster does not attack. It moves when out of sight, but is of no threat. How would i code into it so that it can attack when your back is turned? It needs to be able to attack only when not being observed.


That would involve a check using the angle of the player relative to the monster. Something like this:

Code: Select allExpand view
if(player.angle == self.angle)
{
    (insert your attack code here)
}


Can't guarantee the exact statement above will work, but it's worth a shot.

Hidden Hands wrote:2. When I place these in a map, because they replace the Revenant, I have to choose Revanant from the builder. How can I give it it's own name and selection from GZDoom builder? It's easy to do with DECORATE monsters but how would I do this with a zscript monster?


It's pretty simple, just make a MAPINFO lump and add a DoomEd number definition for the monster into it, like so:

Code: Select allExpand view
doomednums
{
    9999 = PetrifiedGargoyle
}
User avatar
MFG38
 
Joined: 14 Apr 2019
Location: Finland
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Scripting a monster that only moves when out of sight

Postby Hidden Hands » Mon Oct 12, 2020 11:06 am

Varden Tillingspear wrote:1. I assume it's because the monster uses A_Wander() instead of A_Chase().
Try replacing them with A_Chase.

2. You have to add them in MAPINFO: https://zdoom.org/wiki/MAPINFO/Editor_number_definition

3. It could be because the first frame in the Spawn state is TNT1. Try replacing it with a sprite.

Granted, I am looking at the code doomplayer posted.
Please post your code if it was changed if this doesn't work.
The code is pretty much the same.

I changed A_Wander to A_Chase but now the monster does t freeze when observed. Now it stays in its attacking moving state until its shot at then it returns to stone.

Turning your back on it now wakes it up but it stays active... even when observed. Only shooting st it changes its state.
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby doomplayer » Mon Oct 12, 2020 11:20 am

Hidden Hands wrote:The code is pretty much the same.

I changed A_Wander to A_Chase but now the monster does t freeze when observed. Now it stays in its attacking moving state until its shot at then it returns to stone.

Turning your back on it now wakes it up but it stays active... even when observed. Only shooting st it changes its state.


in the missile/melee state of your monster change "goto see" to "goto spawn"
doomplayer
 
Joined: 11 Oct 2019

Re: Scripting a monster that only moves when out of sight

Postby Hidden Hands » Mon Oct 12, 2020 11:22 am

Ok here is my complete setup. Since I can't seem to get this to work properly, I think this is the only way to explain it.

First, here is my zscript for the gargoyle, located in a folder called zscript in my pk3. ZSCRIPT code.
Code: Select allExpand view
Class Petrogoyle : Revenant replaces Revenant
{
       Default{
         
          ActiveSound "";
          SeeSound "";
       }

       States{
         Spawn:
          TNT1 A 0;
          PGRG A 1 A_LookEx(LOF_NOSOUNDCHECK|LOF_NOJUMP);
          PGRG A 0 A_JumpIfTargetInLOS("Spawn2");
          PGRG A 1 A_Wander();
          goto Spawn;
         
          Spawn2:
             PGRG A 1 A_Jumpif(!CheckIfInTargetLOS(120,0,0,0), "See");
          Goto Spawn;
         
          See:
             PGRG B 1 A_Wander();
          Goto Spawn;
         
          Pain:
             PGRG G 3 A_Pain;
          goto Spawn;
         
       }

    }


Here is my MAPINFO code.
Code: Select allExpand view
DoomEdNums
{
    3948 = Petrogoyle
}


Here is my main ZSCRIPT in the root folder.
Code: Select allExpand view
version "3.3.0"

#include "zscript/Petrogoyle"


The DoomEdNums thing still doesn't show it up in GZDOOM Builder, and the monsters behaviour is very strange. It worked fine with A_Wander but didn't attack, so now I have this issue where it wont freeze when observed. I'm also not sure where to put the attack code in that you posted MFG38, I'm very very very new with zscript.

Hope someone can help me clear all this up.

doomplayer wrote:
Hidden Hands wrote:The code is pretty much the same.

I changed A_Wander to A_Chase but now the monster does t freeze when observed. Now it stays in its attacking moving state until its shot at then it returns to stone.

Turning your back on it now wakes it up but it stays active... even when observed. Only shooting st it changes its state.


in the missile/melee state of your monster change "goto see" to "goto spawn"


Ah, I don't have any attacks in the code. It seems to revert to the revenants ones. As I say I pretty much am useless with zscript, this is probably my first time trying to put a zscript together.
User avatar
Hidden Hands
Deadite
 
Joined: 21 Sep 2016
Location: London, England

Re: Scripting a monster that only moves when out of sight

Postby MFG38 » Mon Oct 12, 2020 11:45 am

Hidden Hands wrote:I'm also not sure where to put the attack code in that you posted MFG38, I'm very very very new with zscript.


For that, I suggest reading up on anonymous functions. They're pretty similar to the standard DECORATE/ZScript functions in that they're attached to specific frames of actors' states, only with the benefit of allowing complex custom logic that the built-in functions can't cover. That's how you'd use the code snippet I posted as well.
User avatar
MFG38
 
Joined: 14 Apr 2019
Location: Finland
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Next

Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests