MV Help with Yanfly's buffs states core

I wanted an attack to apply a state, and when the state is removed, it will take a random chance to deal full or half damage.

This is what i used:

<Custom Remove Effect>

if (target.agi + Math.randomInt(20) + 1 >= 11)

{ target.gaintHP(-((Math.randomInt(6) + (Math.randomInt(6) + (Math.randomInt(6))) {

else { target.gaintHP(-((Math.randomInt(6) + (Math.randomInt(6) + (Math.randomInt(6)) / 2) }



target.startDamagePopup();

// Check if the target is dead.

if (target.isDead()) {

// Make the target collapse.

target.performCollapse();

}

</Custom Remove Effect>

This did not work. And i realized that i probably got wrong, so i tried this to make sure i knew what worked:


<Custom Apply Effect>

var value = (Math.randomInt(6) + Math.randomInt(6) + Math.randomInt(6));

target.gainHP(-value);

</Custom Apply Effect>

this did not work tho, and i took this from yanfly's website

pls help thanks xoxox
please give screenshots of your plugin manager so that we can see which plugins you use and which order they are in.
not looking too closely, but
its gainHp, not gainHP or gaintHP
typo aside, capitalization is important
please give screenshots of your plugin manager so that we can see which plugins you use and which order they are in.
1721551636026.png
When there's that many brackets/parentheses, it's easy to forget one or add an extra one which will make the code not work. I usually simplify stuff into a var when using huge complex formulas.

I don't think you need the apply effect portion of the code, just the remove portion?

JavaScript:
<Custom Remove Effect>
var dmg = (Math.randomInt(6) + Math.randomInt(6) + Math.randomInt(6))


if ((target.agi + Math.randomInt(20) + 1) >= 11){
    target.gainHP(-dmg)
    }
else {
//Mathround is used so that the damage value result isnt a decimal
    var half = (Math.round(dmg * 0.5))
    target.gainHP(-half)
    }

target.startDamagePopup();
// Check if the target is dead.
if (target.isDead()) {
// Make the target collapse.
target.performCollapse();
}
</Custom Remove Effect>

I think this is how it would be done? I'm not the best at coding tho
I think this is how it would be done? I'm not the best at coding tho
the logic works, but strictly speaking, you dont need that half variable. its used one time and is value based on an existing variable that also isnt used again later if agi check passes. you could calculate the rolls, make that agi check, halve it there, and then run the gainHp function regardless without the need for an else

Code:
var dmg = (Math.randomInt(6) + Math.randomInt(6) + Math.randomInt(6))
if (!(target.agi + Math.randomInt(20) + 1) >= 11)
  dmg = (Math.round(dmg * 0.5));
target.gainHp(-dmg);
 
target.startDamagePopup();

but as ive said already,
its gainHp, not gainHP or gaintHP
The game would give an error and wouldnt run gainHP. the function is gainHp

Original thread: https://forums.rpgmakerweb.com/threads/help-with-yanflys-buffs-states-core.170489/