Scripting a monster that only moves when out of sight
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!)
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!)
- 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
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.
Thanks in advance.
Re: Scripting a monster that only moves when out of sight
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.
-
- Posts: 8
- Joined: Thu Oct 10, 2019 10:53 pm
Re: Scripting a monster that only moves when out of sight
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;
}
}
- 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
Wow nice thank you! I'll try this out a little later.
- 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
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?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; } }
EDIT: I've attached a screenshot of my fatal error. Please help?
-
- 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
Can't troubleshoot a screenshot easily.
It looks like you'e not inheriting from actor though.
It looks like you'e not inheriting from actor though.
- 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
Ah. Could it be because I type it like this:SanyaWaffles wrote:Can't troubleshoot a screenshot easily.
It looks like you'e not inheriting from actor though.
Code: Select all
petrifiedgargoyle : petrogoyle replaces revenant
-
- 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
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.
- 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
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.
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.
Re: Scripting a monster that only moves when out of sight
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.
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.
- 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
That would involve a check using the angle of the player relative to the monster. Something like this: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.
Code: Select all
if(player.angle == self.angle)
{
(insert your attack code here)
}
It's pretty simple, just make a MAPINFO lump and add a DoomEd number definition for the monster into it, like so: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?
Code: Select all
doomednums
{
9999 = PetrifiedGargoyle
}
- 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
The code is pretty much the same.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.
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.
-
- Posts: 8
- Joined: Thu Oct 10, 2019 10:53 pm
Re: Scripting a monster that only moves when out of sight
in the missile/melee state of your monster change "goto see" to "goto spawn"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.
- 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
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.
Here is my MAPINFO code.
Here is my main ZSCRIPT in the root folder.
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.
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;
}
}
Code: Select all
DoomEdNums
{
3948 = Petrogoyle
}
Code: Select all
version "3.3.0"
#include "zscript/Petrogoyle"
Hope someone can help me clear all this up.
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.doomplayer wrote:in the missile/melee state of your monster change "goto see" to "goto spawn"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.
- 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
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.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.