Yanfly Damage Core Support (can someone move this to Plugin support?)

For my RPG, I am using ICF-Soft's custom parameters and a bunch of Yanfly plugins, and I need help implementing an idea I had.

One of the custom stats I added is Intellect, which I want to do two things. First, I want it to govern how powerful items are. Second- and more to the point- I want it to affect how much damage is done when an elemental weakness or resistance is involved.

Here's how I want it to work:

Instead of working on a multiplier, there will instead be a fixed bonus/penalty. If the spell hits for an elemental weakness, the damage will be increased by the attacker's Intellect x their Level. However, if it's not a spell, but rather an elemental affinity affixed to their weapon, this number is halved. Then, if the enemy is extremely weak to that element, this bonus is multiplied by 2.

However, if the enemy is resistant to that element, the damage is reduced by the DEFENDER'S Intellect x DEFENDER'S Level, with the same multiplier based on how resilient they are. If they absorb that element (say, an Ice elemental taking ice damage), the formula wouldn't apply and they'd just absorb HP the normal damage.

I need a plugin that will not override the normal Yanfly element plugin, but instead just add another thing alongside it (so I can give them 0% damage from one element but add the custom formula for another element as a notetag)
You can do this with the custom damage formula from Yanfly's plugins.

Here is a heavily truncated damage formula I'm using, just to give you an idea of how complicated you can make it. Really the sky is the limit, you can change any of your variables, add more, do crazy math with them.

Just make sure to turn the variance off (unless you're not using random numbers in your formula), and set the skill to HP Damage.

I use a combination of states to do all my heavy lifting, but you can also use equipped weapons, elemental types on attacks.

Spoiler: Damage Formula
<damage formula>
var dmg = 1;
if (user.isWtypeEquipped(2) || user.isWtypeEquipped(12) || user.isWtypeEquipped(13) || user.isWtypeEquipped(16)) //swords - spears - katanas
{
var attack = a.atk + Math.randomInt(a.atk/8);
var M = ((a.level*a.luk)/128 + 2);
var dfn = b.def;
}
else if (user.isWtypeEquipped(1) || user.isWtypeEquipped(9) || user.isWtypeEquipped(7) || user.isWtypeEquipped(10) || user.isWtypeEquipped(5)) //knives - bows - whips - claws
{
var attack = a.atk + Math.randomInt(3);
var M = ((a.level*a.luk)/256 + (a.level*a.agi)/256 + 2);
var dfn = b.def
}
else
{
var attack = Math.randomInt(a.atk) * 2;
var M = ((a.level*a.mat)/256 + 2);
var dfn = b.mdf
}
}
if (user.isStateAffected(7)) //Berserk
{
attack = attack * 3/2;
}
if (b.isStateAffected(29) || (b.isStateAffected(112)))//shell defense boost
{
M = M / 2;
}
if (user.attackElements() == 3) //thunder weapon
{
if (b.isStateAffected(43)) //thunder Vulnerable
{
attack = attack * 2;
dfn = 0;
}
if (user.isStateAffected(53)) //thunder damage boost
{
attack = attack * 2;
}
if (b.isStateAffected(63)) //thunder half damage
{
attack = attack / 2;
}
}
if (b.isEquippedArmor(6)) //Aegis Nullify
{
var aegis = 0;
aegis = Math.random();
if (aegis >= 0.33) {
attack = 0;
}
}
if (user.isEquippedArmor(171)) //Barrier Bit
{
var M = M / 2;
}
if (user.isEquippedArmor(187) && !user.isStateAffected(13)) //Deathgrip gloves
{
var M = M * 2;
}
if (user.isStateAffected(100) ) //Attacker Backrow
{
var M = M / 2;
}
if (b.isStateAffected(100) ) //Defender Backrow
{
var M = M / 2;
}
value = (attack - dfn) * M;
dmg = value;
</damage formula>
You can do this with the custom damage formula from Yanfly's plugins.

Here is a heavily truncated damage formula I'm using, just to give you an idea of how complicated you can make it. Really the sky is the limit, you can change any of your variables, add more, do crazy math with them.

Just make sure to turn the variance off (unless you're not using random numbers in your formula), and set the skill to HP Damage.

I use a combination of states to do all my heavy lifting, but you can also use equipped weapons, elemental types on attacks.

Spoiler: Damage Formula
<damage formula>
var dmg = 1;
if (user.isWtypeEquipped(2) || user.isWtypeEquipped(12) || user.isWtypeEquipped(13) || user.isWtypeEquipped(16)) //swords - spears - katanas
{
var attack = a.atk + Math.randomInt(a.atk/8);
var M = ((a.level*a.luk)/128 + 2);
var dfn = b.def;
}
else if (user.isWtypeEquipped(1) || user.isWtypeEquipped(9) || user.isWtypeEquipped(7) || user.isWtypeEquipped(10) || user.isWtypeEquipped(5)) //knives - bows - whips - claws
{
var attack = a.atk + Math.randomInt(3);
var M = ((a.level*a.luk)/256 + (a.level*a.agi)/256 + 2);
var dfn = b.def
}
else
{
var attack = Math.randomInt(a.atk) * 2;
var M = ((a.level*a.mat)/256 + 2);
var dfn = b.mdf
}
}
if (user.isStateAffected(7)) //Berserk
{
attack = attack * 3/2;
}
if (b.isStateAffected(29) || (b.isStateAffected(112)))//shell defense boost
{
M = M / 2;
}
if (user.attackElements() == 3) //thunder weapon
{
if (b.isStateAffected(43)) //thunder Vulnerable
{
attack = attack * 2;
dfn = 0;
}
if (user.isStateAffected(53)) //thunder damage boost
{
attack = attack * 2;
}
if (b.isStateAffected(63)) //thunder half damage
{
attack = attack / 2;
}
}
if (b.isEquippedArmor(6)) //Aegis Nullify
{
var aegis = 0;
aegis = Math.random();
if (aegis >= 0.33) {
attack = 0;
}
}
if (user.isEquippedArmor(171)) //Barrier Bit
{
var M = M / 2;
}
if (user.isEquippedArmor(187) && !user.isStateAffected(13)) //Deathgrip gloves
{
var M = M * 2;
}
if (user.isStateAffected(100) ) //Attacker Backrow
{
var M = M / 2;
}
if (b.isStateAffected(100) ) //Defender Backrow
{
var M = M / 2;
}
value = (attack - dfn) * M;
dmg = value;
</damage formula>
Sorry it took so long to get back to you, I decided to take a break from working on it for a while due to real life business.

Now that I'm back, I decided to screw around with the Damage Core and I have absolutely zero idea what I'm doing. I know what I WANT to do, but I suck at actually coding it.

What I want to do is add something to the effect of THIS. For the record, I changed my mind about keeping the original percentage in, and "dlv" is another custom attribute I use to stand in for an enemy's level.

If the Element Rate is above 100, then add to the original damage
= (ElementRate-100)*(a.int * a.dlv)

If the Element Rate is below 100, then subtract from the original damage
= (ElementRate+50)*(b.int * b.dlv)

Like I said before. I know exactly what I want it to do, I just have no idea how to implement it.
So a few things, Assuming ElementRate is actually the in game Element Rate,it should be pretty easy.

<damage formula>
var attack = (your_attack_formula_here);
ElementRate = user.elementRate(<elementId>); \\you'll need to specify each element rate separately.
if (ElementRate >= 100) \\check the element rate of the attack against your threshold
{
attack = attack + (ElementRate-100)*(a.int * a.dlv); \\modifies your attack value by the element rate.
}
if (ElementRate < 100)
{
attack = attack + (ElementRate+50)*(b.int * b.dlv); \\modifies your attack value by the element rate.
}
value = attack; \\sets the damage to the attack value.
</damage formula>

if ElementRate is something like a game variable you have stored somewhere, you'll need to call it. This would get super complicated to refresh for each battler, but I guess possible.

<damage formula>
var attack = (your_attack_formula_here);
var ElementRate = $gameVariables.value(X); \\set X to whatever variable you're using
if (ElementRate >= 100) \\check the element rate of the attack against your threshold
{
attack = attack + (ElementRate-100)*(a.int * a.dlv); \\modifies your attack value by the element rate.
}
if (ElementRate < 100)
{
attack = attack + (ElementRate+50)*(b.int * b.dlv); \\modifies your attack value by the element rate.
}
value = attack; \\sets the damage to the attack value.
</damage formula>

**I am a terrible javascript coder, so this is going to require more than a little debugging and I haven't tried it in the system yet.
So a few things, Assuming ElementRate is actually the in game Element Rate,it should be pretty easy.

<damage formula>
var attack = (your_attack_formula_here);
ElementRate = user.elementRate(<elementId>); \\you'll need to specify each element rate separately.
if (ElementRate >= 100) \\check the element rate of the attack against your threshold
{
attack = attack + (ElementRate-100)*(a.int * a.dlv); \\modifies your attack value by the element rate.
}
if (ElementRate < 100)
{
attack = attack + (ElementRate+50)*(b.int * b.dlv); \\modifies your attack value by the element rate.
}
value = attack; \\sets the damage to the attack value.
</damage formula>

if ElementRate is something like a game variable you have stored somewhere, you'll need to call it. This would get super complicated to refresh for each battler, but I guess possible.

<damage formula>
var attack = (your_attack_formula_here);
var ElementRate = $gameVariables.value(X); \\set X to whatever variable you're using
if (ElementRate >= 100) \\check the element rate of the attack against your threshold
{
attack = attack + (ElementRate-100)*(a.int * a.dlv); \\modifies your attack value by the element rate.
}
if (ElementRate < 100)
{
attack = attack + (ElementRate+50)*(b.int * b.dlv); \\modifies your attack value by the element rate.
}
value = attack; \\sets the damage to the attack value.
</damage formula>

**I am a terrible javascript coder, so this is going to require more than a little debugging and I haven't tried it in the system yet.
Thanks. The Element Rate I am using is indeed the built-in one in MV, so hopefully this will work. Once I have had the chance to try and put it in, I'll get back to you. There are 9 elements in this game, so I'll have to implement it 9 times. I'll let you know how that works out.
Just thinking about simplifying things a bit:

<damage formula>
var attack = (your_attack_formula_here);
if (user.elementRate(<elementId>) >= 100) \\check the element rate of the attack against your threshold
{
attack = attack + (user.elementRate(<elementId>)-100)*(a.int * a.dlv); \\modifies your attack value by the element rate.
}
if (user.elementRate(<elementId>) < 100)
{
attack = attack + (user.elementRate(<elementId>)+50)*(b.int * b.dlv); \\modifies your attack value by the element rate.
}
value = attack; \\sets the damage to the attack value.
</damage formula>

Then just repeat that If statement 9 times, and replace the <elementID> with your element numbers.
Just thinking about simplifying things a bit:

<damage formula>
var attack = (your_attack_formula_here);
if (user.elementRate(<elementId>) >= 100) \\check the element rate of the attack against your threshold
{
attack = attack + (user.elementRate(<elementId>)-100)*(a.int * a.dlv); \\modifies your attack value by the element rate.
}
if (user.elementRate(<elementId>) < 100)
{
attack = attack + (user.elementRate(<elementId>)+50)*(b.int * b.dlv); \\modifies your attack value by the element rate.
}
value = attack; \\sets the damage to the attack value.
</damage formula>

Then just repeat that If statement 9 times, and replace the <elementID> with your element numbers.

I keep getting the error message "require(...).Window.get(...)isDevToolsOpen is not a function"

Any advice?
All right, I managed to get the game to stop crashing. However, I can't seem to get it to work.

Here's what I got for the formula:

if (this.calcElementRate(target) >= 1)
{
baseDamage += ((this.calcElementRate(target)-1)*(a.int * a.dlv));
}
if (this.calcElementRate(target) < 1)
{
baseDamage -= ((this.calcElementRate(target)+1)*(b.int * b.dlv));
}
value = baseDamage;

However, this isn't working. Here's what's going on with my tests.

I'm testing this by setting the main mage of this game, Charon, against an enemy, with the spells temporarily set to have 0 variance. The enemy has an element rate of 200% for Fire and 0% for Ice.
Both Charon and the enemy have had their dlv and int both set to 7
Because it has no special resistance or weakness top Thunder, I use the Volt spell as the control (these 3 spells have the same damage formula, by the way). It does 96 damage.
When I cast Pyre, the fire spell, it deals 159 damage. The damage algorithm I want is:
BaseDamage + (ElementRate - 1)(a.int * a.dlv)
so the damage SHOULD be:
96 + 1(49) = 145
I have no idea where it got 159.

Now let's try casting Frost. This spell dealt 47 damage. Since this is an elemental resistance, the damage algorithm I want is:
BaseDamage - (ElementRate + 1)(b.int * b.dlv)
the damage should be:
96 - 1(49) = 47
So logically, we can infer that this part of the damage formula is working properly.

But the worst part is that during the enemy's turn, it uses a normal physical attack that does NOTHING.

Just to make sure I didn't make a mistake with the stats, I disabled the damage formula and tried again. Note that because the only part of the Damage Core I changed pertained to the element rate portion, normal physical damage would be unchanged. And the physical damage it dealt per attack was indeed in the ballpark of 28, as it should be.

So, to sum up:
-The elemental resistance formula is working like a charm.
-The elemental weakness formula almost works, but pulls some random number out of thin air.
-When the enemy attacks me, I always take 0 damage.

Working on a hunch, I decided to give the enemy spells to see what happened. After giving him Pyre and making sure his and Charon's stats were identical (in everything used to calculate magic damage- Magic Atk, Magic Def, and dlv- it dealt 78 damage to Charon, even though the two spells should have been identical in damage.

It would appear that when the game calculates the enemy's int and dlv, it works fine. But when it calculates the player's stats, that's when everything seems to go wonky.

If there's an expert at javascript who knows what's going on, could you tell me please? I don't want to start seriously working on the game until I get the main mechanics completely ironed out.
Okay, you might have already resolved this, but do your enemies have "dlv" established as a custom variable for them?

There may also be an issue with the enemy battlers and the "this" function, I forget if that plays nicely with damage core or not. I personally do not use it, but I have horrible spaghetti code.
Okay, you might have already resolved this, but do your enemies have "dlv" established as a custom variable for them?

There may also be an issue with the enemy battlers and the "this" function, I forget if that plays nicely with damage core or not. I personally do not use it, but I have horrible spaghetti code.
I... think it's a custom variable? I mean, I set their dlv in the notetags. In case you're wondering, dlv is meant to represent an enemy's level in the calculation of how much damage is reduced by defense. (I set it so that a party member's dlv is equal to their level)

Both that and intellect are both custom attributes I added via ICF-Soft's plugins. And truth be told, I don't even know what the "this" function even does. I'm just holding out for someone who actually knows how JS works.

Really, my biggest issue is figuring out why an enemy attacking my character does 0 damage with this formula in effect.

EDIT: I'm relocating this thread to Plugin Support, let's try to keep it over there

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-damage-core-support-can-someone-move-this-to-plugin-support.97599/