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.

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!)
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Scripting a monster that only moves when out of sight

Post by Hidden Hands »

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

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

Post by Cherno »

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.
doomplayer
Posts: 8
Joined: Thu Oct 10, 2019 10:53 pm

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

Post by doomplayer »

you can do something like this:

Code: Select all


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;
		
	}

}
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

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

Post by Hidden Hands »

Wow nice thank you! I'll try this out a little later.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

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

Post by Hidden Hands »

doomplayer wrote:you can do something like this:

Code: Select all


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?
Attachments
Why is this happening?
Why is this happening?
SanyaWaffles
Posts: 800
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

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

Post by SanyaWaffles »

Can't troubleshoot a screenshot easily.

It looks like you'e not inheriting from actor though.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

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

Post by Hidden Hands »

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 all

petrifiedgargoyle : petrogoyle replaces revenant
???
SanyaWaffles
Posts: 800
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

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

Post by SanyaWaffles »

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
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

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

Post by Hidden Hands »

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.
Guest

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

Post by Guest »

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.
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

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

Post by MFG38 »

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 all

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 all

doomednums
{
    9999 = PetrifiedGargoyle
}
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

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

Post by Hidden Hands »

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.
doomplayer
Posts: 8
Joined: Thu Oct 10, 2019 10:53 pm

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

Post by doomplayer »

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"
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

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

Post by Hidden Hands »

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 all

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 all

DoomEdNums
{
    3948 = Petrogoyle
}
Here is my main ZSCRIPT in the root folder.

Code: Select all

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
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

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

Post by MFG38 »

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.
Post Reply

Return to “Scripting”