I dunno, seems like you're trying too hard to reinvent the wheel when you could just use a plugin. I don't mean to be all self-promote-y, but AES_BattleCore, linked in my sig, lets you add extra "death states" so that, rather than killing affected party members affected by petrify, they can be left petrified and still have it count toward a game over. So if 1 was petrified, 2 was petrified, and 3 was killed by damage, you'd get a game over as if all 3 were dead. Looks better.
That aside...
@TSR ok i tried this one in the battle event and works, but there's a bug, even if all three heroes receive petrify, only 2 at the end of turn die, the third (middle one) die the turn after, after receiving another bunch of attacks(still petrified) why?
for (i in $gameParty.aliveMembers()){
if ($gameParty.aliveMembers()
.isStateAffected(2)) {
var h = $gameParty.aliveMembers().hp;
$gameParty.aliveMembers().gainHp(-h);
}
};
the battle event condition is set to turn end -- turn
edit, with 4 battlers, the first and third died at 1 turn, the second at 2, the fourth at 3.
strange.
The reason they're not all being killed is because of your loop logic. I'll explain:
Assuming a party of 3 members, all of which are alive:
- $gameParty.aliveMembers().length == 3
- "i" points to the party member in position 0 (first party member)
- Party member 0 is affected, so they die
- $gameParty.aliveMembers().length == 2
- "i" points to the party member in position 1 (second party member)
- Party member 1 is affected, so they die
- $gameParty.aliveMembers().length == 1
- The loop says, "okay, we're at position 1 and the length is only 1, so we're done processing. The third party member gets skipped.
To bypass this, you generally want to iterate backward through an array:
Code:
for (var i = $gameParty.aliveMembers().length - 1; i > -1; i--)
{
if ($gameParty.aliveMembers()[i].isStateAffected(2)) $gameParty.aliveMembers()[i].addState(1);
}
That said, state 2 is generally reserved for Guard and should probably be left alone. It's not a good idea to start adding custom states until 004.