RMMZ Damage Formula - current mp

I notice that when using a damage formula for "attack" such as:

a.mp / 2 - b.mp / 4

where 'a.mp' is the current mp of the actor, it doesn't actually take the current mp before the attack, but the current mp after reducing the mp pool by the mp cost of the attack.

So for example, if the actor's current mp is 80/80, and the attack costs 40 mp, the formula used would actually be:

a.40 /2 - b.mp / 4

I've searched around but haven't encountered an alternative, and I think my only recourse is to just give the actor more MP, so that attack damage doesn't dwindle so fast?
How about

(a.mp + 40) / 2 - b.mp / 4

given, that 40 is the cost of the skill. Maybe there's even a placeholder for something like "this mp costs", but I don't use the battle system, so I don't know.

But with this workaround the spell would calculate the dmg as of the MP value before reducing the MP.
How about

(a.mp + 40) / 2 - b.mp / 4

given, that 40 is the cost of the skill. Maybe there's even a placeholder for something like "this mp costs", but I don't use the battle system, so I don't know.

But with this workaround the spell would calculate the dmg as of the MP value before reducing the MP.
Thanks for this. It's a solution that didn't occur to me. I think this is a good workaround.
Maybe there's even a placeholder for something like "this mp costs"


I believe this might be what you are referring to:
JavaScript:
(a.mp + this.item().mpCost) / 2 - b.mp / 4

Removed object() since this.item() is a function that returns that value - easier to write and remember.
I believe this might be what you are referring to:
JavaScript:
(a.mp + this._item.object().mpCost) / 2 - b.mp / 4
You're close, but I'm not sure where you got object() from.

It would be this.item().mpCost
You're close, but I'm not sure where you got object() from.

It would be this.item().mpCost
Line 1359 from rmmz objects, right? (I'm using github (v1.8.0) to reference this since I don't have MZ)

JavaScript:
Game_Item.prototype.object = function() {
    if (this.isSkill()) {
        return $dataSkills[this._itemId];
    } else if (this.isItem()) {
        return $dataItems[this._itemId];
    } else if (this.isWeapon()) {
        return $dataWeapons[this._itemId];
    } else if (this.isArmor()) {
        return $dataArmors[this._itemId];
    } else {
        return null;
    }
};

Edit: Found Line 1491 - what you wrote returns what I wrote, haha. I'll edit my post to reflect that:
JavaScript:
Game_Action.prototype.item = function() {
    return this._item.object();
};

Edited the above to use item() instead of ._item.object() since item() returns ._item.object().
@bass2yang That works!

As a general rule of thumb, if you find yourself using one of the properties prefixed with an underscore (e.g. _item) take a quick look. Those are usually intended to be private properties that should have a getter function.

There are, of course, cases where you do need to actually go there, just my general recommendation. 🙂
A little bit of nitpicking, but the MP of the player before using the spell is not always

Code:
a.mp + this.item().mpCost

I would also multiply the second value by "a.mcr" (MP cost rate).


Code:
a.mp + this.item().mpCost * a.mcr
A little bit of nitpicking, but the MP of the player before using the spell is not always

Code:
a.mp + this.item().mpCost

I would also multiply the second value by "a.mcr" (MP cost rate).


Code:
a.mp + this.item().mpCost * a.mcr
Thanks! That's true - in which case, we could simplify with this function from the corescripts, I believe:
JavaScript:
Game_BattlerBase.prototype.skillMpCost = function(skill) {
    return Math.floor(skill.mpCost * this.mcr);
};
JavaScript:
(a.mp + a.skillMpCost(this.item())) / 2 - b.mp / 4
Note that the damage formula has item defined as a local variable (rmmz_objects.js):
JavaScript:
Game_Action.prototype.evalDamageFormula = function(target) {
    try {
        const item = this.item();
So you could further shorten it to: (a.mp + a.skillMpCost(item)) / 2 - b.mp / 4.

Original thread: https://forums.rpgmakerweb.com/threads/rmmz-damage-formula-current-mp.171647/