Solved How to Use aniECount for Letting Two Same Enemies Act at the Same Time

Question that is answered or resolved.

maxman

Well-known member
I thought using aniECount was going to be easy until I started trying it. What I'm having trouble with is the setup within enemy groups in levels.

Code:
group 100 100
at 900
#1ST PHASE: ONE ENEMY SHOULD GO FIRST BEFORE THE TWO FOLLOWING ENEMIES AND THE BOSS
spawn enemy1
coords 756 190
at 900

# 2ND PHASE: TWO FOLLOWING ENEMIES ACT BEFORE THE BOSS

spawn enemy2
@script
void main(){
    changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FOLLOW10"));
}
@end_script
flip 1
coords 160 171
at 900

spawn enemy2 #same enemy as enemy2
@script
void main(){
    changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FOLLOW10"));
}
@end_script
coords 210 171
at 900

#3RD PHASE: BOSS STARTS TO ACT AFTER ALL THREE ENEMIES ARE DEFEATED BUT REMAINING ENEMIES FIGHT ALONG WITH BOSS

spawn boss
coords 185 171
at 900

# SPAWN REMAINING ENEMIES IN THIS LIST RIGHT AFTER BOSS STARTS TO FIGHT

spawn enemy3
coords 500 200
at 900

spawn enemy3
coords -10 210
at 900

spawn enemy4
coords -15 187
at 900

For enemy2, I'm trying to make 2 of them to act after defeating one enemy. But I only could have one of them start one by one after one enemy is defeated. Even what's worse after it's defeated, they can't act to fight at all, leaving them only to idle. That depends on the number of enemies aniECount is used, I guess.

Code:
anim follow10 #First entry
    offset    80 144
    delay    20
    @cmd frozen 1
    @cmd aniChange 0 "ANI_FOLLOW11"
    frame    ...

anim follow11 #Wait
    loop    1
    offset    80 144
    delay    20
    @cmd aniEcount 0 "ANI_FOLLOW12" 1
    frame    ...
    frame    ...
    frame    ...

anim follow12 #Get ready!
    offset    80 144
    delay    20
    @cmd frozen 0
    frame    ...
    frame    ...
    frame    ...

C:
void aniEcount(int type, void ani, int count)
{//Animation changer with ENEMY count (ELEVATORS)
 //Type 0: Less than "count"
 //Type 1: More than "count"
    void self  = getlocalvar("self");
    int eCount = openborvariant("count_enemies");
   
    if(type == 0){
        if(eCount <= count){
            changeentityproperty(self, "animation", openborconstant(ani));
        }
    }
   
    if(type == 1){
        if(eCount >= count){
            changeentityproperty(self, "animation", openborconstant(ani));
        }
    }
}

Here's a couple of examples from SOR2X which I'm trying to get one stage to work:
Code:
spawn        Fog_Wait2 1
map            1
flip        1
coords        120 215 0
at            0

spawn        Fog_Wait2 1
map            1
flip        1
coords        200 215 0
at            0

spawn        Fog_Sit 1
map            1
flip        1
coords        300 215 0
at            0

spawn        Fog_Wait3 1
map            2
weapon        Pipe 1
flip        0
coords        400 215 0
at            0

spawn        Hakuyo_Wait 1
map            0
flip        0
coords        350 240 0
at            0

group        5 5
at            0

spawn        HakuyoB 1
map            1
flip        0
coords        400 240 300
at            0

spawn        HakuyoX 1
map            1
flip        0
coords        400 240 300
at            0

Code:
group        2 2
at            2

spawn        AbadedeB 1
map            1
flip        1
coords        240 250 400
at            2

#########################################################################################

group        1000 1000
at            3

spawn        Shiva_Wait 1
map            0
flip        0
coords        1 1000 0
at            3

spawn        Mrx_Wait 1
map            0
flip        0
boss        1
coords        1 1000 0
at            3

wait
at            3

#########################################################################################

group        1000 1000
at            4

spawn        HarakiriB 1
map            1
flip        0
coords        -100 240 0
at            4

spawn        BasicX1 1
map            4
flip        0
coords        600 240 0
at            4

spawn        BasicX1 1
map            4
flip        1
coords        650 240 0
at            4

spawn        BasicX1 1
map            4
flip        0
coords        700 270 0
at            4

spawn        BasicX1 1
map            4
flip        1
coords        750 270 0
at            4

wait
at            4

#########################################################################################

group        5 5
at            5

spawn        BasicX1 1
map            4
flip        0
coords        600 240 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -100 240 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        700 270 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -200 270 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        600 240 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -100 240 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        700 270 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -200 270 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        600 240 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -100 240 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        700 270 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -200 270 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        600 240 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -100 240 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        700 270 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -200 270 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        600 240 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -100 240 0
at            5

spawn        BasicX1 1
map            4
flip        0
coords        700 270 0
at            5

spawn        BasicX1 1
map            4
flip        1
coords        -200 270 0
at            5

How does this setup of aniECount work, knowing that BasicX1 is a none type that spawns a pair of 2 enemies using (random?) script?
 
Last edited:
Solution
Ah I see.
It's possible to use aniECount but I think it's inflexible. I suggest using global variable to give sign to certain enemies to step in.
Something like this in enemy2's FOLLOW10:
C:
anim follow10
@script
    void self = getlocalvar("self");
    int Check1 = getglobalvar("Go");

    if(frame==1 && Check1==1){
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
@end_script

FOLLOW1 is the step in animation.
I usually reset Go variable but for this case I don't. The purpose is so the other enemy2 would also step in.
After both stepped in, this Go variable won't be read by them anymore.
The boss should use this script:
C:
anim spawn
@script
    void self = getlocalvar("self");
    int Check1 =...
This aniEcount is very basic and I developed it for the elevators, like the description. It basically checks the amount of alive enemies in a loop, and only proceeds to the next animation (going up) when the limit is reached.

In addition, this code considers the own elevator as an enemy type too in order to hold the level advancement.
I didn't understand exactly what you are trying to do, maybe a visual example can help.
 
maxman, are you trying to create scene like this:
Player is in a room with a boss, 2 guys and some enemies. An enemy walks in and after he's defeated, the 2 guys step in to fight player. The defeat of these 2 will make the boss and remaining enemies step in to fight.
 
I didn't think it's for elevators, but it's giving me an idea if I were to make an elevator stage.

This aniEcount is very basic and I developed it for the elevators, like the description. It basically checks the amount of alive enemies in a loop, and only proceeds to the next animation (going up) when the limit is reached.
Now I see the purpose of that script. It's also good for elevator levels.

maxman, are you trying to create scene like this:
Player is in a room with a boss, 2 guys and some enemies. An enemy walks in and after he's defeated, the 2 guys step in to fight player. The defeat of these 2 will make the boss and remaining enemies step in to fight.
Yes! That's exactly what I'm trying to do! I would like to let the first four bad guys to exist in that event. After three enemies are defeated, the boss steps in and the remaining enemies that don't appear in the first phase will appear. The first enemy doesn't have to have a script in anim spawn, unlike the two following enemies and the boss, which they do have.
 
Ah I see.
It's possible to use aniECount but I think it's inflexible. I suggest using global variable to give sign to certain enemies to step in.
Something like this in enemy2's FOLLOW10:
C:
anim follow10
@script
    void self = getlocalvar("self");
    int Check1 = getglobalvar("Go");

    if(frame==1 && Check1==1){
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
@end_script

FOLLOW1 is the step in animation.
I usually reset Go variable but for this case I don't. The purpose is so the other enemy2 would also step in.
After both stepped in, this Go variable won't be read by them anymore.
The boss should use this script:
C:
anim spawn
@script
    void self = getlocalvar("self");
    int Check1 = getglobalvar("Go");

    if(frame==1 && Check1==2){
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
@end_script

The level text should be updated into this:
Code:
group    100 100
at    900
#1ST PHASE: ONE ENEMY SHOULD GO FIRST BEFORE THE TWO FOLLOWING ENEMIES AND THE BOSS
spawn enemy1
coords 756 190
at 900

# 2ND PHASE: TWO FOLLOWING ENEMIES ACT BEFORE THE BOSS

spawn enemy2
@script
void main(){
    changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FOLLOW10"));
}
@end_script
flip 1
coords 160 171
at 900

spawn enemy2 #same enemy as enemy2
@script
void main(){
    changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FOLLOW10"));
}
@end_script
coords 210 171
at 900

#3RD PHASE: BOSS STARTS TO ACT AFTER ALL THREE ENEMIES ARE DEFEATED BUT REMAINING ENEMIES FIGHT ALONG WITH BOSS

spawn boss
coords 185 171
at 900

group    4 4
at    0

spawn    delay # won't be spawned until enemy1 is defeated
@script
void main(){
  setglobalvar("Go", 1);
}
@end_script
coords    100 200
at    0

group    2 2
at    0

spawn    delay # won't be spawned until both enemy2s are defeated
@script
void main(){
  setglobalvar("Go", 2);
}
@end_script
coords    100 200
at    0

group    100 100
at    0

# SPAWN REMAINING ENEMIES IN THIS LIST RIGHT AFTER BOSS STARTS TO FIGHT

spawn enemy3
coords 500 200
at 900

spawn enemy3
coords -10 210
at 900

spawn enemy4
coords -15 187
at 900

HTH
 
Solution
Hey, @Bloodbane. I would like the first enemy of the last wave to expect the player to move forward where the following enemies and boss are. When the player is in the last wave, the first enemy (off or on screen) should wait without making a move until the player steps in. How can I make him wait for the player move forth before he does anything? I tried to put its x coords beyond the current screen resolution farther, but he's still active when he's in follow animation. The following enemies and boss are already done, but only the first one is what I'm having trouble with right now. (I want him to distance himself from the player whether he's on or off screen.)

EDIT: I tried your script of that method but couldn't for the first. It's best for me to wait for any answer that works well.
 
Last edited:
Wait wait, I'm lost here 😖.

I would like the first enemy of the last wave to expect the player to move forward where the following enemies and boss are.

Which wave is the last one? in my understanding, last wave is the very last one in which the boss and remaining enemies excluding ones blocked by group are in.

When the player is in the last wave, the first enemy (off or on screen) should wait without making a move until the player steps in

What do exactly mean by stepping in?

In general, why do you need first enemy or in general an enemy to wait for player?
 
Sorry for the confusion and being vague, Bloodbane. I was referring to only the first enemy (enemy1) in the boss from the last wave which I posted in this topic. Let me explain to you this.

Which wave is the last one? in my understanding, last wave is the very last one in which the boss and remaining enemies excluding ones blocked by group are in.
The very same group/wave which I posted in this topic, and you modified the fix for me. But this time, it's enemy1 that will have to wait for the player to step in while he's off (or on) screen. Two enemy2 ones and the boss are still waiting as well as you scroll through the final wave of enemy groups. Therefore, all the last ones are okay, but only the first enemy which is enemy1 from the first phase that needs to make a waiting moment before he does anything. I just changed the comment for the first enemy from the first phase on what I need it to do.

Code:
group    100 100
at    900
#1ST PHASE: FIRST ENEMY WHICH GOES FIRST BEFORE OTHERS WILL NEED TO WAIT FOR PLAYER TO COME (NEED IMPROVEMENT)
spawn enemy1
coords 756 190
at 900

# THE REST IS ALL OKAY. THAT'S IT.

# 2ND PHASE: TWO FOLLOWING ENEMIES ACT BEFORE THE BOSS (COMPLETE!)

spawn enemy2
@script
void main(){
    changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FOLLOW10"));
}
@end_script
flip 1
coords 160 171
at 900

spawn enemy2 #same enemy as enemy2
@script
void main(){
    changeentityproperty(getlocalvar("self"), "animation", openborconstant("ANI_FOLLOW10"));
}
@end_script
coords 210 171
at 900

#3RD PHASE: BOSS STARTS TO ACT AFTER ALL THREE ENEMIES ARE DEFEATED BUT REMAINING ENEMIES FIGHT ALONG WITH BOSS (COMPLETE!)

spawn boss
coords 185 171
at 900

group    4 4
at    0

spawn    delay # won't be spawned until enemy1 is defeated
@script
void main(){
  setglobalvar("Go", 1);
}
@end_script
coords    100 200
at    0

group    2 2
at    0

spawn    delay # won't be spawned until both enemy2s are defeated
@script
void main(){
  setglobalvar("Go", 2);
}
@end_script
coords    100 200
at    0

group    100 100
at    0

# SPAWN REMAINING ENEMIES IN THIS LIST RIGHT AFTER BOSS STARTS TO FIGHT

spawn enemy3
coords 500 200
at 900

spawn enemy3
coords -10 210
at 900

spawn enemy4
coords -15 187
at 900

What do exactly mean by stepping in?
As in the player that walks forth in the level and the camera scrolls following the player. While the player walks forth, enemy1 starts to appear running fast with aggression 100. It has anim run with its footstep sound though.

In general, why do you need first enemy or in general an enemy to wait for player?
Because I'm not using direction both. I either leave it as default or enter direction right command. In some levels, I use both; in some, I don't. Also, what I want is to make a scene that after the player defeats the penultimate wave of enemies, he walks forward to the last wave where enemy2 and the boss are. At this point, the player shouldn't go/turn back before facing enemy1. This is why I want enemy1 to wait for the player to come. My real problem with this is that after you defeat enemies in the penultimate wave, enemy1 quickly starts to run since it has its sound in its anim run. What I want is for the player to move forward until the very moment when enemy1 starts to appear after getting there.
 
Okay I think I got the idea, so the focus is this enemy:
Code:
group    100 100
at    900
#1ST PHASE: FIRST ENEMY WHICH GOES FIRST BEFORE OTHERS WILL NEED TO WAIT FOR PLAYER TO COME (NEED IMPROVEMENT)
spawn enemy1
coords 756 190
at 900

However you mention penultimate wave before that enemy. I assume they are spawned before scrollpos 900.

What I want is for the player to move forward until the very moment when enemy1 starts to appear after getting there.

At which scrollpos do you want enemy1 to spawn?
 
Back
Top Bottom