Can I count monsters of a specific type?

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
daskraut
Posts: 9
Joined: Fri Oct 27, 2017 1:22 pm

Can I count monsters of a specific type?

Post by daskraut »

Hi!

I'm making a map with 2 cyberdemons (and a whole lot of other monsters). In order to reveal the level exit switch I want both cyberdemons to die. I'm currently using the following code:

Code: Select all

#include "zcommon.acs"
    int CD = 0;

//the following script is executed upon death of a cyberdemon using action 80 - script execute

script 4 (void)    
{
    CD=CD+1;

    if(CD==2)
    {
        //reveals exit switch
        FloorAndCeiling_LowerRaise(7,20,20);
    }
}
However, in the rare case that both cyberdemons die from the same shot, the integer CD is only increased by 1 and the player gets stuck in the level forever. Which is... not good.

Is there a different way to make sure both cyberdemons must be dead for the switch to be revealed?

Greetings from krautland!
daskraut
User avatar
Kappes Buur
 
 
Posts: 4143
Joined: Thu Jul 17, 2003 12:19 am
Graphics Processor: nVidia (Legacy GZDoom)
Location: British Columbia, Canada

Re: Can I count monsters of a specific type?

Post by Kappes Buur »

Give both cyberdemons a tid of 10, for example, then use this script

Code: Select all

#include "zcommon.acs"

script 1 OPEN
{
    While (ThingCount(T_CYBERDEMON, 10) > 0)
    Delay(35);
    // Do Stuff;
} 
See:
https://zdoom.org/wiki/ThingCount
https://zdoom.org/wiki/ThingCountName
User avatar
daskraut
Posts: 9
Joined: Fri Oct 27, 2017 1:22 pm

Re: Can I count monsters of a specific type?

Post by daskraut »

Thank you, Kappes Buur, this helped a lot!
Why count deaths if you can count the living?
(I should stop drinking and start using google. Yup. JFGI on me this time.)
Kappes Buur wrote:Give both cyberdemons a tid of 10, for example, then use this script

Code: Select all

#include "zcommon.acs"

script 1 OPEN
{
    While (ThingCount(T_CYBERDEMON, 10) > 0)
    Delay(35);
    // Do Stuff;
} 
See:
https://zdoom.org/wiki/ThingCount
https://zdoom.org/wiki/ThingCountName

Return to “Scripting”