Unique monsters

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
Sebelino
Posts: 18
Joined: Sun May 28, 2017 3:53 pm

Unique monsters

Post by Sebelino »

I have implemented a weapon that spawns a monster of a certain actor class each time it is fired. I want to make sure that there can only exist at most one such monster at any given time.

I figured that one way to do it would be to kill all monsters of that type (if any) in the map immediately when the weapon is fired. How do I do that in Decorate/ACS/ZScript?

Any alternative solutions?
User avatar
comet1337
Posts: 876
Joined: Fri Sep 25, 2015 3:48 am
Location: elsewhere

Re: Unique monsters

Post by comet1337 »

give the player an inventory token
use a_spawnitemex to set the player as the monster's master
when the monster dies, use a_takeinventory("monsterlimiter", 1, aaptr_master)
and in the weapon, check for the inventory item and disallow firing if it is present
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Unique monsters

Post by Matt »

User avatar
Sebelino
Posts: 18
Joined: Sun May 28, 2017 3:53 pm

Re: Unique monsters

Post by Sebelino »

Thank you both. I went with the simple but effective A_CheckProximity solution:

Code: Select all

actor HuaPoDSP : DSP
{
	Weapon.SelectionOrder 3200
	Weapon.AmmoUse 50
	Weapon.AmmoGive 0
	Weapon.SlotNumber 8
	Inventory.Pickupmessage "You formed a contract with Hua Po!"
	States
	{
	Ready:
		HUPG A 1 A_WeaponReady
		Loop
	Deselect:
		HUPG A 1 A_Lower
		Loop
	Select:
		HUPG A 1 A_Raise
		Loop
	Fire:
	    NULL A 0 A_CheckProximity("Error", "HuaPoAlly", 100000) // Distance should be infinity
		// Fall through
	Summon:
		NULL A 0 A_PlaySound("demon/appear")
		NULL A 0 A_FireProjectile(HuaPoBall, 0, 1, 0, 0, 0, -90) // Workaround for losing ammo
		NULL A 0 A_SpawnItemEx("TeleportFog", 100, 0, 0)
		CEXE A 15 A_SpawnItemEx("HuaPoAlly", 100, 0, 0)
		CEXE A 15 A_PlaySound("huapo/sight", CHAN_AUTO)
		HUPG A 5 A_ReFire
		Goto Ready
	Error:
		CERR A 15 A_PlaySound("ui/error", CHAN_AUTO)
		Goto Ready
	Flash:
		CEXE A 7 Bright A_Light1
		Goto LightDone
		CEXE A 7 Bright A_Light1
		Goto LightDone
    }
}

Return to “Scripting”