MV Counter Attack State using Original Casters Stats for Damage

Hello RPGMAKERS.
I Have been trying to wrap my head around this and I think I need some help.
Using yanfly's counter control & buffs/state core to make a state/counter attack that when applied to the other party members it will counter attack using the original casters stats.

example: the skill would be "caltrops" and when the caster uses the skill it will apply the caltrops state to the entire party.
when the party members are attacked they have a chance to "counter attack" with the new caltrops counter attack skill.
this new skill should use the original casters stats in the damage formula, but I'm not sure how to go about this!

Maybe there's also a better way of doing this? but I don't know!
YEP Buffs & States Core has an undocumented feature: battler.stateOrigin(stateId). It gets the origin of a given state on the given battler, i.e. the one who added the state to that battler. (Also, the "Custom Action Effect" tags have a shortcut for the current state's origin: origin.)

So here are a couple of ideas (untested):
  1. Reference the Caltrops origin in your counter skill's damage formula, e.g.

    a.stateOrigin(123).atk
    Replace 123 with the ID of your Caltrops state.

  2. Or put a Buffs & States notetag on the Caltrops state so the retaliation is "automatic", e.g.

    <Custom Respond Effect> // calculate damage var dmg = origin.atk; dmg *= user.elementRate(1); // apply damage to attacker user.gainHp(-Math.round(dmg)); // collapse if dead if (user.isDead()) { user.performCollapse(); } </Custom Respond Effect>
These examples assume the damage should be equal to the origin's ATK value, and of element ID 1. Edit that however you like!
@caethyril These are some interesting ideas, but I believe you are overthinking it.

If @NineTales is using Yanfly's counter attack plugin to replace the victim's counter attack, that means you just need a regular damage formula like this:

b.atk - b.def

Since a.[stat] calls the stats of the attacker, and b.[stat] calls the stats of the attacked.
@caethyril These are some interesting ideas, but I believe you are overthinking it.

If @NineTales is using Yanfly's counter attack plugin to replace the victim's counter attack, that means you just need a regular damage formula like this:

b.atk - b.def

Since a.[stat] calls the stats of the attacker, and b.[stat] calls the stats of the attacked.
I don't think this will work, because the damage formula you suggest will use the current battlers stats and not the origin stats (the original caster of the skill)

I will try what @caethyril suggests, it seems like it's right for what I am going for!
Oh, I read this too fast. I need to stop doing that. :hswt: I thought you were trying to use the enemy's stats against them. Whoops.
YEP Buffs & States Core has an undocumented feature: battler.stateOrigin(stateId). It gets the origin of a given state on the given battler, i.e. the one who added the state to that battler. (Also, the "Custom Action Effect" tags have a shortcut for the current state's origin: origin.)

So here are a couple of ideas (untested):
  1. Reference the Caltrops origin in your counter skill's damage formula, e.g.

    a.stateOrigin(123).atk

    Replace 123 with the ID of your Caltrops state.

  2. Or put a Buffs & States notetag on the Caltrops state so the retaliation is "automatic", e.g.

    <Custom Respond Effect> // calculate damage var dmg = origin.atk; dmg *= user.elementRate(1); // apply damage to attacker user.gainHp(-Math.round(dmg)); // collapse if dead if (user.isDead()) { user.performCollapse(); } </Custom Respond Effect>

These examples assume the damage should be equal to the origin's ATK value, and of element ID 1. Edit that however you like!
I find it very strange that yanfly didn't document this feature, as it's pretty cool and would have saved me a post. Makes me wonder what else is not documented hehe

I just used a.stateOrigin(stateID).stat in my current damage formula, and ya, it just works as expected lol
Thank you!
Yea, I knew about it from some of Yanfly's Tips & Tricks articles, but was surprised to find no mention of it in the plugin's help section. Good to hear you got it working! 👋
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/counter-attack-state-using-original-casters-stats-for-damage.154455/