Monster Spawner Script.

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
Aeddes
Posts: 13
Joined: Wed Aug 10, 2022 12:58 pm
Preferred Pronouns: He/Him

Monster Spawner Script.

Post by Aeddes »

Hello.

I'm trying to create a spawner.
Looking for a spawner that spawn a few monsters and stop at monster count = X. Then, when a monster get killed, restart spawn until monster count reach X again.

First tryed this:

script "Demon spawner" (void)
{
Thing_Spawn (1, 8, 64, 0);
delay (700);
Restart;
}

With this, spawning don't stop.

This:
script "Demon spawner" (int demoncount)
{
demoncount = 0;

if (demoncount < 3);
{
Thing_Spawn (1, 8, 64, 0);
demoncount = demoncount + 1;
}
}

This:
script "Demon spawner" (void)
{
int demoncount;
demoncount = 0;

if (demoncount < 3);
{
Thing_Spawn (1, 8, 64, 0);
demoncount = demoncount + 1;
}
}


Have tryed variations with: Integers, Booleans, If's, Else's, While's, all dictionary and no sucess...

Sometimes, monsters spawn the right quantity but no restart after get killed; sometimes spawn the right quantity, but disapear and spawn again.
Two days burning my small brain and nothing works.

Could someone explain me how (IF) can i do this?

Thanks in advance.
Jarewill
 
 
Posts: 1849
Joined: Sun Jul 21, 2019 8:54 am

Re: Monster Spawner Script.

Post by Jarewill »

You are resetting the demoncount variable to 0 right before doing the check, so it will always pass.
For what you need, I recommend using ThingCount instead.
For example:

Code: Select all

Script "Demon spawner" (void){
	Thing_Spawn(1,8,64,100); //Spawn a single monster when the script starts
	While(true){ //Start a loop
		If(ThingCount(T_NONE,100)<3){ //Check for all monsters with the TID 100
			Delay(700);
			Thing_Spawn(1,8,64,100); //Spawn a new monster with the TID 100
		}Else{Delay(1);} //If monster limit has been reached, delay the loop
	}
}
User avatar
Aeddes
Posts: 13
Joined: Wed Aug 10, 2022 12:58 pm
Preferred Pronouns: He/Him

Re: Monster Spawner Script.

Post by Aeddes »

Tried this, but after a few seconds, the spawned monster disappear.
No idea what is happening.
Jarewill
 
 
Posts: 1849
Joined: Sun Jul 21, 2019 8:54 am

Re: Monster Spawner Script.

Post by Jarewill »

That sounds weird, it shouldn't be caused by that code.
What monster are you trying to spawn?
If it's a custom one, could you send code for it?
User avatar
Aeddes
Posts: 13
Joined: Wed Aug 10, 2022 12:58 pm
Preferred Pronouns: He/Him

Re: Monster Spawner Script.

Post by Aeddes »

I'm using Blood Demon (from Realm667). But tested with Demon and Spectre, and result is the same.
After a few seconds, the spawned monster vanish.
Spoiler:
User avatar
Aeddes
Posts: 13
Joined: Wed Aug 10, 2022 12:58 pm
Preferred Pronouns: He/Him

Re: Monster Spawner Script.

Post by Aeddes »

Tested on a new map, without any other scripts, and worked great.
Probably any of my scripts are conflicting.

Really thanks for the help!

Edit. Another script was using Thing tag 100. Working fine now!

Return to “Scripting”