Need help with Zscript custom monster

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!)
Post Reply
Protozoare
Posts: 17
Joined: Sat Oct 08, 2022 2:51 am
Preferred Pronouns: He/Him

Need help with Zscript custom monster

Post by Protozoare »

I was messing around with Zscript the other day, and I tried something new for a mod I am working on. I need this enemy to change state after the death animation, and then do a number of pushups before it goes to the raise state. The sprites and sounds and all that are done, with more being planned. But I've never dealt with a monster that repeats an animation for x amount of times before it raises itself and gets back into action. I've tried the for and while functions, and some other things. I was disappointed when I found out that the loop function does not support something like "loop until", which I needed so much here. Originally the code was written in DECORATE, but I am currently writing it is Zscript, but instead of going to raise state when pushupscount>5 and repeating the pushups animation while adding one per each pushup to the counter, for some unknown reason, the monster executes the death frames, goes into the pushups state, and then after going through it only once, it raises and becomes invincible. I have no clue why this is the case. Here is the code I am using. note that this is the only file besides sounds sndinfo and sprites in the wad. The XDeath is commented out, as I am still working on the spritework.

Code: Select all

class Bostan : Actor 
{
	Default
	{
		Health 500;
		Radius 20;
		Height 56;
		Speed 8;
		PainChance 200;
		MinMissileChance 256;
		Monster;
		-COUNTKILL
		+FLOORCLIP
		+NOBLOOD
		SeeSound "bostan/sight";
		AttackSound "bostan/attack";
		PainSound "bostan/pain";
		DeathSound "bostan/death";
		ActiveSound "bostan/active";
		Obituary "%o did to many push-ups.";
		Tag "$FN_BOSTAN";
	
	}
 	States
	{
	Spawn:
		BOST AB 10 A_Look;
		Loop;
	See:
		BOST AABBCCDD 4 A_Chase;
		Loop;
	Missile:
		BOST E 10 A_FaceTarget;
		BOST E 8 A_Playsound("bostan/attack");
		BOST E 8;
		Goto See;
	Pain:
		BOST G 3;
		BOST G 3 A_Pain;
		Goto See;
	Death:
		BOST H 5;
		BOST I 5 A_Scream;
		BOST J 5 A_NoBlocking;
		BOST K 5 A_GiveInventory ("Pushupscount",1);
		Goto Pushups;
	Pushups:
		BOST IJK 10 {A_GiveInventory ("Pushupscount",1);
		A_Playsound("bostan/PushUps");
		A_NoBlocking();
		{if(CountInv("Pushupscount") < 5);
		A_Jump(256,"Pushups");
		}
		}
	//XDeath:
		//BOST M 5;
		//BOST N 5 A_XScream;
		//BOST O 5 A_NoBlocking;
		//BOST PQRST 5;
		//BOST U -1;
		//Stop;
	 Raise:
		BOST K 5;
		BOST JIH 5;
		Goto See;
	}
}
Class Pushupscount : Inventory
{
    Default
    {
        Inventory.Amount 1;
        Inventory.MaxAmount 250;
	}
	}
	
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Need help with Zscript custom monster

Post by Jarewill »

Jumps inside anonymous functions work differently, so you will have to use Return ResolveState("Pushups"); instead.
You also need to actually resurrect the monster to prevent it from going invincible, you can use functions like A_RaiseSelf for this.

I will also note that you don't need to use inventory tokens to keep track of the pushups, since ZScript actors can make use of variables.
Personally I would also recommend using A_JumpIf for things like this.
For example:

Code: Select all

	int pushupcount; //Keep track of the current pushups, you need to place this outside the Default and States blocks.

	Pushups:
		BOST IJK 10 {
			pushupcount++; //Because this function has 3 frames, it will increase this counter by 3
			A_Playsound("bostan/PushUps");
			A_NoBlocking();
		}
		TNT1 A 0 A_JumpIf(pushupcount < 5,"Pushups"); //Loop the animation if the condition has not been met
		BOST K -1 { //Set to allow resurrection
			pushupcount=0; //Reset the counter
			A_RaiseSelf(); //Resurrect the monster
		}
Protozoare
Posts: 17
Joined: Sat Oct 08, 2022 2:51 am
Preferred Pronouns: He/Him

Re: Need help with Zscript custom monster

Post by Protozoare »

Thank you for the support, but I have a question though. Is there a way to define a custom raise sound, instead of the default gibbing one, or is it a hardcoded value from the raise function?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Need help with Zscript custom monster

Post by Jarewill »

As far as I can tell, it's hard-coded.
However you can also use the Revive() function, which doesn't play the sound, but it also doesn't set other properties and I don't know the extent of differences between Revive and A_RaiseSelf.
Here's an example:

Code: Select all

		BOST K 0 {
			pushupcount=0; //Reset the counter
			Revive(); //Revive the monster
			A_SetSize(-1,default.height); //Reset their height
		}
		Goto Raise; //Go to the raise state (Revive doesn't do it automatically)
There might be other quirks of Revive that I am unaware of, so point them out if you encounter any.
Post Reply

Return to “Scripting”