Help with creating a specific state

Hey everyone, I'm looking to create a specific state that I've been having trouble figuring out how to implement.

The state is called Corrupt. Essentially, certain late-game monsters can inflict a state on party members of the player called Corrupt which turns the player's party member into an enemy essentially turning them on auto battle and only attacking allies. That part I've got figured out. Here are the parts I'm stuck on:

I use the Visustella core plugins along with a few others of theirs (including the variable gauges). I've turned MP into the corruption stat because all monsters are inflicted with corruption and the player has to reduce their corruption meter to weaken them (the higher their corruption meter, the more powerful they are). This is displayed as a vertical variable gauge behind the enemy that the player can reduce using specific corruption-reducing skills. Each corruption skill reduces the enemy's MP, then calls a common event to set the EnemyCorruption Variable to equal the enemy's MP. I've hidden the MP bar for all actors and enemies because I want to use the larger vertical bar for the monster's corruption meter.

These late-game monsters can inflict a Corrupt status on player's party members causing them to only attack allies while inflicted with the state and I want to set it to where the only way to turn that party member back into an ally is to either finish the battle or use those corruption/MP reducing skills on their afflicted party member. Where I'm stuck is how to implement this feature. My initial thought was to create a variable gauge for each possible party position with a Party1Corruption, Party2Corruption, etc. variable (5 max party members allowed), have the variable gauge appear above the party member if afflicted by the state. Then just add some conditional within my common event that runs whenever a corruption reducing skill is used and check if the target is a party member, then if so, get the target's position in the party, then reduce their MP accordingly and set their specific corruption variable to equal their MP to adjust their corruption meter accordingly.

**That's what I can't figure out exactly how to do. So how would I run a conditional to check if the target is a party member, then if so, how can I set a variable to equal the target's position in the party. From there I know how to adjust their MP and corruption variable.

**The next thing I'm not sure how to do is how to set it to when the party member's MP or Corruption variable is 0, that the state is cleared.

Any help with either of those two above would be phenomenally appreciated!

Also, if there is a much better way to go about this, let me know as well. I'm pretty layman when it comes to RPG Maker and scripting and no virtually no javascript other than what I've incidentally picked up while working on my project.

I've attached my current common event when the player uses a corruption-reducing skill.
If I may suggest - you're likely to get better help if you focus the request a bit more. You have quite a lot in there about this corruption mechanic and the UI and stuff like that - none of which has anything to do with your actual question.

If you trim all of that out, it's easier for us to read the post and address only what you're asking without getting distracted by other parts of it.

**That's what I can't figure out exactly how to do. So how would I run a conditional to check if the target is a party member
A common event attached to your skill doesn't know this. You would need to use a notetag on the skill from VisuStella Battle Core. For example:

Code:
<JS Pre-Apply>
$gameSwitches.setValue(1138, target.isActor());
</JS Pre-Apply>

That will set switch 1138 to ON if the target is an actor, OFF if it's an enemy.

Then you just use Conditional Branches in your attached common event.

how can I set a variable to equal the target's position in the party.
This is right in Control Variables, Game Data -> Last -> Last Target Actor ID
It's the ID, not their index, but you can do anything you need using that data.

**The next thing I'm not sure how to do is how to set it to when the party member's MP or Corruption variable is 0, that the state is cleared.
Using VisuStella Battle Core, give the state the notetag:

Code:
<JS Post-Apply as Target>
if (target.mp == 0)
    target.removeState(state.id);
</JS Post-Apply as Target>

That will check every time any action targets the battler whether it's reduced their MP to 0.
That's genius, thanks so much! I think that would work, but I have one concern that's only a concern because of a mechanic I'm using (that may clear up once I try it out though)

1) Is there a script to get the last target index? I can foresee my common event getting a little chaotic because I use a monster capture plugin that just starts adding captured monsters starting at Actor ID 300 and on so it may be tough to implement based on Actor ID. I'm sure it could be done, though.
I think it would make more sense for you to show exactly what you're doing to an actor that you think would be harder to do using their ID than the party index.

The answer is that you can get the index from the ID, but you probably don't need to.
Maybe I'm not thinking clearly on this, but in my head, when one of the player's party members is afflicted with the corrupt state, the player would use a corrupt reducing skill on the ally to attempt to reduce their corruption level. Sometimes this would take multiple uses of the skill to get that MP/corruption variable to zero to remove the state. So I would have the skill set to reduce the MP of the target based on a specific parameter of the user. Then, in the common event that's triggered when the skill is used using Visustella's action sequence, identify the target of the skill and set the corruption variable to equal the target's MP. I would need multiple corruption variables (ideally for each party index number) since I may have multiple allies with the corrupt state and would need to track them individually.

How I would know which variable gauge to reduce is where I'm stuck. The only way I could think of is to tie it to party index.
Okay. I'm still a bit confused as to why you need to create a new variable and a new UI element instead of just using the existing gauge for MP, since that's what you're using to track corruption.

(or if you're using SRD's HUDMaker or something to create these new gauges, you should be able to simply tie them to the actor's MP instead of some additional variable and they'd update automatically...it doesn't seem like you should have to be doing this manually)

But, regardless, if you have an actor's ID in a variable as above, you can do Control Varaibles -> Script -> $gameActors.actor($gameVariables.value(69)).index()

where 69 is the ID of the variable you're using.
You know, that's an angle I hadn't considered. Seeing if there's a way in the Visustella Variable plugin to tie the gauge to MP would make it a lot easier. I don't think there is though since I think it can only be set up to be tied to a variable. That's why I had been, in the skill's common event, setting the variable to equal the monster's MP.

The main reason I had hid the MP bar is because the monsters capable of inflicting the corrupt state are very late-game (I'm talking the very last world) so it would be an entire game with a random bar that stays empty throughout 90% of the game. I guess that wouldn't be terrible, but that's why I turned them off and decided on using a variable gauge when it's relevant.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-creating-a-specific-state.168202/