MZ Death nova modification.

Hi I try to modified the death nova script from yanfly plugin tips and trick. But I whant this state as a debuff and not a buff. So lets say I kill a enemy with this state , he explode on all his ally. I thought I can probably get this effect by switching most of the foe word by ally. But something is off cause he doesnt work.

Here the script I have right now.:
Can someone try it ? This script goes in the knockout state.

---------------------------------

State #1 will be automatically added when
HP reaches 0.

// Death Nova
<Custom Apply Effect>
// Get the Death Nova state's ID
var deathNovaId = 74;
// Check if the target is dead and is affected by the Death Nova state
if (target.isDead() && target.isStateAffected(deathNovaId)) {
// Get the poison state
var poisonId = 4;
// Get the original caster for the Death Nova state
var caster = target.stateOrigin(deathNovaId);
// Calculate the damage dealt
var dmg = caster.mat * 3;
// Get the dying unit's opponents
var foes = target.opponentsUnit().aliveMembers();
// Loop through the foes
for (var i = 0; i < foes.length; ++i) {
// Get the currently looped foe
var foe = foes;
// Check if the ally exists
if (ally) {
// Make the ally take damage.
ally.gainHp(-dmg);
// Add the poison state to the ally.
ally.addState(4);
// Show the damage popup.
ally.startDamagePopup();
// Check if the ally is dead
if (ally.isDead()) {
// If it is, collapse the ally
ally.performCollapse();
}
// Clear the ally's results
ally.clearResult();
}
}
// Play an animation on the dying unit
target.startAnimation(109);
// Remove the Death Nova state
target.removeState(74);
}
</Custom Apply Effect>
My guess is it's happening here:

// Get the dying unit's opponents
var foes = target.opponentsUnit().aliveMembers();
// Loop through the foes
for (var i = 0; i < foes.length; ++i) {
// Get the currently looped foe
var foe = foes;
// Check if the ally exists
if (ally) {


After all, "ally" as you've defined it here, I think, isn't a built in keyword but a variable you're suppsoed to define... except you never defined it at the first point you're using it (("if (ally)")), so it will return false and therefore nothing inside that branch will run. I think you will need to change the line "var foe = foes{i}" to "var ally = foes{i}" ((NOTE: replace curly brackets { and } in the line above with regular brackets [ and ] - the forum thought I was asking for italics lol)), meaning that your temporary variable called "ally" will be the object at spot "i" in the array of enemies in battle (as you're looping through and increasing i, this means you're looking at every enemy, which is good).

It's possible there's something else also going wrong, but this is what I see as probably the main issue.
I will try that soon. Here his the original scrip from yanfly maybe it could be easier with that to find the problem. This version work but act mosly like a buff rather then a buff.

---------

// Death Nova
<Custom Apply Effect>
// Get the Death Nova state's ID
var deathNovaId = 271;
// Check if the target is dead and is affected by the Death Nova state
if (target.isDead() && target.isStateAffected(deathNovaId)) {
// Get the poison state
var poisonId = 37;
// Get the original caster for the Death Nova state
var caster = target.stateOrigin(deathNovaId);
// Calculate the damage dealt
var dmg = caster.mat * 6;
// Get the dying unit's opponents
var foes = target.opponentsUnit().aliveMembers();
// Loop through the foes
for (var i = 0; i < foes.length; ++i) {
// Get the currently looped foe
var foe = foes;
// Check if the foe exists
if (foe) {
// Make the foe take damage.
foe.gainHp(-dmg);
// Add the poison state to the foe.
foe.addState(poisonId);
// Show the damage popup.
foe.startDamagePopup();
// Check if the foe is dead
if (foe.isDead()) {
// If it is, collapse the foe
foe.performCollapse();
}
// Clear the foe's results
foe.clearResult();
}
}
// Play an animation on the dying unit
target.startAnimation(109);
// Remove the Death Nova state
target.removeState(deathNovaId);
}
</Custom Apply Effect>
Here a link to the original plugin.

Original thread: https://forums.rpgmakerweb.com/threads/death-nova-modification.129818/