MV Help making a Baton Pass skill in MV.

I've been trying to replicate the Persona 5 Royal Baton Pass System where you are able to give an extra turn to another character. While I've been successful, it is incredibly time consuming. I made an entire common event that goes over everything, when I thought of a possible way to do it making the time incredibly short.

I thought using Yanfly's Skill Core, I could make a custom effect using if statements to apply/remove states when needed, and had an original script that went like:

<Custom Execution>
if (target.isStateAffected(10)) {
user.addState(4) }
else {target.addState(4)}
</Custom Execution>

Basically, it would check whether or not the target could receive the baton pass, and if not, it would return the turn to the user.
This did not work.

If someone could help me figure out what I did wrong would be greatly appreciated.
Your code is valid JavaScript...how is receiving a state supposed to give someone an extra turn?
Your code is valid JavaScript...how is receiving a state supposed to give someone an extra turn?
The state has an aura effect which puts everyone except the person with the state Stasis which essentially gives them a free turn, probably should have stated that in the original post.
Just to clarify: These are the same states that do what you want in your common event approach? And by
This did not work.
Do you mean just nothing happens? Or does something unintended happen? (And if so, what?)

That said, my suspicion is that contrary to what @ATT_Turan said, your code is in fact not valid. You seem to have missed the semicolons (😉 after your statements. Try instead:
JavaScript:
<Custom Execution>
  if (target.isStateAffected(10)) {
      user.addState(4);
  }
  else {
      target.addState(4);
  }
</Custom Execution>

Two general tips:
- If asking for help please describe what actually happens and not only that something "doesn't work". This is information that is immensely helpful for people trying to help you.
- Yanfly's plugins are mostly set up i a way that if they encounter syntax errors in lunatic mode notetags, they will not execute the code (obviously) but will log the occurrence in the console.

You could try your not-working code again and see if such a log entry is visible if you open the console (F8).
Do you mean just nothing happens? Or does something unintended happen? (And if so, what?)
Literally nothing happens. It just goes to the next enemy's turn as if literally nothing happened.
You could try your not-working code again and see if such a log entry is visible if you open the console (F8).
I put the Javascript you provided in the move and still nothing happened, but I checked the console and it came up with the photo provided. I'm assuming something went wrong because there's no cost to use the skill, or at least that's what it sounds like.
<Custom Execution> happens right after you selected and confirmed the usage of the skill.

At that point, the target is not defined, e.g. the plugin does not yet know who the target is.

Try replacing <Custom Execution> with one of the following:

If the skill also deals damage
<Pre-Damage Eval>
<Post-Damage Eval>

If the skill does not deal damage
<Before Eval>
<After Eval>

Example:
JavaScript:
<After Eval>
if (target.isStateAffected(10)) {user.addState(4);} else {target.addState(4);}
</After Eval>
No, your assumption is incorrect. paySkillEvalCost is just the function that runs the code provided in the <Custom Execution> notetag. This does happen at the stage where the skills costs are paid (hence the name), but it works perfectly fine if the defined skill cost is 0 MP and 0 TP. Which I assume you mean by:
there's no cost to use the skill
The actual error is that in your code you try to access target, which apparently is not defined at this stage yet.

However any of the following should have target defined:
<Before Eval>, <Pre-Damage Eval>, <Post-Damage Eval>, <After Eval>

Edit: Ninja'd
If the skill does not deal damage
<Before Eval>
<After Eval>
This worked! It also makes a lot of sense, seems I didn't quite understand the actual use of <Custom Execution>.
That said, my suspicion is that contrary to what ATT_Turan said, your code is in fact not valid. You seem to have missed the semicolons after your statements.
Semicolons are optional in JavaScript. I always recommend them, of course, but the OP's code wasn't wrong for that reason.

Original thread: https://forums.rpgmakerweb.com/threads/help-making-a-baton-pass-skill-in-mv.143866/