Kill a monster is its spawner dies

Ask about mapping, UDMF, using DoomBuilder/editor of choice, etc, 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.
User avatar
Daryn
Posts: 122
Joined: Wed Jan 23, 2019 10:22 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11 Professional X64
Graphics Processor: nVidia with Vulkan support

Kill a monster is its spawner dies

Post by Daryn »

I'm working on a Micro-Missile spider. It spawns three loiter missiles, then when those see the player, they fire off micro-rockets and die. The trouble I'm having is, sometimes those loiter missiles hang around the map, so I'd like to tie them to the spider that spawned them so that when it's killed, they die too.

I've tried a few things, but my ZScript isn't quite there yet. Still very much a learning-as-I-go thing for me.

Here's what I have so far. I've omitted the Rocket and its trail's code, since there's nothing there that's relevant, it's just changing some sizes and values of the original rocket.

This doesn't work, well, the monster works, but the rocket shells don't die when the spider does. If anyone has suggestions, please, let me know. I've been at this a good while already, and not had a lot of luck.

Code: Select all

class MMArachnotron : Arachnotron
{
	Default
	{
		//$Category Custom Monsters
		//$Title Arachnotron (Micro-Missile)
		Health 500;
		Radius 64;
		Height 64;
		Mass 600;
		Speed 12;
		PainChance 128;
		Monster;
		SeeSound "baby/sight";
		PainSound "baby/pain";
		DeathSound "baby/death";
		ActiveSound "baby/active";
		Obituary "$OB_BABY";
		Tag "$FN_ARACH";
	}
	States
	{
	Spawn:
		BSPI AB 10 A_Look;
		Loop;
	See:
		BSPI A 20;
		BSPI A 3 A_BabyMetal;
		BSPI ABBCC 3 A_Chase;
		BSPI D 3 A_BabyMetal;
		BSPI DEEFF 3 A_Chase;
		Goto See+1;
	Missile:
		BSPI A 20 BRIGHT A_FaceTarget;
		BSPI G 25 BRIGHT A_SpawnItemEx("RocketShell", 0, 32, 68, 8, 0, 1, -15, SXF_TRANSFERPOINTERS|SXF_NOCHECKPOSITION);
		BSPI G 25 BRIGHT A_SpawnItemEx("RocketShell", 0, -32, 68, 8, 0, 1, 0, SXF_TRANSFERPOINTERS|SXF_NOCHECKPOSITION);
		BSPI G 25 BRIGHT A_SpawnItemEx("RocketShell", 32, 0, 68, 8, 0, 1, 15, SXF_TRANSFERPOINTERS|SXF_NOCHECKPOSITION);
		BSPI H 4 BRIGHT;
		BSPI H 1 BRIGHT A_SpidRefire;
		Goto Missile+1;
	Pain:
		BSPI I 3;
		BSPI I 3 A_Pain;
		Goto See+1;
	Death:
		BSPI J 20 A_Scream;
		BSPI K 7 A_NoBlocking;
		BSPI LMNO 7;
		BSPI P -1 A_BossDeath;
		Stop;
	Raise:
		BSPI P 5;
		BSPI ONMLKJ 5;
		Goto See+1;
	}
}

Class RocketShell : Actor {
	Default {
		Damage 0;
		Speed 10;
		Monster;
		+NOGRAVITY
		+RANDOMIZE
		+ROCKETTRAIL
		+ZDOOMTRANS
		+NEVERRESPAWN
		-COUNTKILL
		SeeSound "weapons/rocklf";
		DeathSound "weapons/rocklx";
	}
	
	States {
		Spawn:
			MISL A 1 Bright;
			Goto See;
		See:
			MISL A 1 BRIGHT A_Chase();
			Loop;
		Missile:
			MISL B 10 RocketSplitFire();
			Goto Death;
		Death:
			MISL B 8 Bright;
			MISL C 6 Bright;
			MISL D 4 Bright;
			Stop;
	}
	override void Tick()
	{
	super.tick(); // Call original Tick function.
	if (!master) {
		ResolveState("Death");
	}
	}
	void RocketSplitFire()
	{
		A_SpawnProjectile("MicroMissile", 0, -12, -10);
		A_SpawnProjectile("MicroMissile", -8, 0, 0);
		A_SpawnProjectile("MicroMissile", 0, 12, 10);
	}
}
Thanks. Stay safe, everyone.
User avatar
Enjay
 
 
Posts: 26540
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Kill a monster is its spawner dies

Post by Enjay »

There are several functions that can be used (in ZScript or DECORATE) that can manipulate individuals in a master/child relationship.

[wiki]A_KillChildren[/wiki] might be what you are looking for but, if not, look at the bottom of that page for several more links.

As long as you spawn your items using the parameters that set a master/child relationship, those functions should be available to you.
User avatar
Daryn
Posts: 122
Joined: Wed Jan 23, 2019 10:22 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11 Professional X64
Graphics Processor: nVidia with Vulkan support

Re: Kill a monster is its spawner dies

Post by Daryn »

It looks like that worked, which makes the timer function unnecessary. I may implement something in there later, though. Thanks, Enjay, you've been a huge help over the years.

Return to “Mapping”