How can I have skills lower target's TP?

Hi! I'm making a game that utilizes TP as a Temperature bar, and I was wondering if there's a way I can have certain attacks damage an Actor's TP rather than HP or MP.

damage formula
b.gainTp(-X)
X being the amount you want to reduce targets TP.

this can even be a % of the current amount, ie:
b.gainTp(Math.floor(-b.tp*0.25)) this would reduce their current tp by 25%
(math.floor is to round down the number i always just hate seeing decimal numbers in HP/MP/TP)

damage formula
b.gainTp(-X)
X being the amount you want to reduce targets TP.

this can even be a % of the current amount, ie:
b.gainTp(Math.floor(-b.tp*0.25)) this would reduce their current tp by 25%
(math.floor is to round down the number i always just hate seeing decimal numbers in HP/MP/TP)
I actually tried this out, and it worked, but it didn't update on the actual TP bar in the game. The only way I could actually see the adjusted TP was by checking in the console. Is there a way I could fix this?
You would need to refresh Window_BattleStatus to get it to update (as tested in a new/blank game).

JavaScript:
SceneManager._scene._statusWindow.refresh()

Not ideal. But neither is the way that Window_BattleStatus was implemented, which is why it was rewritten in MZ.

If this is a core mechanic of your game, it might be worthwhile to just code a refresh call as a hook into the gainTp() function.

Not sure if there's a much better way to do it. I haven't futzed with TP much in MV. For that reason, I'm also not sure if the YEP plugins address it.
You would need to refresh Window_BattleStatus to get it to update (as tested in a new/blank game).

JavaScript:
SceneManager._scene._statusWindow.refresh()

Not ideal. But neither is the way that Window_BattleStatus was implemented, which is why it was rewritten in MZ.

If this is a core mechanic of your game, it might be worthwhile to just code a refresh call as a hook into the gainTp() function.

Not sure if there's a much better way to do it. I haven't futzed with TP much in MV. For that reason, I'm also not sure if the YEP plugins address it.
I tried out that code, but it didn't actually update the bar in-game.
Give this a try as a new plugin(name it whatever you want, doesn't matter as long as it ends with .js) :

JavaScript:
Game_Actor.prototype.gainTp = function(value) {
    Game_Battler.prototype.gainTp.call(this, value);
    if (SceneManager._scene.hasOwnProperty("_statusWindow")) {
        SceneManager._scene._statusWindow.refresh();
    }
}

Fair warning, wrote this in about a minute using Kenan's comment, and HAVE NOT tested this in anyway.
Give this a try as a new plugin(name it whatever you want, doesn't matter as long as it ends with .js) :

JavaScript:
Game_Actor.prototype.gainTp = function(value) {
    Game_Battler.prototype.gainTp.call(this, value);
    if (SceneManager._scene.hasOwnProperty("_statusWindow")) {
        SceneManager._scene._statusWindow.refresh();
    }
}

Fair warning, wrote this in about a minute using Kenan's comment, and HAVE NOT tested this in anyway.
How would I use it in-game? Just using the "target.gainTP" function?
Give this a try as a new plugin(name it whatever you want, doesn't matter as long as it ends with .js) :

JavaScript:
Game_Actor.prototype.gainTp = function(value) {
    Game_Battler.prototype.gainTp.call(this, value);
    if (SceneManager._scene.hasOwnProperty("_statusWindow")) {
        SceneManager._scene._statusWindow.refresh();
    }
}

Fair warning, wrote this in about a minute using Kenan's comment, and HAVE NOT tested this in anyway.
Still doesn't appear to have worked, though I'm still just using the same "gainTP" function in the notetags as before.
Oh, wait, I think I was actually wrong in the first place! It doesn't actually seem to be changing the character's TP at all, I just wasn't checking correctly in the console! Are we sure that "gainTP()" actually works with negative numbers?
it should to my knowledge, but I might be wrong - let someone who knows the code give an answer.

however there is another possible cause for the problem:
do your actors have the trait "preserve TP" in their traits (either by actor or by class)?
only with that trait the engine stores the TP between battles, otherwise the TP is randomized at battlestart.

If that trait is not present, it might disable other TP functions as well.
Still doesn't appear to have worked, though I'm still just using the same "gainTP" function in the notetags as before.
um... "notetags"? this is supposed to be damage formula. looking over the discussion im not seeing anywhere that it was suggested this become a notetag
If they're using Yanfly's SkillCore it could amount to the same thing.

As far as I know, gainTp SHOULD work with negative numbers, all TP changes go through that function.
it should to my knowledge, but I might be wrong - let someone who knows the code give an answer.

however there is another possible cause for the problem:
do your actors have the trait "preserve TP" in their traits (either by actor or by class)?
only with that trait the engine stores the TP between battles, otherwise the TP is randomized at battlestart.

If that trait is not present, it might disable other TP functions as well.
I actually have been using preserve TP, because I wanted TP to be able to stay the same between battles! I'll try it without.
I actually have been using preserve TP, because I wanted TP to be able to stay the same between battles! I'll try it without.
I just realized I completely misunderstood their post. Whoops. And actually I was wrong, I only had Preserve TP on before I started to try to do all of this, I'll try it with.
it should to my knowledge, but I might be wrong - let someone who knows the code give an answer.

however there is another possible cause for the problem:
do your actors have the trait "preserve TP" in their traits (either by actor or by class)?
only with that trait the engine stores the TP between battles, otherwise the TP is randomized at battlestart.

If that trait is not present, it might disable other TP functions as well.
Enabling "Preserve TP" still didn't actually change anything.
can u share a screenshot of the skill. im still getting hung up on you mentioning "notetag" when nobody else has referenced any notetag usage
can u share a screenshot of the skill. im still getting hung up on you mentioning "notetag" when nobody else has referenced any notetag usage
In the comment, I say "for 10 temp" because, in my game, I'm wanting to use TP as a Temperature bar that enemies can lower for certain effects that I've already set up.
1625454644712.png
I tried out that code, but it didn't actually update the bar in-game.

I'm not sure what your definition of "tried out that code" is, but if you used the plugin that Drakkonis was kind enough to provide for you, the TP bar will absolutely update in battle after a gainTp() call:

mS51saf8ae.gif


If it doesn't work for you, then you have some kind of plugin conflict, or you are not correctly using whatever notetag it is that you're trying to use. For reference, here's a screenshot of the skill I used in the above gif:

RPGMV_rxYUmjZYMa.png
i just tryed making a new project only plugin is skill core, and testing an almost exact copy of your skill (i just changed target to ally so could have party use it on themself)
the notetag your using does nothing.
then tryed a damage formula version like @Kenen just shared while i was doing my testing and it works perfectly.

edit: not even using the code @Drakkonis provided.
literally no plugins required for the working damage formula version.
i just tryed making a new project only plugin is skill core, and testing an almost exact copy of your skill (i just changed target to ally so could have party use it on themself)
the notetag your using does nothing.
then tryed a damage formula version like @Kenen just shared while i was doing my testing and it works perfectly.

edit: not even using the code @Drakkonis provided.
literally no plugins required for the working damage formula version.
Yeah, Yanfly's Skill Core doesn't have Custom Execution as a notetag option, no idea where that's coming from. I just assumed it was present because I know that Skill Core DOES have notetag options for custom code execution. It's the only one I'm personally aware of, for MV anyway. And even if it WAS Skill Core, I remember reading in the documentation that comments in the code would comment out all following code.

I thought it was odd that a TP change wouldn't trigger a refresh, but I haven't really worked with MV beyond testing MZ plugins for RETRO, so I didn't give it much thought when I saw Kenan's post and decided to write the code. No skin off my back though, like I said, wrote it in a minute. *shrug*

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-have-skills-lower-targets-tp.138004/