MV Yanfly Skill Help: Detonating a DOT from Smite

Hello,

I've recently been trying to recreate two skills from smite's god Zhong Kui, which essentially applies a dot, and if the other skill is used to remove it, they take damage and 75% of the remaining damage is done instantly. I have tried to recreate this with this code but I am having trouble getting effects to run while removing the state, so I'm probably putting my energy into the wrong thing. I'm just looking for the simple numbers of course not an exact recreation, just the main functions.
Spoiler
Code:
<Custom Apply Effect>
this._DemonCounter = 1;
</Custom Apply Effect>

<Custom Regenerate Effect>
var n = this._DemonCounter;
var value = Math.floor(n * 222 * -1);
user.gainHp(value);
this._DemonCounter += 1;
</Custom Regenerate Effect>

  <Custom Leave Effect>
 // Reset the stack count.
this._DemonCounter = 0;
  </Custom Leave Effect>

<Custom Remove Effect>
// Declare the dispeller.
var dispeller = BattleManager._subject;
// Check to see if the effect is a leave effect or removal.
var notLeaveEffect = !$gameTemp._customLeaveEffectEval;
// Check the conditions to see if they're met.
if (dispeller && notLeaveEffect) {
  // Get the Silence status effect.
  var stateId = 6;
  // Get the Darkness element.
  var elementId = 9;
  var n = this._DemonCounter;
  var value = Math.Ceil(222);
  var exorcism = Math.Ceil(value * (n === 3 ? +0 || n === 1 ? +2 || n === 2 ? +1;));
  exorcism *= 0.75;
  exorcism *= target.elementRate(elementId);
  user.startAnimation(102);
  user.addState(stateId);
  user.gainHp(-exorcism);
  user.startDamagePopup();
  if (user.isDead()) {
    user.performCollapse();
  }
  user.clearResult();
}
</Custom Remove Effect>

zhong kui.png
im not sure what this line:

var exorcism = Math.Ceil(value * (n === 3 ? +0 || n === 1 ? +2 || n === 2 ? +1😉);

is meant to be (syntax-wise), BUT, i think your code could be a lot simpler.

and i wouldnt use any common term yanfly uses while creating custom stuff just to be safe. i mean: value, target, user, etc... your value variable would be called nValue, for example... just an observation. now, back to the subject:

what i would, since the custom remove notetag works for both a state decaying or being removed is make the skill/item removing it do the effect and i would be sure to test in every scope if the variable created exists before going using or changing it:

this._DemonCounter = this._DemonCounter || 1;

to make a skill resolve, remove and aplly new states, you can use the custom execution from the skillCore plugin (im assuming you have all yanfly plugins):


Code:
<Custom Execution>
   //check if theres a state to be removed, replace #, you know the drill
   if(b.isStateAffected(#)){
      b.removeState(#);
      //makes the calculation needed
      this._DemonCounter = this.DemonCounter || 1;
      var nValue = 0; //and, then, whatever it needs to be...
      b.gainHp(-nValue);
      b.addState(Y);
      //and so on...
   }
</Custom Execution>


if the removing skill has damage, you could use de custom damage formula (from the damage core plugin).

i hope it helps.
im not sure what this line:

var exorcism = Math.Ceil(value * (n === 3 ? +0 || n === 1 ? +2 || n === 2 ? +1😉);

is meant to be (syntax-wise), BUT, i think your code could be a lot simpler.

and i wouldnt use any common term yanfly uses while creating custom stuff just to be safe. i mean: value, target, user, etc... your value variable would be called nValue, for example... just an observation. now, back to the subject:

what i would, since the custom remove notetag works for both a state decaying or being removed is make the skill/item removing it do the effect and i would be sure to test in every scope if the variable created exists before going using or changing it:

this._DemonCounter = this._DemonCounter || 1;

to make a skill resolve, remove and aplly new states, you can use the custom execution from the skillCore plugin (im assuming you have all yanfly plugins):


Code:
<Custom Execution>
   //check if theres a state to be removed, replace #, you know the drill
   if(b.isStateAffected(#)){
      b.removeState(#);
      //makes the calculation needed
      this._DemonCounter = this.DemonCounter || 1;
      var nValue = 0; //and, then, whatever it needs to be...
      b.gainHp(-nValue);
      b.addState(Y);
      //and so on...
   }
</Custom Execution>


if the removing skill has damage, you could use de custom damage formula (from the damage core plugin).

i hope it helps.
What I was trying to do with the first part was figure out some sort of way of tackling the "75% of the remaining damage the DOT would've done is done instantly" because if used early, it would be more damage but if used later it should be much less. I tried to think of a way to use counters per turn, so I was trying to make it so that (value * (n === 3 ? +0 || n === 1 ? +2 || n === 2 ? +1😉); if the stacks were at the third turn (ie. 3) then add 0 stacks, if turn 2, add the one last stack, if on the first, add 2 stacks, since there is still 2 turns to go. I'm still not entirely sure how to go about that part, even with the idea of using the formula on the second dispelling skill rather than the first state, but this does simplify the code a lot I believe, so I greatly appreciate it 🙂 Any ideas on that part?
well.. have the state create a counter if it dont exists, like you tried to do with the apply effect notetag (but the safe way):

user._DemonCounter = user._DemonCounter || 3;

but make it so that i starts with the number of turns the state would have in total. in this example, im using 3.

then the regenerate notetag:

JavaScript:
<Custom Regenerate Effect>
   user._DemonCounter = user._DemonCounter || 3;
   //then figure out how much should the total damage be,...
   //...create new variables if needed, calculate rates and whatever else you want.
   // and store it in this new counter.
   user._totalDamage = user._totalDamage || 0;
   user._totalDamage = X;  //replace X with the total damage you just calculated.
 
   //now calculate the damage that one fraction would deal. in this example, it would be total damage / 3.
   var value = Math.floor(user._totalDamage / 3);
   user.gainHp(-value);
   //then remove a counter:
   user._DemonCounter--;
   //remove state if counters reach zero:
   if(user._DemonCounter < 1){user.removeState(Y); }// replace Y with this state id.
</Custom Regenerate Effect>

if left alone, each turn the user will lose a fraction.

now the removing skill notetag:

JavaScript:
<Custom Execution>
   //check if theres a state to be removed, replace #, you know the drill
   if(b.isStateAffected(#)){
      b.removeState(#);

      //get the values if they exist (and they should by this point):
      user._DemonCounter = user.DemonCounter || 3;
      user._totalDamage = user._totalDamage || 0;
      //calculating the damage left:
      var nValue = Math.floor(user._totalDamage / (4 - user.DemonCounter));

      //ive made so that, in the formula above, _totalDamage would be the total, half or 30%.
      //you can apply other formulas.
    
      //make the target receive the damage.
      b.gainHp(-nValue);
      //apply states...
      b.addState(Y);
      //and so on... if needed, use the popuDamage command...
   }
</Custom Execution>

basically, what i did was create on the state the _totalDamage that would act along with the _DemonCounter. maybe it helps. double check the code as its around 4:00am around here and im starting to get sleepy...
well.. have the state create a counter if it dont exists, like you tried to do with the apply effect notetag (but the safe way):

user._DemonCounter = user._DemonCounter || 3;

but make it so that i starts with the number of turns the state would have in total. in this example, im using 3.

then the regenerate notetag:

JavaScript:
<Custom Regenerate Effect>
   user._DemonCounter = user._DemonCounter || 3;
   //then figure out how much should the total damage be,...
   //...create new variables if needed, calculate rates and whatever else you want.
   // and store it in this new counter.
   user._totalDamage = user._totalDamage || 0;
   user._totalDamage = X;  //replace X with the total damage you just calculated.

   //now calculate the damage that one fraction would deal. in this example, it would be total damage / 3.
   var value = Math.floor(user._totalDamage / 3);
   user.gainHp(-value);
   //then remove a counter:
   user._DemonCounter--;
   //remove state if counters reach zero:
   if(user._DemonCounter < 1){user.removeState(Y); }// replace Y with this state id.
</Custom Regenerate Effect>

if left alone, each turn the user will lose a fraction.

now the removing skill notetag:

JavaScript:
<Custom Execution>
   //check if theres a state to be removed, replace #, you know the drill
   if(b.isStateAffected(#)){
      b.removeState(#);

      //get the values if they exist (and they should by this point):
      user._DemonCounter = user.DemonCounter || 3;
      user._totalDamage = user._totalDamage || 0;
      //calculating the damage left:
      var nValue = Math.floor(user._totalDamage / (4 - user.DemonCounter));

      //ive made so that, in the formula above, _totalDamage would be the total, half or 30%.
      //you can apply other formulas.
 
      //make the target receive the damage.
      b.gainHp(-nValue);
      //apply states...
      b.addState(Y);
      //and so on... if needed, use the popuDamage command...
   }
</Custom Execution>

basically, what i did was create on the state the _totalDamage that would act along with the _DemonCounter. maybe it helps. double check the code as its around 4:00am around here and im starting to get sleepy...
I can't believe I didn't think of that, thank you, this looks great!

Edit: For some reason I can't remove the state with this removing skill notetag, I tried with another cleanse all states skill and it removed it but I can't get this specific code to remove the state on the enemy. Not sure why, but I have enough to work with here to figure the rest out.
you mean that

b.removeState(Z);

didnt work?

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-skill-help-detonating-a-dot-from-smite.132833/