How do I make a debuff that explodes for damage after x amount of turns?

Hello! As the title states, I am trying to make a debuff that if not removed by cleansing spells will explode and deal damage to the person its on. Also, if you also know how to make the explosion hit the entire party, I could also use that information for another debuff as well. (Not sure if it would be a simple change or not to make it hit all PCs) And if you’re even more knowledgeable and are willing to go the extra mile, is there a way to apply another debuff if the original debuff explodes? Perhaps the explosion could apply damage dealt down as a punishment for just trying to heal through it.

I have all of the Yanfly plugins, but I'm not familiar with scripting so I'm not sure what to do exactly. Any help is greatly appreciated! 🙂
Buffs and States Core is enough to make this. I think you can try this in the state:
Code:
<Custom Leave Effect>
user.startAnimation(x); //X is your animation ID in case you wanna show some animation
var dmg = y; //Y is the damage set by you. Tell me if you want a more complex damage formula.
user.gainHp(-dmg);
</Custom Leave Effect>
Thank you! Do you happen to know how to make the damage hit the entire party, or how to inflict a debuff along with the damage?
Sure. I can do the explosion damage to hit all other enemies (both including and excluding the target) and apply a new state to them. Tell me in detail if you want to do that.
P/s: There was a mistake in the above formula (-y). It should be (-dmg). I made a fix so please check again.
Sure. I can do the explosion damage to hit all other enemies (both including and excluding the target) and apply a new state to them. Tell me in detail if you want to do that.
P/s: There was a mistake in the above formula (-y). It should be (-dmg). I made a fix so please check again.
I'd prefer a version of the code you've already provided that hits all player characters, including the main target, as well as a separate code that applies debuff x if the original debuff explodes from expiring. Not sure if you'd need anymore details, but let me know if you do!
Thanks for the update on the original code and for your help so far! 🙂
Well, I will make 2 versions as you said below:

1. Target explodes, damaging all of its allies including itself:
Code:
<Custom Leave Effect>
//Set the damage with X is the explosion damage
var dmg = x;
// Get the living members of the same party (all other enemies).
var members = user.friendsUnit().aliveMembers();
// Make an empty group to list affected members.
var affected = [];
// We'll go through each member to check them.
for (var i = 0; i < members.length; ++i) {
// Getting the individual member.
var member = members[i];
affected.push(member);}
// We'll go through each of the affected members now.
for (var i = 0; i < affected.length; ++i){
// Getting the individual affected member.
var member = affected[i];
// Ignore the effect if the member is the target of attack.
// Let's play animation y on the affected member.
member.startAnimation(y);
// The affected member takes damage.
member.gainHp(-dmg);
// We'll have the affected member reveal a damage popup.
member.startDamagePopup();
// Clear the results of the effect.
member.clearResult();
// Next, check to see if the member is dead.
if (member.isDead()){
// If the member is dead, we'll make it collapse.
member.performCollapse();}}
</Custom Leave Effect>

2. Target explodes, adding new negative state to itself. This is easy. Just add another line of code to the original codes I gave you before
Code:
<Custom Leave Effect>
user.startAnimation(x); //X is your animation ID in case you wanna show some animation
var dmg = y; //Y is the damage set by you.
user.gainHp(-dmg);
user.addState(z); //Z is another state ID
</Custom Leave Effect>
Thank you so much for your help! I'll test these soon (I'm busy with irl stuff at the moment) and let you know if I need any more help! 🙂
Ok please let me know if it works or if you encounter some weird things.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-a-debuff-that-explodes-for-damage-after-x-amount-of-turns.138899/