MZ Stance System Help (Various VIZ Plugins)

All righty, I know almost nothing about how JavaScript works, but I know enough on how to get this mostly working, I just need help on making it ALWAYS work.

For context I'm trying to make a turn based Souls like, and this is going to be a joint stamina/poise system. (I'll do my best to explain how I want it to work, so don't worry if you have no idea what I'm talking about)

So, to quickly go over how the system works (as it does currently):

To start off I use VIZ Expanded TP System to create a custom TP Style, have the max TP value be 50 + agi (temporary values). I then set the TP the battler starts with the max. (Using the same formula) I then have the Actor take TP damage whenever their hit. (I'm also planning for attacking to cost TP, and for the Guard command to regen 50% of their Max TP)

Now, how I want it to work is that when a character hits 0 TP, I want them to then be stunned (State 13 currently), and then get back up with half of their max TP. How I have is set up currently is that in the troop battle events, at the end of the turn I check all the actors TP values by setting a variable to the current TP ($gameActors.actor(1).tp) and then run the following script if they have 0 TP:

JavaScript:
var target = $gameParty.members()[0];

target.addState(13);

It mostly works the way I want it to, but there's a couple of problems. Number 1, the state gets applied at the turns end, meaning this whole system would break if an actor had TP Regen, as regen is applied before turn end. Also I'm not sure how to set the TP after the stun runs out.

I think I know a fix, by using VIZ Battle Core I can run a similar script in the JS: Pre Regenerate section, and I could use <JS On State Expire> to set the TP. I just don't know enough JavaScript to create the scripts.

Anyone know how to do this? I'm willing to clarify any questions you might have.

Thank you in advance for the help.
I presume all your "VIZ" stuff means VisuStella? There's no "Z" in there 😛

Now, how I want it to work is that when a character hits 0 TP, I want them to then be stunned (State 13 currently), and then get back up with half of their max TP. How I have is set up currently is that in the troop battle events, at the end of the turn I check all the actors TP values
You can just put a Battle Core notetag directly onto each actor.
Code:
<JS Pre-End Turn>
if (user.tp==0)
    user.addState(13);
</JS Pre-End Turn>

You could put it in the pre-regenerate section, too, I don't think there would be a functional difference.
I presume all your "VIZ" stuff means VisuStella? There's no "Z" in there 😛


You can just put a Battle Core notetag directly onto each actor.
Code:
<JS Pre-End Turn>
if (user.tp==0)
    user.addState(13);
</JS Pre-End Turn>

You could put it in the pre-regenerate section, too, I don't think there would be a functional difference.
Thank you! I did mean Visustella, not sure were the z came from...

Original thread: https://forums.rpgmakerweb.com/threads/stance-system-help-various-viz-plugins.163052/