MZ Help with changing TP function [solved]

So I've been trying to change the function of TP in my game for a while, without downloading plugins (mostly because the plugins often change other aspects of the game in ways i don't want them to). My goal currently is to make it to where TP isn't gained at the start of battle. I made this part work fairly easily by copying and pasting into the plugins folder the rmmz_objects plugin within the game files and changing the this.SetTp(Math.randomInt to 0.
I also only want to gain TP when taking damage which i also managed since it's already in the code, all i had to do was remove TP cost and gain when using skills and items.
However i want to also add a state when TP reaches 100. Specifically, i want the character to gain a Fear state where they can no longer attack and/or take more damage when attacked.
is there any way to add a simple script plugin, or change something in my copied plugin that would apply the state, or am i missing an easier way to do this in the database? Any advice would help

P.s. sorry if this is the wrong forum or worded poorly. I've never posted a thread before.
Darkest Dungeon inspired?
AFAIK you can't set this up in the database, because while you can use a script in a common event to check for the TP and then add a state, I cannot find any way to attach this to a character without a plugin. Not without a workaround I can't see.
Since you already edited the tp functions, doesn't it work if you just do something like this:

Game_BattlerBase.prototype.setTp = function(tp) {
this._tp = tp;
if (this.isActor() && this._tp === 100){this.addState(*state id*)}
this.refresh();
};
Since you already edited the tp functions, doesn't it work if you just do something like this:

Game_BattlerBase.prototype.setTp = function(tp) {
this._tp = tp;
if (this.isActor() && this._tp === 100){this.addState(*state id*)}
this.refresh();
};
Would i just add this to the same script somewhere? It looks promising! I'll definitely give it a try either way.
OK, let's start from the top.

Most of what you did in the copy of the objects core file could have been done without any script manipulation at all.

1) having all actors have the trait "Preserve TP" disables the random TP at start of battle and has the actor keep the TP from the end of the last battle.
If you want to start at zero, you just need to remove all TP from all actors after battle, and that is fairly easy.

2) The trait "TP Charge Rate" (one of the parameters) determines how much TP is gained based on damage.
There is no need to delete TP cost and TP gain from the code, because these are database values that can simply be set as zero in all skills - just a bit of typing if you want to use default skills without that.

3) You can have a troop event running at the end of each turn and check each actor TP in that troop event. If the TP value is 100, apply a state by event command that does what you do.

This requires a bit of script (which is available one of the pinned topics here in the forum), and you might want to consider adding a base troop plugin to have that event automatically run in all troops without having to copy it manually into all troops.
Since you already edited the tp functions, doesn't it work if you just do something like this:

Game_BattlerBase.prototype.setTp = function(tp) {
this._tp = tp;
if (this.isActor() && this._tp === 100){this.addState(*state id*)}
this.refresh();
};
I tried this and now the game won't even open XD. I did change (*state id*) to the number associated with the state i want it to apply.
Did you remove the ** ?
Did you remove the ** ?
I did, but it was my mistake, somehow i added a whole other line of code that was messing with. I got it functioning mostly, it applies "a" state, but for some reason it won't apply the state i set it to. I made "fear" under states in 0011 and put that as the state id, but it keeps applying the state in 0009's space. I don't really understand why, but still like 80% of the way there lol
I made "fear" under states in 0011 and put that as the state id, but it keeps applying the state in 0009's space. I don't really understand why, but still like 80% of the way there lol
Don't use leading zeros. JS interprets numbers with those as octal values. The editor displays them as an aesthetic, but the engine doesn't ever use them.
Yeah, my understanding is that it's reading your 0011 as octal number -> 9

Write 11 there.
Yeah, my understanding is that it's reading your 0011 as octal number -> 9

Write 11 there.
Thank you! This has been super helpful and i really appreciate it <3

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-changing-tp-function-solved.178962/