MZ Need help with a custom combat plugin

I want to modify the way Tactical Points work ; as of now, I want to make it so that their maximum value is 3, and hitting an enemy with a basic attack gives you 1 TP (and this is the only way to gain TP, for example taking damage from enemies doesn't work anymore)

With the code I have here, everything works perfectly :


Now I want to make it so that TPs are shared between allies : if an ally uses 1 TP to do something, all allies lose 1 TP as well, and if an ally gains 1 TP, the others gain it too, etc.
I've been trying to implement this for over an hour, without success. The code I have (and my other tries) were generated by ChatGPT as I barely have any experience in programming, but I just can't make it work, so I was wondering if anyone could help.

Here is one of my failed codes, just in case it can help :
While I don't have RPG Maker MZ, the plugin YEP_PartyLimitGauge for MV sounds like a better solution to what you want to achieve, since you want a resource to be shared between all battle members. If there is something similar available to MZ users, I would use that.
rpg_objects.js
JavaScript:
Game_BattlerBase.prototype.maxTp = function() {
    return 100;
};

The update function:
JavaScript:
Game_BattlerBase.prototype.refresh = function() {
    this.stateResistSet().forEach(function(stateId) {
        this.eraseState(stateId);
    }, this);
    this._hp = this._hp.clamp(0, this.mhp);
    this._mp = this._mp.clamp(0, this.mmp);
    this._tp = this._tp.clamp(0, this.maxTp());
};

JavaScript:
let qTP_Team; // Should be init to 0 or leave it as You want
Game_BattlerBase.prototype.refresh = function() {
    this.stateResistSet().forEach(function(stateId) {
        this.eraseState(stateId);
    }, this);
    this._hp = this._hp.clamp(0, this.mhp);
    this._mp = this._mp.clamp(0, this.mmp);
    // this._tp = this._tp.clamp(0, this.maxTp());
    this._tp = 0; // Set all actors TP to 0 every "turn"
    // or
    this._tp = qTP_Team; // Set it to Team TP ( so all actors are showing same TP value )
};

You probably could detect damage as:
JavaScript:
Game_Battler.prototype.onDamage = function(value) {
    this.removeStatesByDamage();
    this.chargeTpByDamage(value / this.mhp);
    if( this.isEnemy() ){
        qTP_Team += 1; // Add 1 TP every time enemy is damaged
        if(qTP_Team > 3){ qTP_Team = 3; } // Check if TP is more than 3, if so, reduce to 3
    }
};

Tho I'm not gonna test if for You, it's just a theory code that I made based on looking on the functions in the rpg_objects.js and yes, I'm using RPG Maker MV so in Your MZ it could look a bit different... but I guess very similar...

if You want, feel free to upload Your rpgmz_objects.js here, Ill look into it and give You modified version of it so You can test it...
if You want, feel free to upload Your rpgmz_objects.js here, Ill look into it and give You modified version of it so You can test it...
Redistribution is prohibited as per the EULA.

Article 6 (Prohibitions)​

  1. The User will adhere to the user obligations set forth in This Agreement and the Terms of Use, etc. (henceforth collectively "This Agreement, etc.") and use This Software appropriately and within the law.
  2. The User may not engage in any of the following during the use of This Software.
    1. (1) Allow the use of This Software by a third party, as installed on a User Device, or installation of This Software on three (3) or more User Devices. However, terms of use may be resolved via separate consultation with and consent from the Company pursuant to advance application, in the event that multiple licenses are required by educational institutions, etc.
    2. (2) Removal of security from This Software via utilization of bugs or malfunctions, etc., or via usage of This Software in any manner not permitted by the Company, including production of derivative software via adaptation, translation, or modification, etc. of This Software.
    3. (3) The duplication, publication, projection, lending, sale, distribution, display, publish transmission, or enabling of transmission of This Software in whole or in part without the prior written consent of the Company, or separate Distribution, etc. of either the computer programs (henceforth "Company Programs") comprising This Software, or other Company Assets.
Redistribution is prohibited as per the EULA.

Article 6 (Prohibitions)​

  1. The User will adhere to the user obligations set forth in This Agreement and the Terms of Use, etc. (henceforth collectively "This Agreement, etc.") and use This Software appropriately and within the law.
  2. The User may not engage in any of the following during the use of This Software.
    1. (1) Allow the use of This Software by a third party, as installed on a User Device, or installation of This Software on three (3) or more User Devices. However, terms of use may be resolved via separate consultation with and consent from the Company pursuant to advance application, in the event that multiple licenses are required by educational institutions, etc.
    2. (2) Removal of security from This Software via utilization of bugs or malfunctions, etc., or via usage of This Software in any manner not permitted by the Company, including production of derivative software via adaptation, translation, or modification, etc. of This Software.
    3. (3) The duplication, publication, projection, lending, sale, distribution, display, publish transmission, or enabling of transmission of This Software in whole or in part without the prior written consent of the Company, or separate Distribution, etc. of either the computer programs (henceforth "Company Programs") comprising This Software, or other Company Assets.
me xD
meanning that games made on RPG Maker are possible to make only for personal use? 😛
1737693720166.png

Correct me if I'm wrong... but pretty much every RPG Maker Game shares it's plugins 😛

I own only RPG Maker MV, don't own MZ version...
Yet... some way I got the Plugins... ohh right... I downloaded a game made on the MZ...

Or what, does it makes a difference? So tell him to send me his whole game, I mod it for him and send him back his game xD lol...

But yee, I just checked the scripts of game that I downloaded and it seems that MZ and MV functions are exactly the same 🙂

Well, report and ban me then 😛
The provided code above comes from the RPG Maker MV RPG_Object.js...
or in part

xDDDD
So tell him to send me his whole game, I mod it for him and send him back his game xD lol...

You can't put together coherent code or a coherent post. Why do you think someone would trust you to "mod" their project?
Or what, does it makes a difference? So tell him to send me his whole game, I mod it for him and send him back his game xD lol...
I ran into similar problems when RPG Maker added in JS and I couldn't figure out how to modify script without exporting it and editing in VS Code.
RPG Maker MV API Help File
RPG Maker MZ

It is similar to working with other engines where you have to loop stuff around to get it back into RPG Maker.
Iunno, guys. Oddly. There is an expectation to follow the RPG Maker EULA while using one of the publisher’s websites. Either way, this thread is not on topic, like… at all. That said, this section is not intended to repair inoperable ChatGPT outputs either. Requesting and recommending alternative plugins is fine, of course.
Sorry, I didn't know it was prohibited. As for the YEP plugin, it requires you to pay, and I do not want really to spend money on this project (for now, at least).

So I guess I'm stuck.
Everyone does also realize you could just get the MZ trial and see the code that way, right? That would not break EULA. So for those who want to assist and don't own MZ that should give you a legal way to get it with no issues.
The code I have (and my other tries) were generated by ChatGPT as I barely have any experience in programming, but I just can't make it work, so I was wondering if anyone could help.
Well, yes. AI tends to just create garbage and unless you know JS and logic well enough to tell its nonsense, you wont know know its feeding you garbage, much less know how to "fix" it. If by mentioning your inexperience that youre implying that youre also trying to learn, id suggest not relying on AI at all and do tutorials instead.

i dont know if you want both enemies and actors to have this shared TP system. you never mentioned enemies, but youre overwriting Game_Battler methods and are affecting both actors and enemies. You also only ever (try to) update the party's TPs and not the troop's. if an enemy were to run gainTp, youd still try to increase and update the party's TP. Then logically, making gainTp run gainTp on all actors can only cause an infinite loop.

...also the function that gives battlers tp for acting is gainSilentTp, so none of that would actually be ran in the first place outside of skill/item effect
So I guess I'm stuck.
i mean... had you asked someone, you would have saved yourself an hour fiddling with AI. the change you want to make mechanically is basic. instead of trying to synchronize all the battlers' tp's, make them all reference the same value within the party/troop and change setTp to manipulate the battler's unit's shared tp instead.

Spoiler
Code:
(() => {
    Object.defineProperties(Game_BattlerBase.prototype, {
        tp: { get: function() { return this.friendsUnit()._tp;}, configurable: true }
    });

    Game_BattlerBase.prototype.maxTp = function() {
        return 3;
    };

    Game_Battler.prototype.initTp = function() {
        this.setTp(0);
    };

    Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
        return this.friendsUnit()._tp >= this.skillTpCost(skill) && this._mp >= this.skillMpCost(skill);
    };
    
    Game_BattlerBase.prototype.paySkillCost = function(skill) {
        this._mp -= this.skillMpCost(skill);
        this.friendsUnit()._tp -= this.skillTpCost(skill);
    };

    Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
    };

    Game_BattlerBase.prototype.setTp = function(tp) {
        this.friendsUnit()._tp = tp.clamp(0, this.maxTp());
    };

    var GU_Init = Game_Unit.prototype.initialize;
    Game_Unit.prototype.initialize = function() {
        GU_Init.call(this);
        this._tp = 0;
    };
})();
@TobiChaos Just a reminder to you:

NEVER EVER MODIFY THE CORE FILES, that's a reason we create plugins
to overwrite the core so the core stays in tact, if the maker updates, all
data would be lost!

if your new, learn the engine and create plugins for modifications as it's
far safer than modify the core files.

@Picsney listen to the others, like Robro33 as a plugin is 10x safer and
they know what they do as MV wont work in MZ (most part) without FOSSIL.

but most try to stay away when not needed, as there are MZ plugins that
could help you or a snippet that others can make 🙂
I know about modifying the core files, I always create plugins when it comes to changing the way the game works.
Thanks for the help, I eventually found a solution without having to code something but I tested your plugin, and it runs smoothers than what I did, so I'll try to implement it.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-custom-combat-plugin.174911/