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.
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);
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.