Damage Over Time: Yanfly's Plugin

Hello, I have a question about how to fix this code or just some more explanation. 


Basically, I'm I took Yanfly's Unstable Affliction skill and found a user on his Youtube that post the following code: 


<Custom Regenerate Effect>
// Get the Darkness element.
var elementId = 10;
// Damage set to equal the origin's MAT.
var damage = origin.mat;
// Damage multiplier for weakness/resistance to Darkness element.
damage *= user.elementRate(elementId);
// Round down the damage, apply mdf and mdr.
damage = Math.floor((damage * 100 / (100 + user.mdf)) * user.mdr);
// Inflict damage to the user.
user.gainHp(-damage);
</Custom Regenerate Effect>




I'm trying to take this code and make a formula that basically works like this for the regen effect: 


a.mat * 4 - b.mdef * 2


However, the code above doesn't seem to apply the enemies magic defense. And, the damage = Math.floor((damage * 100/(100+usermdf))*user.mdr); seem sto amplify the damage as if I change 100 to 1, the damage is reduce but if I increase the number to 200, it boost the damage. Taking the players defense to 999 doesn't even mitigate the damage. Any help 😀



Thanks!
Try this:


<Custom Regenerate Effect>
// Get the Darkness element.
var elementId = 10;
// Round down the damage, apply formula.
var damage = Math.floor((origin.mat * 4 - user.mdf * 2) * user.mdr);
// Damage multiplier for weakness/resistance to Darkness element.
damage *= user.elementRate(elementId);
// Inflict damage to the user, caps at zero to prevent unintentional healing.
user.gainHp(Math.min(-damage, 0));
</Custom Regenerate Effect>




For states as far as I can tell, 'origin' is the original caster (a) and 'user' is the person inflicted with the state (b)


a.mat * 4 - b.mdf * 2  = origin.mat * 4 - user.mdf * 2


I have moved the elemental multiplier after the formula to better emulate how skills normally work, in addition the damage is capped at 0 so there wont be accidental healing if MDF is too high.


Remember to change the element ID if needed
I love you so much! Can I make a statue of you 😀 <3!!! I'll check it out. 


If user isn't "correct", what could be some other terms I could try. 


Thanks! 


This works just fine. Thanks for the help. 

Original thread: https://forums.rpgmakerweb.com/threads/damage-over-time-yanflys-plugin.60986/