Change TP gain to be equal to a Stat?

I want to alter the amount of TP gained to always be equal to the characters M.Def ("Spirit" in my game).
But no matter what I tweak, the TP seems to still use it's damage based formula. Any idea how to fix this?


Code:
Game_Battler.prototype.initTp = function() {
    this.setTp(Math.randomInt(0)); // Set's Starting TP to 0
};

    mdf: { // Defining mdf (Spirit)
        get: function mdf() {
            return this.param(5);
        }
        configurable: true
    }

Game_Battler.prototype.chargeTpByDamage = function(mdf) {
    const value = Math.floor(mdf * this.tcr); // Replaces damageRate with Spirit
    this.gainSilentTp(value);
};

This is the plugin I've been using up to this point.
You'll want to remove the part where you tried to redefine mdf from the plugin. That's not the right way to define a property, and there's no point in doing so anyway (since it's already defined by the engine). The other two functions should look like this:
JavaScript:
Game_Battler.prototype.initTp = function() {
    this.setTp(0);
};

Game_Battler.prototype.chargeTpByDamage = function(/* damageRate */) {
    const value = Math.floor(this.mdf * this.tcr);
    this.gainSilentTp(value);
};

Note that this will also affect the rate at which enemies gain TP.
You'll want to remove the part where you tried to redefine mdf from the plugin. That's not the right way to define a property, and there's no point in doing so anyway (since it's already defined by the engine). The other two functions should look like this:
JavaScript:
Game_Battler.prototype.initTp = function() {
    this.setTp(0);
};

Game_Battler.prototype.chargeTpByDamage = function(/* damageRate */) {
    const value = Math.floor(this.mdf * this.tcr);
    this.gainSilentTp(value);
};

Note that this will also affect the rate at which enemies gain TP.
Tested this out, it works! 😀
But now realizing it only effects taking damage, not dealing it. 😮
Thanks for the help, I'm gonna try to find that other piece of code now.

Also, this is just me confirming I'm reading the code right as I'm trying to learn it for myself.
My issue (beyond a needless define) was that I was forgetting to use "this." to recall whose m.def I was using? That and the "Math.randomInt" was pointless because the value is 0?
Tested this out, it works! 😀
But now realizing it only effects taking damage, not dealing it. 😮
Thanks for the help, I'm gonna try to find that other piece of code now.

Also, this is just me confirming I'm reading the code right as I'm trying to learn it for myself.
My issue (beyond a needless define) was that I was forgetting to use "this." to recall whose m.def I was using? That and the "Math.randomInt" was pointless because the value is 0?
Right, the Math.randomInt technically wasn't causing any problems, but it served no purpose, so I removed it. In addition to not using this. with mdef, you had also named the function's parameter mdf, which resulted in mdf referring to whatever value gets passed to the function (which in this case, was damage).
Right, the Math.randomInt technically wasn't causing any problems, but it served no purpose, so I removed it. In addition to not using this. with mdef, you had also named the function's parameter mdf, which resulted in mdf referring to whatever value gets passed to the function (which in this case, was damage).
Alright, thanks! That makes sense!

Also, I believe I've located the code that effects tp on damage, but any attempt I make to edit it just caused the TP bar to disappear upon an attack being made. Any idea what the tweak is needed here?


Code:
Game_Action.prototype.applyItemUserEffect = function(/*target*/) {
    const value = Math.floor(this.item().tpGain * this.subject().tcr);
    this.subject().gainSilentTp(value);
};
Alright, thanks! That makes sense!

Also, I believe I've located the code that effects tp on damage, but any attempt I make to edit it just caused the TP bar to disappear upon an attack being made. Any idea what the tweak is needed here?


Code:
Game_Action.prototype.applyItemUserEffect = function(/*target*/) {
    const value = Math.floor(this.item().tpGain * this.subject().tcr);
    this.subject().gainSilentTp(value);
};
There was likely a mistake in your attempt to edit it, but without seeing exactly what you did, I couldn't tell you what was wrong. If I were to take a shot in the dark, I'd guess that you probably tried to use this.mdf, which won't work in this case, since this would refer to the Game_Action object, instead of the battler. In this function, you could refer to the battler using this.subject(). Something like this should work:
JavaScript:
Game_Action.prototype.applyItemUserEffect = function(/*target*/) {
    const value = Math.floor(this.subject().mdf * this.subject().tcr);
    this.subject().gainSilentTp(value);
};

Though that may not wind up working exactly the way you want it to, since it will apply to almost any action the player does (guarding, using items, etc). If that winds up being the case, to offer suggestions, I would need to know more details about exactly how you want it to work.
There was likely a mistake in your attempt to edit it, but without seeing exactly what you did, I couldn't tell you what was wrong. If I were to take a shot in the dark, I'd guess that you probably tried to use this.mdf, which won't work in this case, since this would refer to the Game_Action object, instead of the battler. In this function, you could refer to the battler using this.subject(). Something like this should work:
JavaScript:
Game_Action.prototype.applyItemUserEffect = function(/*target*/) {
    const value = Math.floor(this.subject().mdf * this.subject().tcr);
    this.subject().gainSilentTp(value);
};

Though that may not wind up working exactly the way you want it to, since it will apply to almost any action the player does (guarding, using items, etc). If that winds up being the case, to offer suggestions, I would need to know more details about exactly how you want it to work.
That works! Thanks again! 😀
As for what I'm trying to do? It's still in very early setup/planning days, but it's built off the back of a Plugin series called SPRG, basically converting RPG Maker to a Fire Emblem-like game.

So still experimenting is all the potential options with TP and all. But I suspect the only thing I'd want to make note to exclude atm from TP gain would be Item Use.
That works! Thanks again! 😀
As for what I'm trying to do? It's still in very early setup/planning days, but it's built off the back of a Plugin series called SPRG, basically converting RPG Maker to a Fire Emblem-like game.

So still experimenting is all the potential options with TP and all. But I suspect the only thing I'd want to make note to exclude atm from TP gain would be Item Use.
No problem. If you want to exclude TP gain from all item use, I think this would do it:
JavaScript:
Game_Action.prototype.applyItemUserEffect = function(/*target*/) {
    if (this.isItem()) {
        return;
    }
    const value = Math.floor(this.subject().mdf * this.subject().tcr);
    this.subject().gainSilentTp(value);
};
No problem. If you want to exclude TP gain from all item use, I think this would do it:
JavaScript:
Game_Action.prototype.applyItemUserEffect = function(/*target*/) {
    if (this.isItem()) {
        return;
    }
    const value = Math.floor(this.subject().mdf * this.subject().tcr);
    this.subject().gainSilentTp(value);
};
That did the trick! Thanks bunches!
I've made sure to note you as the Author in the plugins details. 😀

Original thread: https://forums.rpgmakerweb.com/threads/change-tp-gain-to-be-equal-to-a-stat.159400/