Skill applying buff before damaging?

Quick Question regarding damage formulas:

I have a move that I want to apply a buff that increases the next Magic Attack next turn [state(x)] upon using a skill damaging an enemy.
The issue I'm having is, that the buff is applied whenever this skill is being used. I'm using this formula at the moment:

a.addState(x); a.mat * 7 - b.mdf * 2

At first I tried just reversing the formula to a.mat * 7 - b.mdf * 2; a.addState(x) thinking it was a priority like an event, but that lead to no damage being dealt. (probably because the formula is now incorrect.)

I'm trying to avoid plugins and seeing if this can be achieved through the base game. Thanks in advance!
When a skill/item hits, its formula is evaluated, then the result of that formula is applied as damage/healing. This means the formula cannot be directly used to apply an effect after the formula is applied.

You could try Yanfly's Skill Core plugin; it offers notetags that let you run code at particular stages in a skill's execution, e.g.
Code:
<Post-Damage Eval>
user.addState(123);
</Post-Damage Eval>
If you use the action sequence packs, there's also that approach for applying it not only after the damage is dealt, but exactly when you want it during the course of execution:

<Target Action>
perform action
action animation: target
wait for animation
action effect: target
add state x: target
death break
perform finish
</Target Action>

As a basic example. What really matters is that the "add state x: target" (with x being your intended state id) sequence occurs after "action effect: target" because that's when the formula/etc all get applied as damage to the target(s)
All of the above works, but in your case there is a much easier way to do it; all you need to do is calculate the damage, store it to a variable, apply the buff, then restore the amount of damage, using the following formula:

c = a.mat * 7 - b.mdf * 2; a.addState(x); c

(That will work in VX Ace. I think it will work in MV too, but if not, try making the first part var c = instead of c = )

The reason it didn't work without the c's is that the damage dealt will be whatever the last expression in your formula was. When it was a.addState(x), that's not a number. But when it's the variable c that was calculated earlier, it will deal that much damage.
It's my understanding that the order in which you apply states, calculate damage, etc in the formula box doesn't matter. The debuff is going to be applied first in every case (in MV) since the formula box contents gets eval'ed (at which point the state is applied immediately because of addState() being called) but the damage itself is applied later, since it still has to go through a few other functions to apply elemental resistances, critical modifiers, etc.

You have to apply the damage to the character (not just calculate it) before you attempt to add the state.

That said, in retrospect, I'd probably use @caethyril 's approach over mine, since mine will apply the state even on a miss (I forget not everyone is using a 100% accuracy system like me) whereas the post damage eval tag only gets applied if the attack lands on its target.
All of the above works, but in your case there is a much easier way to do it; all you need to do is calculate the damage, store it to a variable, apply the buff, then restore the amount of damage, using the following formula:

c = a.mat * 7 - b.mdf * 2; a.addState(x); c

(That will work in VX Ace. I think it will work in MV too, but if not, try making the first part var c = instead of c = )

The reason it didn't work without the c's is that the damage dealt will be whatever the last expression in your formula was. When it was a.addState(x), that's not a number. But when it's the variable c that was calculated earlier, it will deal that much damage.
Yeah, so I went ahead and did as you suggested. Strangely it's acting the same way as the default. The self buff bonus damage is applied on the first hit.

I ended up using @caethyril method and just got the plug in, and it works exactly as needed.
And @Aesica is correct, as I read up on it before getting back home.

Thank you, all so very much for the help! Saved me some time from having to go crazy all night. =P

- Surge
@Aesica @TheSurge Thanks for clearing up my misconception! I was nearly sure that mathematical calculations (and conversions between a stat's placeholder and the actual value of the stat) were done in strict order alongside any other commands entered in the formula box, but I guess that's not the case!!

Original thread: https://forums.rpgmakerweb.com/threads/skill-applying-buff-before-damaging.117188/