Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Kyka

Getting Stuff to happen When Multiple Monsters Die.

Recommended Posts

Ok. So it is not a difficult thing to make lots of things happen when a single monster dies. (Thing special 80) But to make that something only happen when multiple monsters die, I understand how it works in theory, but I simply don't know enough of the scripting syntax to make it work in practice.

{
If int(monster count tagged to the particular script) > 0 then

Do nothing in particular.

else

if monster count = 0

run all the crap in the script.
}


My Coding Is So Awesome Not Really.

Could someone show me how to do this, or where to find a script that does this.

Thanks heaps. :)

Share this post


Link to post

int killedCountA = 60; //set how many monsters you have tagged

SCRIPT Do_This_When_Monster_Dies{
  killedCountA--; //decrements it by 1
  if(killedCountA == 0){ //enter the following code block when all 60 monsters are dead
    //Do crazy stuff
  }
}

Share this post


Link to post

There are multiple ways.

Here is an example.

script 41 (void)
{
combatkill+=1;
}

script 42 (void)
{
if (combatkill > 41)
{
Floor_LowerByValueTimes8 (67, 10, 13);
}
if (combatkill < 42)
delay(100);
restart;
}

This is an old script of mine, but works.

At the top of all scripts, make sure to have this:

int combatkill;

"Combatkill" is just what I used as a variable. Name it whatever you want.

On each monsters that needs to be killed, use action 226 (Script Execute ALWAYS). In this case, it needs to execute script 41.

Everytime one of these monsters dies, they increase the variable by 1. The 2nd script, 42, need to be started somewhere before. I guess you can make it OPEN, but I prefer to have it running only when needed. Put in on a line that must be crossed before killing the monsters, or something.

The first part of script 42 here activate when the variable is over 41, and execute the action (here it lowers a floor). If its under 42, the script restarts constantly to check the variable again and again.


I'm sure its not the most efficient way to do it, but it works perfectly in my maps.

EDIT: Someone beat me to it. I like my method, alright?

Share this post


Link to post

Thanks heaps for the replies guys. Both ways make good sense. And more than one way to do it is cool. 'specially seeing as i have no real idea about this stuff other than general principles.

I'm going to go apply some of this.

Much appreciated. :)

Share this post


Link to post

Otherwise, you can have an open script that is constantly delayed as long as the thing count of all things of type 0 with TID (whatever TID you gave to all the monsters) doesn't reach the desired threshold, and then once it reaches it does the series of stuff it needs to do.

The advantage of doing it this way (rather than the previous, simpler method) is that this way the monsters can be spawned by script as well.

Share this post


Link to post
Gez said:

The advantage of doing it this way (rather than the previous, simpler method) is that this way the monsters can be spawned by script as well.

Well, depending on the way you're spawning monsters you could just as well increment/decrement your explicit counter when spawning too:

...
Spawn_Monster; //(It's been a while since I used ACS last time so I don't remember the function names and parameters)
killedCountA++; //increment the monster counter
...
In the end, it's more a matter of how you want to organize your scripts. With modern computers there's no need to worry about what would be the most optimal solution performance-wise. :P Gez's way is "tidy" in that you have all related code neatly in one place even for more dynamic cases, but on the other hand if you're going to have a script heavy map with a lot of similar stuff you'll get a main loop (or main loops) with a ton of stuff in them which also is messy.

Share this post


Link to post

Yaaay. I made it work.

Now there is a complication.

In the main wad where I want to use this, most of the monsters start out dead, and are raised by archviles, are killed and possibly raised again etc etc.

Is there a way to do this without using a counter, say a check to see if everything is dead rather than a counted number of corpses? coz you could potentially cross the counting threshhold with still a bunch of monsters alive still.

Just wondering if this can be done.

thanks guys. :)

Share this post


Link to post

If I recall correctly, when a monster is resurrected ZDoom actually creates a new thing with 0 thing ID (I might be wrong, but I think I had a related problem with a map some time ago), so what you're thinking about might be close to impossible. Still, it should be worth trying Gez's method.

Share this post


Link to post

The check would work, but if monsters of the same type exist anywhere else in the map, its a problem.

In which case you can just make a copy of the monster in DECORATE and use this copy only for that event, but I don't know how to check for custom monsters... as far as I remember, I never even found out how to spawn custom monsters from a script. I'm hoping there is a way I just don't know about, or things have changed.

Share this post


Link to post

Oh shit, so wait.

Resurrected monsters lose their TIDs? If this is not the case, then try the following:

Check for whether your archviles are alive using an Open script which queries ThingCount(). If the archviles are dead, then check your monsters with ThingCount() using the TID that was given to them. Spawned monsters can be specified to have a TID, so there isn't a problem with those. If all your monsters are dead, perform your level stuff and terminate the script.

Script X Open
{
  While (ThingCount(T_ARCHVILE, ArchieTID))  Delay(35);
  While (ThingCount(T_NONE,     MonsterTID)) Delay(35);

  // Do map stuff.
}

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
Sign in to follow this  
×