Monster that wanders

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:

Monster that wanders

Post by Hidden Hands »

I have asked this before-ish, but I need some help getting a monster to act in a very specific way. I need my monster to NOT chase the player unless it sees them first.

This is what I want.

The monster roams around the room mindlessly. It takes a few steps randomly. It stops, for a few seconds, then randomly moves again. Like imagine it as a horse in a field. Just randomly walking about pausing for a few seconds every now and then.

Then, when it catches sight of the player, it goes into a fast dash towards them on the attack. If you run from the monster, or leave the room, the monster returns to acting mindlessly again roaming and wandering the room and stopping every few seconds.

Best way I can describe this is "think of SCRABS from ODDWORLD. They roam about minding their own business until they see the player then BOOM dash to attack. Can I replicate something like this? They do have to forget the player though when out of sight for a while. I'm writing this monster in ZSCRIPT.

THANKS IN ADVANCE!
User avatar
Enjay
 
 
Posts: 26534
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Monster that wanders

Post by Enjay »

You even hit the name of the pointer in your thread title: [wiki]A_Wander[/wiki]. ;)
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Monster that wanders

Post by Hidden Hands »

I'm having a surprising amount of trouble with this...
Here is my code:

Code: Select all

//wandering variant for natural habitats
class WanderKakos : Cyberdemon replaces Cyberdemon
{
	Default
	{
	//$Category Monsters
    //$Title WanderKakos
		Health 150;
		PainChance 180;
		Speed 10;
		Radius 30;
		Height 56;
		Mass 400;
		Renderstyle "Normal";
		Bloodcolor "Red";
		Monster;
          +DROPOFF
          +FLOORCLIP
          +TELESTOMP
          +DONTHARMCLASS
		SeeSound "photokakos/sight";
        AttackSound "photokakos/melee";
        PainSound "photokakos/pain";
        DeathSound "photokakos/death";
        ActiveSound "photokakos/active";
		Obituary "$OB_DEMONHIT";
		Tag "$FN_DEMON";
	}
	States
	{
	Spawn:
        PHOT AA 3 A_Wander;
        PHOT A 0 A_Look;
        PHOT BB 3 A_Wander;
        PHOT B 0 A_Look;
        PHOT CC 3 A_Wander;
        PHOT C 0 A_Look;
        PHOT DD 3 A_Wander;
        PHOT D 0 A_Look;
		PHOT EE 3 A_Wander;
		PHOT E 0 A_Look;
		PHOT FF 3 A_Wander;
		PHOT F 0 A_Look;
        loop;
	See:
		PHOT ABCDEF 8 Fast A_Chase;
		Loop;
	Melee:
		PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
	    PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
		Goto See;
	Missile:
	    Goto See;
	Pain:
		PHOT J 2 Fast;
		PHOT J 2 Fast A_Pain;
		Goto See;
	Death:
		PHOT Q 8;
		PHOT R 8 A_Scream;
		PHOT S 4;
		PHOT T 4 A_NoBlocking;
		PHOT U 4;
		PHOT V -1;
		Stop;
	Raise:
		PHOT V 5;
		PHOT UTSRQ 5;
		Goto See;
	}
}
The monster still has massive problems. Firstly, it seems to see me right away. I don't want it to be able to see me unless I get close enough.

Secondly, the monster gets sight of the player and relentlesly hunts them down. I only want it to do this until it loses sight of the player then return to its wandering state.

Thirdly, I want the monster to wander, stop for a few seconds, then continue to wander. As it is now, it seems to do none of these things. Please can someone help?? What am I doing wrong here? I'm using ZSCRIPT.

Thanks in advance.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Monster that wanders

Post by wildweasel »

You may be interested in [wiki]A_LookEx[/wiki], which allows you to enforce minimum and maximum see distances, disable sound checks, and narrow its field of view.

It's worth noting A_Wander behaves similarly to A_Chase - just instead of heading in the nearest direction to its target, it moves randomly. In order to make your monster stop, you'll need to write its Look states so that it actually stops. A few tics of A_Wander, then some A_Look with an actual duration, during which it will be looking instead of moving.
User avatar
Enjay
 
 
Posts: 26534
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Monster that wanders

Post by Enjay »

As for the final piece of the jigsaw, I'm almost certain that it would be possible to make the monster lose/forget its target (not sure about DECORATE - maybe, but ZScript almost certainly) but I don't know how to do it. If you combine that functionality with a line of sight check, you would probably be able to get the "I can't see the player any more, so I'll just go back to wandering" effect.

Like I said, I don't know how to do it but I am highly confident that it must be possible. So perhaps someone will have some bright ideas.

Perhaps something from here? viewtopic.php?f=43&t=62232
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Monster that wanders

Post by Hidden Hands »

Ok so my monster now has a field of vision and wanders. BUT I'm still having trouble getting the monster to stop and stand on the spot for a while. Here is my code:

Code: Select all

Spawn:
        PHOT AA 8 A_Wander;
        PHOT A 0 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
        PHOT BB 8 A_Wander;
        PHOT B 0 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
        PHOT CC 8 A_Wander;
        PHOT C 0 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
        PHOT DD 8 A_Wander;
        PHOT D 0 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
		PHOT EE 8 A_Wander;
		PHOT E 0 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
		PHOT FF 8 A_Wander;
		PHOT F 0 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
        loop;
This all works great, except I have no idea how to get it to stop on the spot between wanders. I want it to behave like an animal grazing in a field. Slowly walks about mindlessly and stops from time to time. How would I implement the TICS to A_LOOK? I mean, where about do I put this?
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Monster that wanders

Post by Caligari87 »

use [wiki]A_Jump[/wiki] to randomly jump to a waiting state, then randomly jump back.

Also you can use anonymous functions to clean up your code significantly.

Code: Select all

Spawn:
    PHOT AABBCCDDEEFF 8 {
        A_Wander;
        A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
    }
    PHOT A 0 A_Jump(32,"Wait"); // 12% chance (32/256) to jump after each walk cycle
    loop;

Wait: 
    PHOT AABB 16 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See"); // Slowly animate in place for a couple frames
    PHOT A 0 A_Jump(32,"Spawn"); // 12% chance (32/256) to jump back to wander cycle
    loop;
8-)
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Monster that wanders

Post by Hidden Hands »

Caligari87 wrote:use [wiki]A_Jump[/wiki] to randomly jump to a waiting state, then randomly jump back.

Also you can use anonymous functions to clean up your code significantly.

Code: Select all

Spawn:
    PHOT AABBCCDDEEFF 8 {
        A_Wander;
        A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
    }
    PHOT A 0 A_Jump(32,"Wait"); // 12% chance (32/256) to jump after each walk cycle
    loop;

Wait: 
    PHOT AABB 16 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See"); // Slowly animate in place for a couple frames
    PHOT A 0 A_Jump(32,"Spawn"); // 12% chance (32/256) to jump back to wander cycle
    loop;
8-)
Excellent thatnk you! I am having one issue though. I'm getting this on bootup?

Code: Select all

Texman.Init: Init texture manager.
ParseTeamInfo: Load team definitions.
LoadActors: Load actor definitions.
Script error, "HorryefieingCircleMansion.ipk3:zscript/kakos" line 105:
Unexpected ':'
Expecting ';'
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Monster that wanders

Post by Caligari87 »

my only guess is you're missing a semicolon somewhere before line 105.

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

Re: Monster that wanders

Post by Hidden Hands »

I've been trying to find the error but can't seem to locate it... am I missing something here?

Code: Select all

States
	{
	Spawn:
        PHOT AABBCCDDEEFF 8 {
            A_Wander;
            A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
        }
        PHOT A 0 A_Jump(32,"Wait"); // 12% chance (32/256) to jump after each walk cycle
        loop;
    Wait:
        PHOT AABB 16 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See"); // Slowly animate in place for a couple frames
        PHOT A 0 A_Jump(32,"Spawn"); // 12% chance (32/256) to jump back to wander cycle
        loop;
	See:
		PHOT ABCDEF 8 Fast A_Chase;
		Loop;
	Melee:
		PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
	    PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
		Goto See;
	Missile:
	    Goto See;
	Pain:
		PHOT J 2 Fast;
		PHOT J 2 Fast A_Pain;
		Goto See;
	Death:
		PHOT Q 8;
		PHOT R 8 A_Scream;
		PHOT S 4;
		PHOT T 4 A_NoBlocking;
		PHOT U 4;
		PHOT V -1;
		Stop;
	Raise:
		PHOT V 5;
		PHOT UTSRQ 5;
		Goto Spawn;
	}
}
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: Monster that wanders

Post by MFG38 »

A_Wander should have empty parentheses after it, since it's being called in an anonymous function, like so:

Code: Select all

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

Re: Monster that wanders

Post by Hidden Hands »

I niw have a different error...

Code: Select all

Texman.Init: Init texture manager.
ParseTeamInfo: Load team definitions.
LoadActors: Load actor definitions.
Script error, "HorryefieingCircleMansion.ipk3:zscript/kakos" line 100:
Unexpected ')'
Expecting '-' or '+' or '++' or '--' or '(' or 'class' or identifier or string constant or 'super' or '~' or '!' or 'sizeof' or 'alignof' or integer constant or unsigned constant or float constant or name constant or 'false' or 'true' or 'null'


User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Monster that wanders

Post by ramon.dexter »

...and which line is line 100? Stop showing only snippets of code or error messages!

You are running in circle. When you encounter an error, instantly post the whole affected code, without the need of any of us asking for it. Do you understand?
SanyaWaffles
Posts: 806
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: Monster that wanders

Post by SanyaWaffles »

I have to second ramon here. It's incredibly frustrating to have no context for any of these errors or issues you are getting.

I know the pain of creating minimal examples or showing off code but it is good practice to do so.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Monster that wanders

Post by Hidden Hands »

I'm hard work, right? Sorry about that. Here is my entire ZSCRIPT for the monster that contains the problem. Can anyone see what's causing the error? I've looked it over a lot and can't seem to catch it.

Code: Select all

//===========================================================================
//
// Non-photosensitive Demon
//
//===========================================================================
class Kakos : Fatso replaces Fatso
{
	Default
	{
	//$Category Monsters
    //$Title Kakos
		Health 150;
		PainChance 180;
		Speed 10;
		Radius 30;
		Height 56;
		Mass 400;
		Renderstyle "Normal";
		Bloodcolor "Red";
		Monster;
          +DROPOFF
          +FLOORCLIP
          +TELESTOMP
          +DONTHARMCLASS
		SeeSound "photokakos/sight";
        AttackSound "photokakos/melee";
        PainSound "photokakos/pain";
        DeathSound "photokakos/death";
        ActiveSound "photokakos/active";
		Obituary "$OB_DEMONHIT";
		Tag "$FN_DEMON";
	}
	States
	{
	Spawn:
		PHOT ABCDEF 10 A_Look;
		Loop;
	See:
		PHOT ABCDEF 8 Fast A_Chase;
		Loop;
	Melee:
		PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
	    PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
		Goto See;
	Missile:
	    Goto See;
	Pain:
		PHOT J 2 Fast;
		PHOT J 2 Fast A_Pain;
		Goto See;
	Death:
		PHOT Q 8;
		PHOT R 8 A_Scream;
		PHOT S 4;
		PHOT T 4 A_NoBlocking;
		PHOT U 4;
		PHOT V -1;
		Stop;
	Raise:
		PHOT V 5;
		PHOT UTSRQ 5;
		Goto See;
	}
}

//wandering variant for natural habitats
class WanderKakos : Cyberdemon replaces Cyberdemon
{
	Default
	{
	//$Category Monsters
    //$Title Kakos
		Health 150;
		PainChance 180;
		Speed 10;
		Radius 30;
		Height 56;
		Mass 400;
		Renderstyle "Normal";
		Bloodcolor "Red";
		Monster;
          +DROPOFF
          +FLOORCLIP
          +TELESTOMP
          +DONTHARMCLASS
		SeeSound "photokakos/sight";
        AttackSound "photokakos/melee";
        PainSound "photokakos/pain";
        DeathSound "photokakos/death";
        ActiveSound "photokakos/active";
		Obituary "$OB_DEMONHIT";
		Tag "$FN_DEMON";
	}
	States
	{
	Spawn:
        PHOT AABBCCDDEEFF 8 {
            A_Wander;()
            A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See");
        }
        PHOT A 0 A_Jump(32,"Wait"); // 12% chance (32/256) to jump after each walk cycle
        loop;
    Wait:
        PHOT AABB 16 A_LookEx (LOF_NOSOUNDCHECK, 32, 0, 0, 30, "See"); // Slowly animate in place for a couple frames
        PHOT A 0 A_Jump(32,"Spawn"); // 12% chance (32/256) to jump back to wander cycle
        loop;
	See:
		PHOT ABCDEF 8 Fast A_Chase;
		Loop;
	Melee:
		PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
	    PHOT GH 8 Fast A_FaceTarget;
        PHOT I 8 Fast A_CustomMeleeAttack (random (2, 6) *5, "ClawHit", "skeleton/swing");
		Goto See;
	Missile:
	    Goto See;
	Pain:
		PHOT J 2 Fast;
		PHOT J 2 Fast A_Pain;
		Goto See;
	Death:
		PHOT Q 8;
		PHOT R 8 A_Scream;
		PHOT S 4;
		PHOT T 4 A_NoBlocking;
		PHOT U 4;
		PHOT V -1;
		Stop;
	Raise:
		PHOT V 5;
		PHOT UTSRQ 5;
		Goto Spawn;
	}
}
Post Reply

Return to “Scripting”