Scripting Question

Hi guys, I want to make state be able to stack, so I write this code in rpg_objects.js:

Code:
Game_Battler.prototype.addState = function(stateId) {
    if (this.isStateAddable(stateId)) {
        if (!this.isStateAffected(stateId)) {
            this.addNewState(stateId);
            this.refresh();
        }
        this.resetStateCounts(stateId);
        this._result.pushAddedState(stateId);
    }
};

But when turn refresh, all same state's turn refresh.
Can someone teach me?
Moved to: Learning JavaScript
Wait wait wait... you need to clarify 2 things for me to understand exactly what you want:

1) What do you mean by stack? Stacking in a sense of having multiple different states at once, or stacking in a sense where the duration (and/or effect???) of a state can be increased if you re-add the state to an enemy?

2) What exactly is not working in the code? From what I understand, when the enemy's turn arrives, similar states are being cleared?

I always use my own custom battle systems so I'm not very familiar with the default battle system and how states work in it, but I can look into it for you.
Wait wait wait... you need to clarify 2 things for me to understand exactly what you want: ......

Looks like I didn't express clearly......sorry.
Basically I want to make state be add on a target again and again.

Example:

but I don't know how to make their remaining turns different.
Ohh, you need to modify the core of how states work in battles. Basically, each state should be independent from others, no matter the stateId. There might be a plugin out there that already does that. I'm thinking maybe Yanfly. I'll try to look (programming it sounds like a pain in the ass to me lol);
Okay, I found a plugin from Yanfly:

http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/

It allows stacking, but doesn't not treat the reaffected state seperately. So the duration will stack and be extended, but the state effect will remain the same from what I understand (only watched the video quickly).

Is that suitable for you? Or you want the effect to be reapplied?

So let's take an example with a state that gives +50% atk for 5 turns. If there are 2 turns left and you reapply the buff:

1) Yanfly plugin will do this: 7 turns left and +50% atk.

2) By treating every affected state differently: 2 turns left with +100% atk, and then 3 turns with +50% atk.

I suppose you want option 2?

Ya, 2 is the thing I want to make.
But state's effect won't stack, only state stack.
Well that's kinda tricky... because the default state system sees each state as a propriety, and that's not what you want if you want to go with option 2. Let me try to explain. Currently the system works like this:

Battler:
- State A: on or off
- State B: on or off
- State C: on or off
etc.

That means that you can't have 2 times state A. The Yanfly plugin follow this rules, it only extends the duration. What you want is a system in which each added state is treated as a separate object from the rest in a State Container. So it would be like this instead:

Battler._statesCoutainer = [ state1, state2, state3, etc. ]

Obviously you start with an empty container. State1 and state2 could be the same state from the database, it would matter not because they are treated differently. Adding a state would just push that state into the container. Now each added states would have their own proprieties (turn, states modifier, effects like poison, etc.).

TLDR: To do what you want, you need to rebuild the core of how the states work in the battle system. It's not a simple task that I can just do by writting 20 lines now. I hope you can code, or find a plugin that does that.
Well that's kinda tricky... because the default state system sees each state as a propriety, and that's not what you want if you want to go with option 2. Let me try to explain. Currently the system works like this:

......
OK, looks like I raise a hot potato, thanks for your information!

Original thread: https://forums.rpgmakerweb.com/threads/scripting-question.92189/