MV Attacks with multiple damage formulas?

I’ve bee working on a timed defense mechanic for my game. There would be an aspect of that system where the player would be able to counter the enemy with their own damage on a successful defense. There’s a small problem however:

I have been using Yanfly’s Action Sequences and have it set that the action effect is set to the user, which I think the damage calc is drawing from the enemy instead of the party. If ever I wanted to add effects that boost counter damage, this may not work.

Is there a way where I can add a second damage formula to account for this, or make some way to add the party’s own damage to this mechanic?
Code:
Game_Battler.prototype.attack = function(a, b) {
    if (a.isActor()) {
        damage = "formula"
        return damage
    }
    else {
        damage = "formula"
        return damage
    }
}

This will allow you to have 2 formulas for the same skill, in this case actor and enemy.
Not 100% sure if this will be what you're wanting, but might be a spot to start?

the code can be made as a plugin and works anywhere in the plugin order, really.

To call the specified attack "a.attack(a, b)" into the damage formula box in the database, where 'attack' is whatever name you put into the code as the attack name, like this:
1756060300455.png


Just make sure you edit the formula for each section accordingly 😀
Code:
Game_Battler.prototype.attack = function(a, b) {
    if (a.isActor()) {
        damage = "formula"
        return damage
    }
    else {
        damage = "formula"
        return damage
    }
}

This will allow you to have 2 formulas for the same skill, in this case actor and enemy.
Not 100% sure if this will be what you're wanting, but might be a spot to start?

the code can be made as a plugin and works anywhere in the plugin order, really.

To call the specified attack "a.attack(a, b)" into the damage formula box in the database, where 'attack' is whatever name you put into the code as the attack name, like this:
View attachment 348219

Just make sure you edit the formula for each section accordingly 😀
would the “formula” be whatever the damage formula for that for the situation would be?
Yes, so like 'a.atk * 4 - b.def * 2'

These formula, since written in the plugin file can be as complicated or simple as you would want, and is much easier (to me) to edit than a single like code like the database editor.

Here is an example of one of my spells I've made for my game that both players and enemies have access to, but have FAR different formula effects... mainly as an example to show just how much more you can do and how much cleaner it can look. 😀

Code:
Game_Battler.prototype.flame = function(a, b) {
    if (a.isActor()) {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*1.50
        damage *= 1.40
        damage *= ($gameVariables.value(8)*0.02)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        // console.log(a._name+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
    else {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*2.25
        damage *= 1.40
        damage *= (b.level*0.05)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        // console.log(a.originalName()+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
}

(the 2 commented out lines for sending data to the console lets me see the damage values with variance for balancing stats)
Yes, so like 'a.atk * 4 - b.def * 2'

These formula, since written in the plugin file can be as complicated or simple as you would want, and is much easier (to me) to edit than a single like code like the database editor.

Here is an example of one of my spells I've made for my game that both players and enemies have access to, but have FAR different formula effects... mainly as an example to show just how much more you can do and how much cleaner it can look. 😀

Code:
Game_Battler.prototype.flame = function(a, b) {
    if (a.isActor()) {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*1.50
        damage *= 1.40
        damage *= ($gameVariables.value(8)*0.02)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        // console.log(a._name+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
    else {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*2.25
        damage *= 1.40
        damage *= (b.level*0.05)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        // console.log(a.originalName()+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
}

(the 2 commented out lines for sending data to the console lets me see the damage values with variance for balancing stats)
Code:
CHANGE SWITCH 25: on
CHANGE VARIABLE 11 = 1

START SEQUENCE INPUT: ok, 6

END SEQUENCE INPUT

if (target.isAffected(10))
 action effect
else
 if (Input.isPressed('shift'))
  SE: Blow1
  motion guard: target
  wait: 10
  CHANGE VARIABLE 11 = 2
  action effect
  CHANGE VARIABLE 11 = 1
  wait: 5
  CHANGE SWITCH 25: off
 else if $gameVariables.value(6) < 5
  action effect
  wait: 5
  CHANGE SWITCH 25: off
 else
  SE: Sword2
  motion guard: target
  wait: 5
 end
end
death break

if $gameSwitches.value(25) == true
 FLASH SCREEN: 0, 255, 255, 50, 5
 SE: Attack1
 wait: 5
 motion attack: target
 wait 5
 animation 2: user
 wait for animation
 action effect: user
end
Here's the code that I have currently for an attack, using both yanfly's Action Sequences, and Sumrndmdde's Sequence Inputs, if it would help to understand how to apply what I'm considering here.
Yes, so like 'a.atk * 4 - b.def * 2'

These formula, since written in the plugin file can be as complicated or simple as you would want, and is much easier (to me) to edit than a single like code like the database editor.

Here is an example of one of my spells I've made for my game that both players and enemies have access to, but have FAR different formula effects... mainly as an example to show just how much more you can do and how much cleaner it can look. 😀

Code:
Game_Battler.prototype.flame = function(a, b) {
    if (a.isActor()) {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*1.50
        damage *= 1.40
        damage *= ($gameVariables.value(8)*0.02)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        // console.log(a._name+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
    else {
        damage  = (((a.mat+Math.pow((a.mat/10), 2)))*(100/(100.00+b.mdf))+((a.mat-b.mdf)/2))*2.25
        damage *= 1.40
        damage *= (b.level*0.05)+1.00
        if (a.isStateAffected(40)) { damage *= 1.25 }
        if (a.isStateAffected(47)) { damage *= 0.75 }
        if (b.isStateAffected(46)) { damage *= 0.75 }
        if (b.isStateAffected(54)) { damage *= 1.25 }
        if (damage <= 0) { damage = 1 }
        damage = parseInt(damage*a.mdr)
        // console.log(a.originalName()+": Flame ("+(parseInt(damage*0.8))+"-"+(parseInt(damage*1.2)+")"))
        return damage
    }
}

(the 2 commented out lines for sending data to the console lets me see the damage values with variance for balancing stats)
Do I just have to slot this somewhere in the notebox?
As I had already stated above, you would make the whole formula as a .js file and put it in as a plugin... it can have every formula in your entire game so you don't need a huge list of extra files.

Then, in the database you would simply put the command to call it.
for the 2 examples I provided it would be:
a.attack(a, b)
a.flame(a, b)

Whatever you define it as in the 1st line of each section, the word after 'Game_Battler.prototype.' is what you would use in the damage formula box.

As for your other question I never answered regarding action sequences, I don't really use those any more, but back when I did use them these custom formulas worked with them just the same as any other would have.
As I had already stated above, you would make the whole formula as a .js file and put it in as a plugin... it can have every formula in your entire game so you don't need a huge list of extra files.

Then, in the database you would simply put the command to call it.
for the 2 examples I provided it would be:
a.attack(a, b)
a.flame(a, b)

Whatever you define it as in the 1st line of each section, the word after 'Game_Battler.prototype.' is what you would use in the damage formula box.

As for your other question I never answered regarding action sequences, I don't really use those any more, but back when I did use them these custom formulas worked with them just the same as any other would have.
The main thing I am trying to achieve is that, during the same skill sequence, there would be one damage formula when the party is getting targetted, and one where, on a successful counter, the enemy using the exact skill gets targetted by the party.

Would I have to change the "isActor" to "isEnemy"? What if the enemy targets multiple pary members and they each get to counter? Any other things I need to include?
JavaScript:
Game_Battler.prototype.attack = function(a, b) {
    if (a.isEnemy()) {
        damage = (a.atk * 3 - b.def * 2) / v[11]
        return damage
    }
    else {
        damage = (b.atk * 4 - a.def * 2) * (1 + v[12])
        return damage
    }
}

Here's what I have so far, and it's just returning 0 damage on either end.
When writing it out as javascript you can't use the shortcuts used in the database...
Your v[id] needs to be written as $gameVariables.value(id), otherwise from that it should work for you 😀


and the way the formula works whomever is the check (a.isActor or a.isEnemy) just uses the top block of code, the other would use the bottom if you are allowing both actors and enemies access to the same skill.

As for how to make it work as a counter, I would assume you just call the same formula again when you want the counter to trigger and it (should) work as expected from the victim hitting back to the attacker. if you use math.randomInt(100) to make a chance roll, you can fine tune the odds of a counter attack.
Okay, I found out what I needed to do for this.

I just had to put the damage formula as an if-else condition, and have a variable that would change upon the successful counter, for instance:

v[x] ? b.atk * 4 - a.def * 2 : (a.atk * 4 - b.def * 2) / v[y]

Original thread: https://forums.rpgmakerweb.com/threads/attacks-with-multiple-damage-formulas.179752/