Solved How to remove all child entities when parent dies

Question that is answered or resolved.

kimono

Well-known member
Hello fellow code experts,
I'm trying to delete summoned entities when the summoner dies.

I tried writing this small script in its death animation:
Code:
anim death
    landframe 1
    delay    15
    offset    25 81
@script
  if(frame==1){
    void self = getlocalvar("self");
    void alfclone = getlocalvar("alfclone");

    killentity(alfclone); //kill all spawned enemies entities
  }
@end_script      
    @cmd    dasher -3.5 0.1 0 1
    frame    data/chars/alf/hit.png
    frame    data/chars/alf/hit.png  
    @cmd    stop
    offset    25 87
    frame    data/chars/alf/death1.png
    frame    data/chars/alf/death2.png
    frame    data/chars/alf/death3.png
    frame    data/chars/alf/death4.png
    frame    data/chars/alf/death5.png
    frame    data/chars/alf/death6.png
    frame    data/chars/alf/death7.png
    sound data/sounds/explode4.wav  
    frame    data/chars/alf/death8.png
    frame    data/chars/alf/death9.png
    frame    data/chars/alf/death10.png
    frame    data/chars/alf/death11.png
    frame    data/chars/alf/death12.png

But it doesn't seem to work, as evidenced by the video:

Alf's scheme is also supposed to be much more subtle; it involves encouraging Kenshiro to hit his poisoned cloak, which can cause a clone to be summoned in front of and behind him.
I tried to translate it like this in its animation block, but I don't know if it's correct:

Code:
anim block
    offset    25 81
    bbox 9 1 33 80
    range 80 150
    followanim 1
    followcond 1
    delay    6
    hitfx data/sounds/aof2-199.wav
    frame    data/chars/alf/block1.png
   
anim follow1 #Spawn Clones
    delay    15
    offset    25 81
    bbox 9 1 33 80
    @cmd spawn01 "alfclone" 150 0 0
    @cmd spawn01 "alfclone" -150 0 0
    frame    data/chars/alf/block2.png
    frame    data/chars/alf/block3.png
    frame    data/chars/alf/block4.png
    frame    data/chars/alf/block5.png
    frame    data/chars/alf/block6.png
    frame    data/chars/alf/block7.png
From anime to video games, this is the type of combat I wanted to translate :)

How can I correct my code so that it's correct? Thanks for your lights :)
 
Last edited:
Solution
Here's simple script to limit spawning:
C:
anim follow1 #Spawn Clones
@script
  if(frame == 1){
    int Enemy = openborvariant("count_enemies");

    if(Enemy <= 6){ // maxed to 6 enemies on screen, true alf is counted.
      spawn01("alfclone", -150, 0 , 0);
      spawn01("alfclone", -150, 0 , 0);
    }
  }
@end_script
    delay    15
    offset    25 81
    bbox 9 1 33 80
    frame    data/chars/alf/block2.png
    frame    data/chars/alf/block3.png
    frame    data/chars/alf/block4.png
    frame    data/chars/alf/block5.png
    frame    data/chars/alf/block6.png
    frame    data/chars/alf/block7.png

HTH
There are couple ways to solve this issue, the easiest is to kill all enemies when Alf dies either with script or just by spawning invisible entity which hits the whole screen and damages enemies only.

I tried to translate it like this in its animation block, but I don't know if it's correct:

It is correct though you should use limiter to limit number of spawned clones.
 
There are couple ways to solve this issue, the easiest is to kill all enemies when Alf dies either with script or just by spawning invisible entity which hits the whole screen and damages enemies only.



It is correct though you should use limiter to limit number of spawned clones.
That's indeed wise advice on your part: I've limited the lifespan of the clones to 5 seconds, but I'd also like to know how to limit their number on the screen (5 maximum, for example :) )
 
Here's simple script to limit spawning:
C:
anim follow1 #Spawn Clones
@script
  if(frame == 1){
    int Enemy = openborvariant("count_enemies");

    if(Enemy <= 6){ // maxed to 6 enemies on screen, true alf is counted.
      spawn01("alfclone", -150, 0 , 0);
      spawn01("alfclone", -150, 0 , 0);
    }
  }
@end_script
    delay    15
    offset    25 81
    bbox 9 1 33 80
    frame    data/chars/alf/block2.png
    frame    data/chars/alf/block3.png
    frame    data/chars/alf/block4.png
    frame    data/chars/alf/block5.png
    frame    data/chars/alf/block6.png
    frame    data/chars/alf/block7.png

HTH
 
Solution
Back
Top Bottom