Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Rosh Fragger

How to spawn monsters one after another using DB2 scripts?

Recommended Posts

Hi everyone! I'm working on a survival wad using doom builder 2. I know how to make monsters spawn using scripts (crossing a line-def, or after killing one etc). But I wanna know how to do this:

"Player presses a switch, opens a door, or kills a monster and another monster spawns (map spot of course). Then the player kills that too and another monster spawns to be taken care of."

I'm confused about it. I tried using 'Script Execute' on the first mapspot and making a script for it to spawn a thing facing and tagged it to another mapspot, but that doesn't seem to work.

Can anyone help?

Share this post


Link to post

You must put the "Script Execute" action on something that can be activated. For example on a switch (with "player presses use" trigger), on a walkover linedef (with "player walks over" trigger), on a monster (the action will be executed upon the monster's death), or inside another script (as ACS_Execute).

Share this post


Link to post

So how do I actually make more monsters spawn from nowhere when some already existing monsters on the level get killed by the player?

For example: I kill an imp, a demon spawns behind me to haunt me, then as soon as I kill the demon, a few cacodemons summon somewhere in the room out of nowhere, and so on.

This can anyone explain to me please?

Share this post


Link to post

What you described is not exactly a trivial task, but still relatively easy. There are multiple ways to achieve it. I'll tell you the one that's optimal in regards of engine performance.

Put a map spot or multiple ones whereever you want, and give them unique TIDs (for example 1-5). Then put a monster or multiple ones somewhere, select them all as a group, give them an unique TID (for example 6) and set their Action to ACS_ExecuteAlways(1,0,6,0,0) - "1" refers to the script number and "6" refers to their own TID. Now write script 1:

#include "zcommon.acs"

script 1 (int myTID) {
    if(!ThingCount(T_NONE,myTID)) {
        switch(myTID) {
            case 6:
                SpawnSpotFacing("Demon",1,7); // Spawns a Demon at map spot 1 with TID 7
                SetThingSpecial(7,ACS_ExecuteAlways,1,0,7);
                if(ThingCount(T_NONE,7)) { break; }
            case 7:
                SpawnSpotFacing("Cacodemon",2,8); // Spawns a Cacodemon at map spot 2 with TID 8
                SpawnSpotFacing("Cacodemon",3,8); // Spawns a Cacodemon at map spot 3 with TID 8
                SetThingSpecial(8,ACS_ExecuteAlways,1,0,8);
                if(ThingCount(T_NONE,8)) { break; }
            case 8:
                SpawnSpotFacing("ChaingunGuy",4,9); // Spawns a ChaingunGuy at map spot 4 with TID 9
                SpawnSpotFacing("ChaingunGuy",5,9); // Spawns a ChaingunGuy at map spot 5 with TID 9
                SetThingSpecial(9,ACS_ExecuteAlways,1,0,9);
                if(ThingCount(T_NONE,9)) { break; }
                // Continue with as many waves of new monsters you want.
            case 9:
                // Perform some final action after the last enemy is killed, for example open a door, or do nothing, whatever
        }
    }
}
This code will execute whenever one of the initial monster will be killed. After the last one will be killed, the script will detect it via ThingCount, spawn more monsters with another unique TID (on firmly defined map spots), and set their thing special to ACS_ExecuteAlways again, so that the chain will continue. The "if(ThingCount(T_NONE,*)) { break; }" command is there because if something was physically occupying the map spots, the monsters wouldn't get spawned, so the algorithm would follow with the next wave of monsters instead.

Share this post


Link to post

Alright so I placed around 5 map spots and gave them 1-5 tags. Then placed a few zombiemen and gave them all tag 6. Now there's no ACS_ExecuteAlways action here, I'm assuming because I'm using DB2 instead of DB1. So I gave the zombiemen the action # 226: Script Execute Always with the script number 1.

I don't understand each and everything in that script provided by you, but copy/pasted it into my wad. Now I guess I'll have to make some changes into the script to make it work? cuz it's not working right now.

Share this post


Link to post
Xtercomp said:

So I gave the zombiemen the action # 226: Script Execute Always

That's correct.

Xtercomp said:

with the script number 1.

And don't forget that Arg1 should be 6, same as the Zombiemen's TID.

Share this post


Link to post

Now it's working!! :) Thanks man. I'll go through the scripts now and try creating some nice monster layers in mah survival wad!

Share this post


Link to post
Xtercomp said:

I don't understand each and everything in that script provided by you,

You should try to, because it would suck if you always had to rely on other people writing your scripts for you.

Here is reference/documentation to everything I used in the script:

http://zdoom.org/wiki/A_quick_beginner%27s_guide_to_ACS
http://zdoom.org/wiki/Structure_of_a_script
http://zdoom.org/wiki/Script_types
http://zdoom.org/wiki/ThingCount
http://zdoom.org/wiki/Switch/Case
http://zdoom.org/wiki/SpawnSpotFacing
http://zdoom.org/wiki/SetThingSpecial
http://zdoom.org/wiki/ACS_ExecuteAlways

Share this post


Link to post
scifista42 said:

"if(ThingCount(T_NONE,*)) { break; }" command is there because if something was physically occupying the map spots, the monsters wouldn't get spawned, so the algorithm would follow with the next wave of monsters instead.

An alternative, if the room is high enough, is to raise the map spots. I think if they're 92 units up they'll be out of reach of even a jumping player. When the monsters are spawned, they'll fall on the ground (except flying monsters like cacos, pains, and souls).

Another possibility is to have their spawn points surrounded by lines with the block players flag. To avoid invisible walls you can make them visible with some sort of forcefield effect -- something as simple as a translucent FIREBLU2 mid texture will do the job in a pinch if you don't have any better texture.

Share this post


Link to post

Who knows what would be blocking the destination map spot(s) at the critical moment - consider stacked monster/player bodies, stuff summoned by cheating, something specific to a gameplay mod the player was using, etc. The important thing is that if there wasn't this safety check and the spawning of the whole wave of monsters failed for whatever reason, it would break the entire rest of the sequence forever. That's why it's better to keep that safety check in, even if the abovementioned "alternatives" were implemented too - anyway, they're still good for reducing probability/opportunity that the spawning will fail in the first place.

Share this post


Link to post

Alright. Another question: what's with the "case 6, 7, 8" etc? Not working after renaming to 1 - 4.

Edit: Also can't I use the monster spawn ids instead of the proper respective name in ""? I tried, but not working then.

Share this post


Link to post

1. Since the numbers refer to TIDs, they should be unique, NOT corresponding to TIDs of anything in your map. (Particularly not to the TIDs of your map spots.)

2. Spawning by classname is better, but if you insist on spawning them by spawn id, use Thing_Spawn instead of SpawnSpotFacing. Make sure to acknowledge the differences between parameters and behavior of Thing_Spawn and of SpawnSpotFacing.

Share this post


Link to post

Thanks for the help! Gonna read the wiki now to get a better hang onto this, and will ask here anything that I find confusing. Best doom modders from around the world available here :)

Share this post


Link to post

So I've learned that using Thing_spawnfacing is the easiest technique to make monster layers like I want em. I'm still learning, but have been able to successfully make a test room with zombiemen spawning after picking up a shotgun, followed by another layer of them, then a few medkits on another tagged map spot, then after a short delay invade the imps, and so on.

Also, I was able to add teleport fog in the provided script here, but still it was getting a bit complicated. But this other technique is really working for me at the moment.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×