MV Animal Scream

Upon defeating an enemy and dealing damage greater than
30% of their health, all enemies
receive a 20% ATK and 25% ARM debuff
for 3 turns.

This state is in the actor, as a passive.

I'm trying to do this, without success, I'm trying this way, do you know what's wrong?



<Custom Conclude Effect>

var enemies = $gameTroop.members();

for (var i = 0; i < enemies.length; i++) {

var target = enemies;

if (target.isDead() && target._lastHpDamageFromUser) {

var limiar = Math.floor(target.mhp * 0.30);

if (target._lastHpDamageFromUser >= limiar) {

var debuffState = 243;

for (var j = 0; j < enemies.length; j++) {

var other = enemies[j];

if (!other.isDead() && other !== target) {

other.addState(debuffState);

}

}

}

target._lastHpDamageFromUser = undefined;

}

}

</Custom Conclude Effect>
since this is a request for help involving a plugin,

I'll be moving this thread to Plugin Support



when youre sharing code on these forums, put it within [CODE] [/CODE] tags or use the code option on the top of the text box. if you dont, itll become standard text and standard text gets formatted in ways that makes it harder to read code.
you lose indents and then some things youd write in code gets removed. for example, you probably meant var target = enemies[i];, but in standard text, the [i] is a tag to start italicizing text and you end up with var target = enemies; and the rest of your text in italics


<Custom Conclude Effect>
since you want to check how much damage you did and that requires a hit, you want to use an establish effect for this. they only run if the attack hit the target and theres a value variable that has the value of the damage the battler dealt

_lastHpDamageFromUser
im not sure what plugin youre getting that from, but you dont need it because of above

var target = enemies;
There is also a targetvariable predefined that refers to the current target. you dont to loop through the troop to see if any of them are dead, and the way you have it would mean doing more than 30% of any enemy's max hp causes all foes to get the state

if (target.isDead() && target._lastHpDamageFromUser) {
if youre using yanfly's battle engine core, target.isDead()doesnt work for this. battlers being hit dont die until the end of the skill, so if youre trying to see if the current skill has killed/is going to kill them, that way cant be used

for (var j = 0; j < enemies.length; j++) {
you already had a loop going through all the enemies and checking if they were dead and if enough damage was dealt to them. this 2nd loop wont accomplish much more than applying the same debuff multiple times when it can, which isnt necessary

Code:
<Custom Establish Effect>
if (target.hp === 0 && !target.isStateResist(1) && value >= target.mhp * 0.3)
  target.friendsUnit().aliveMembers().forEach(enemy => {
    enemy.addState(243)
  });
</Custom Establish Effect>
since this is a request for help involving a plugin, Moderator note: I'll be moving this thread to Plugin Support

when youre sharing code on these forums, put it within [CODE] [/CODE] tags or use the code option on the top of the text box. if you dont, itll become standard text and standard text gets formatted in ways that makes it harder to read code.
you lose indents and then some things youd write in code gets removed. for example, you probably meant var target = enemies[i];, but in standard text, the [i] is a tag to start italicizing text and you end up with var target = enemies; and the rest of your text in italics



since you want to check how much damage you did and that requires a hit, you want to use an establish effect for this. they only run if the attack hit the target and theres a value variable that has the value of the damage the battler dealt


im not sure what plugin youre getting that from, but you dont need it because of above


There is also a targetvariable predefined that refers to the current target. you dont to loop through the troop to see if any of them are dead, and the way you have it would mean doing more than 30% of any enemy's max hp causes all foes to get the state


if youre using yanfly's battle engine core, target.isDead()doesnt work for this. battlers being hit dont die until the end of the skill, so if youre trying to see if the current skill has killed/is going to kill them, that way cant be used


you already had a loop going through all the enemies and checking if they were dead and if enough damage was dealt to them. this 2nd loop wont accomplish much more than applying the same debuff multiple times when it can, which isnt necessary

Code:
<Custom Establish Effect>
if (target.hp === 0 && !target.isStateResist(1) && value >= target.mhp * 0.3)
  target.friendsUnit().aliveMembers().forEach(enemy => {
    enemy.addState(243)
  });
</Custom Establish Effect>
Thank you, I didn't know about the "Code" I apologize, I tried the script you sent me, but without success



I tried without the "if" and it worked
I tried the script you sent me, but without success
i forgot yanfly's battle engine core also makes isStateResist() for death states false during skills to prevent targets from dying mid skill🤣
if anything, it can just be removed
Code:
<Custom Establish Effect>
if (target.hp === 0 && value >= target.mhp * 0.3)
  target.friendsUnit().aliveMembers().forEach(enemy => {
    enemy.addState(243)
  });
</Custom Establish Effect>
i forgot yanfly's battle engine core also makes isStateResist() for death states false during skills to prevent targets from dying mid skill🤣
if anything, it can just be removed
Code:
<Custom Establish Effect>
if (target.hp === 0 && value >= target.mhp * 0.3)
  target.friendsUnit().aliveMembers().forEach(enemy => {
    enemy.addState(243)
  });
</Custom Establish Effect>


I was trying here, and it worked, thank you very much.

Code:
<Custom Establish Effect>
if (target.hp <= 0 && value >= target.mhp * 0.3) {
  target.friendsUnit().aliveMembers().forEach(enemy => {
    enemy.addState(243)
  });
}
</Custom Establish Effect>

i forgot yanfly's battle engine core also makes isStateResist() for death states false during skills to prevent targets from dying mid skill🤣
if anything, it can just be removed
Code:
<Custom Establish Effect>
if (target.hp === 0 && value >= target.mhp * 0.3)
  target.friendsUnit().aliveMembers().forEach(enemy => {
    enemy.addState(243)
  });
</Custom Establish Effect>


I always thought that after "if" you needed a "{", I was wrong all along
I always thought that after "if" you needed a "{", I was wrong all along
the curly brace is optional if the "if" only does a single statement. if there is no curly brace, then the "if" only executes the next statement.

it doesnt hurt to always use the curly braces, but if you know ahead of time that youre only going to be doing one thing, they can be skipped. There are other times where you may or may not need them as well. as an example, i was initially going to add more into the forEach loop and would have needed a set there, but ended up not doing what i planned to do with it.

Original thread: https://forums.rpgmakerweb.com/threads/animal-scream.180277/