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.

Can I count monsters of a specific type?

Postby daskraut » Sat Oct 28, 2017 3:58 pm

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 allExpand view
#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
daskraut
 
Joined: 27 Oct 2017

Re: Can I count monsters of a specific type?

Postby Kappes Buur » Sat Oct 28, 2017 6:20 pm

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

Code: Select allExpand view
#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
Kappes Buur
 
 
 
Joined: 17 Jul 2003
Location: British Columbia, Canada

Re: Can I count monsters of a specific type?

Postby daskraut » Sun Oct 29, 2017 3:47 am

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 allExpand view
#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
 
Joined: 27 Oct 2017


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests