Making sure monsters spawn [ACS]

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
User avatar
Korni27
Posts: 46
Joined: Sun Jan 31, 2021 9:18 am
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Poland
Contact:

Making sure monsters spawn [ACS]

Post by Korni27 »

Hi, I am creating a custom horde mode script and I have a problem, that being, I want to stop spawning monsters after enough have spawned.

I have a variable that tracks how many monsters there should be (maxMonsters), how many monsters have been killed (monsterCounter), how many have spawned (monstersSpawned), and how many are there before the spawn (currentMonsterCount)

Here is the code

Code: Select all

int currentMonsterCount;

Script "WaveStart" (VOID)
{
	While(monsterCounter > 0)
	{
		Delay(100 - waves);
		If(monstersSpawned != maxMonsters)
		{
			currentMonsterCount = ThingCount(T_NONE,666);
			Thing_SpawnFacing(random(1,27),monsterList[random(0,levelOfEnemies)],0,666);
			SetThingSpecial(666,80,667,0,0,0,0);
			if(currentMonsterCount < ThingCount(T_NONE,666))
			{
				monstersSpawned++;
			}
		}
	}
}

Script 667 (VOID)
{
	monsterCounter--;
}

Script "ViewShower" (VOID)
{
	While(monsterCounter > 0)
	{
		SetFont("BIGFONT");
		SetHudSize(520, 400,0);
		HudMessage(s:"Monsters left: ", i: monsterCounter; HUDMSG_PLAIN, 0, CR_GOLD, 260.4, 80.4, 0.03);
		Delay(1);
	}
	Thing_Remove(666);
	HudMessage(s:"All Monsters Killed!"; HUDMSG_FADEOUT, 0, CR_GOLD, 260.4, 80.4, 0.0,1.0);
	Delay(35);
	ActivatorSound("BRS/annoucer/complete",128);
	HudMessage(s:"Wave Completed!"; HUDMSG_FADEOUT, 0, CR_GOLD, 260.4, 80.4, 2.0,1.0);
	Delay(35*3);
	FadeTo(0,128,0,0.5,0.0);
	for (int i = 1; i < PlayerCount(); i++) {
		GiveActorInventory(1000 + i,"horde_live",3);
	}
	FadeTo(0,128,0,0.0,0.1);
	SetFont("SMALLFONT");
	HudMessage(s:"Lives recovered!"; HUDMSG_FADEOUT, 0, CR_GREEN, 260.4, 80.4, 1.0,1.0);
	Delay(35*2);
	//Before all, changes the music
	musicRandomizer = Random(0,16);
	SetMusic(songList[musicRandomizer]);
	SetFont("SMALLFONT");
	SetHudSize(520, 400,0);
	HudMessage(s:"Now Playing: ", s:songName[musicRandomizer]; HUDMSG_TYPEON, 0, CR_GOLD, 260.4, 70.4, 1.0, 0.1, 0.5);
	ACS_NamedExecute("WaveCountdown",0,0,0,0);
}
Normally the code works just fine, but the is a chance that a monster fails to spawn, but still increases the spawn counter, which means one or two kills will keep you from finishing the wave, but they won't be accessible, soft locking you.
a simple ThingCount won't work, as the number of monsters can be lowered between the spawns.
if anyone is willing to help, thank you in advance.
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Making sure monsters spawn [ACS]

Post by Jarewill »

I don't know if Thing_SpawnFacing returns any value, but if you use SpawnSpotFacing instead, you will be able to do this:

Code: Select all

int spot = random(1,27); //Choose the random spot to spawn on, required to spawn both the monster and the fog on the same spot
If(SpawnSpotFacing(monsterList[random(0,levelOfEnemies)],spot,666)){
	//This code will only trigger if the monster actually spawned
	SpawnSpotFacing("TeleportFog",spot,0);
	SetThingSpecial(666,80,667,0,0,0,0);
	if(currentMonsterCount < ThingCount(T_NONE,666))
	{
		monstersSpawned++;
	}
}
User avatar
Korni27
Posts: 46
Joined: Sun Jan 31, 2021 9:18 am
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Poland
Contact:

Re: Making sure monsters spawn [ACS]

Post by Korni27 »

I used this method, but it doesn't wanna spawn monsters
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Making sure monsters spawn [ACS]

Post by Jarewill »

Could you upload your full file?
User avatar
Korni27
Posts: 46
Joined: Sun Jan 31, 2021 9:18 am
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Poland
Contact:

Re: Making sure monsters spawn [ACS]

Post by Korni27 »

Here, don't mind the missing stuff, there is a lot of custom content that would be unnecessary.
Attachments
map.zip
(31.48 KiB) Downloaded 20 times
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Making sure monsters spawn [ACS]

Post by Jarewill »

SpawnSpotFacing requires classnames, instead of spawn numbers, so you will have to edit your monster list, like so:

Code: Select all

str monsterList [3] = {
	"Zombieman",
	"ShotgunGuy",
	"LostSoul"
};
The WaveStart script also had two errors: You called the monster spawning function twice instead of once and you missed one closing bracket. ( } )
Post Reply

Return to “Scripting”