MZ A little help with a self-made plugin for damage over time effects

Hi everybody,

I hope this is the right place to speak about my problem. I want custom damage over time for 3 states, I tried using the <JS type Slip Damage> notetags from VisuStella plugin but for unknown reasons it doesn't work for me. Looking for solutions I found out that another user had the same problem and he solved with a little plugin of his own creation.

I did the same (my hardcode plugin is attached) and everything works smoothly when the state 4 (Poison) is inflicted in battle, but when I force Poison on the team via map events (traps) then things behave strangely - the DoT damage and effect just happen later during the battle (I think maybe after a whole turn), and not at the first regeneration phase. I didn't check the other 2 states (15 and 16).
I am not an expert in JS and I build things from scratch, so I'm aware someone will have nightmares looking at my code XD... Can someone help me understand why when I force the state from map events it doesn't behave as I think it should from the beginning of the battle?

Additional info: all 3 states don't clear at battle end (database setup) and don't end if not removed by items/recovery.

Original thread: https://forums.rpgmakerweb.com/threads/a-little-help-with-a-self-made-plugin-for-damage-over-time-effects.144601/