Conditional Branch JS Help: 1st Party Member & StateAffected

Hello,
I am unfamiliar with JS and I need some help with a conditional branch.

I assigned a variable to the character in the first party slot. This changes, depending on who is put there, and identifies the Character ID.
Now, I would like to have a script that calculates the HP or even just the state of the 1st party member.

So, basically this:
If Character ID = Variable 21, && their HP is 0;
then etc.
You can get a reference to the party leader using one of these:
  • $gameParty.leader()
  • $gameParty.members()[0] (position 0 is the leader, 1 for the next actor, etc).
By default these are equivalent, some plugins might change that.

You can then use that to check various things, e.g.
  • $gameParty.members()[0].hp === 0 - true iff the leader's HP is 0.
  • $gameParty.leader().isStateAffected(123) - true if the leader is affected by state ID 123.
These can be used in Conditional Branch -> Script.
You can get a reference to the party leader using one of these:
  • $gameParty.leader()
  • $gameParty.members()[0] (position 0 is the leader, 1 for the next actor, etc).
By default these are equivalent, some plugins might change that.

You can then use that to check various things, e.g.
  • $gameParty.members()[0].hp === 0 - true iff the leader's HP is 0.
  • $gameParty.leader().isStateAffected(123) - true if the leader is affected by state ID 123.
These can be used in Conditional Branch -> Script.
Thank you. This is very helpful, though I tried it and I am still running into an issue. Just so I don't waste any time, I am going to ask two questions.

1.
I am trying to make it so that when this character falls, another character sacrifices half of their life force in order to bring them back to life, after character 1 falls in battle. Is there any way that I could make this happen reliably? The following is what I have at the moment, though my indicator (squeaky) doesn't seem to be going off.
1739992406714.png


2.I also wanted to know if it was possible to have a retrograde system, where the longer that character x stays in the fight, the weaker they become. is this possible? I was thinking of applying 3 states. Retrograde 1, 2, & 3, but I am not sure how to make it apply after every attack / "round."

Again, thank you so much for your help.
If it is of any importance, I am using YANFLY plugins.
  1. By itself, that event command list looks OK.

    You say the SE doesn't seem to play, but what about the other effects? Is Sami's HP being reduced? Is the leader being revived? You could test by putting the Play SE command (or a Show Text command) outside the branch, to see if the event is actually triggering at all.

    If state 1 (the death state) has the "Remove at Battle End" option checked, then everyone will revive after battle ends. Your event uses a self-switch, so I guess it's a map event, intended to be run once the party has returned to the map after battle.

    Otherwise...you've cropped a lot of information out of that screenshot, e.g. the event trigger. You also haven't mentioned other relevant information, such as:
    • Should this happen during battle (troop event), or after battle has ended (map event)?
    • Is this for an evented battle (Battle Processing) or all battles, including random encounters?

  2. You could use 3 troop events, e.g. the first one with Condition: Turn 1, Span: Battle, Commands:
    • Is Actor 5 in the party?
    • If so, add {Retrograde 1} state to Actor X.
    ...but then you would need to copy those troop events into every (applicable) troop.

    It may be neater to use a tag from YEP Buffs & States Core, perhaps like this (untested):

    <Custom Turn End Effect> var actor = $gameActors.actor(5); // actor ID 5 if ($gameParty.members().contains(actor)) { switch ($gameTroop.turnCount()) { case 1: // at the end of turn 1, add state ID 16 actor.addState(16); break; case 2: // at the end of turn 2, add state ID 17 actor.addState(17); break; case 3: // etc actor.addState(18); break; } } </Custom Turn End Effect>
    Then I think you can give them the tagged state using YEP Auto Passive States~
1.
I made the mistake of running a sound effect with the parallel event. My ears can confirm that the event does take place.
1739997400914.png


This is what the common event looks like at the moment. I do want it to trigger during the battle, though, almost as if it is a passive skill or something.
To answer your questions:

I would like this revive to take effect during the battle. The character is sort of like a necromancer who takes damage from healing, has lifesteal, and can revive the protagonist once per battle, though it takes half their health. I hope that makes sense.
The event trigger I have had on parallel. I am not sure if this is the right decision though.
Lastly, this is something I want to trigger in every battle and not just once.

I'm gonna try that second part, and I'll let you know what happens.
This is yet another planned character gimmick. I am not yet too familiar with troops yet, but I will see what happens.

2. Here is what it looks like so far:
I tried that Buffs & States Core, but I am not too familiar with how to implement it. It appears in the plugin description, it seems to want me to place this in the states description. So, I put it in my States as the following:

<Custom Turn End Effect>
var actor = $gameActors.actor(9);
if ($gameParty.members().contains(actor)) {
switch ($gameTroop.turnCount()) {
case 1:
actor.addState(40); break;
case 2:
actor.addState(41); break;
case 3:
actor.addState(42); break;
}
}
</Custom Turn End Effect>

1740000138293.png


Below that are states that don't share the same note. With this in mind, knowing it won't likely automatically trigger, I then added this common event.

1740000195326.png


This did not work, but it may be because I don't understand how to put it into Troops.

This is how it appeared:

1740000437131.png
  1. OK, by default Parallel/Autorun events don't run in battle. That means you would need a troop event (or some plugin-based solution).

    Troop events offer a condition for {Actor HP < X%}, i.e. the event will run when that specific actor's HP falls below the threshold. And you can set a troop event's Span = Battle to ensure it only runs once per battle. But in your case you don't know who is the leader. That makes things more difficult...I think you'd want a plugin for this part as well.

    Perhaps a passive state (YEP_AutoPassiveStates) on Sami, with a Buffs & States Core notetag on it to check, at certain times, whether the party leader is at 0 HP and if so, revive them. There would also need to be something to make sure it only happens once per battle. So you could make a new state, and try putting this in its Note box (untested):

    <Custom Battle Effect> user._canRevive = true; // reset on battle start </Custom Battle Effect> <Custom Action End Effect> var leader = $gameParty.leader(); if (user._canRevive && leader.isDead()) { var heal = Math.floor(user.hp / 2); leader.startAnimation(49); // play anim (optional) leader.gainHp(heal); // transfer HP user.gainHp(-heal); // from state bearer leader.startDamagePopup(); // display heal user.startDamagePopup(); // display damage leader.clearResult(); // clear results user.clearResult(); user._canRevive = false; // once per battle } </Custom Action End Effect>
    (I partially based this on Yanfly's code for an Auto-Life state.) Then you could add it to Sami as a passive state, by putting a tag in that actor's Note box:

    <Passive State: 123>
    Replace 123 with the ID of the state you just created~ 👋

  2. You would want to make a new state, to be applied as a passive via the YEP_AutoPassiveStates plugin. The notetag should go on that state. Then I think you would just need to add a notetag to the actor to give them that passive state, as described above. 😮‍💨

    Alternatively, set the troop event Conditions to Turn 1 for the first event, Turn 2 for the second one, Turn 3 for the third one. Make sure they all have Span = Battle so they only run once per battle.
1. I tested, following these directions.
State 43, CanRevive contains the notetag.
Sami has the <Passive State: 43> Notetag.
It did not seem to work.

1740052303811.png
1740052339500.png


2. On the bright side....
Retrograde system works!
In the event someone wants to replicate this...
Retrograde0 is applied as an autopassive state on Actor notetags section <Passive State: 39>

Then, inside of that specific State's notetag, I put the script you wrote:
<Custom Turn End Effect>
var actor = $gameActors.actor(9);
if ($gameParty.members().contains(actor)) {
switch ($gameTroop.turnCount()) {
case 1:
actor.addState(40); break;
case 2:
actor.addState(41); break;
case 3:
actor.addState(42); break;
}
}
</Custom Turn End Effect>

Then, I designed states 40,41,42 to further diminish the stat of the character.(This would also be a great system for buffing, for the longer the battle goes on)
In order to make it so that these states don't continue after battle, simply check "Remove at battle end" for all three of these.
Note: Additionally, if you want the Retrograde1 (40) state to go away after 41 comes in, simply put a State Resist [40] in the foreceeding state effect.

After 3 rounds, the debuff is capped, and Retrograde is in full effect.



I love this. I think my next step is to find a way to indicate that this is a debuff. I have a character where the more debuffs others/(and themselves) have on them, the more powerful they become.
Thank you for your help!
Well, at least one of them works! 😂

For the auto-revive, here's a completely different (and probably better) idea. You can try putting this Buffs & States Core notetag on state ID 1, i.e. the death state:

<Custom Apply Effect> var sami = $gameActors.actor(9); var isLeader = user.isActor() && user.index() === 0; var hasSami = $gameParty.members().contains(sami); var canRevive = sami.isAlive() && sami._lastRevive !== $gameSystem.battleCount(); if (isLeader && hasSami && canRevive) { var heal = Math.floor(sami.hp / 2); user.removeState(1); // just in case user.gainHp(heal); sami.gainHp(-heal); user.startDamagePopup(); sami.startDamagePopup(); user.clearResult(); sami.clearResult(); sami._lastRevive = $gameSystem.battleCount(); user.startAnimation(49); // play anim (optional) } </Custom Apply Effect>
I think this one notetag should work. It means that whenever someone dies, this code should run: if the victim is the party leader, and Sami is present, is alive, and hasn't used the revive ability yet in this battle, then the effect happens.
[*]OK, by default Parallel/Autorun events don't run in battle. That means you would need a troop event (or some plugin-based solution).

If you do want to go with the plugin-based solution as an alternative, you can use a plugin that will let parallel common events still run during battle, such as this one: https://forums.rpgmakerweb.com/inde...common-events-in-battle.68251/#comment-648991 (I've been using it in combination with Yanfly's plugins and haven't had any issues).
If you do want to go with the plugin-based solution as an alternative, you can use a plugin that will let parallel common events still run during battle, such as this one: https://forums.rpgmakerweb.com/inde...common-events-in-battle.68251/#comment-648991 (I've been using it in combination with Yanfly's plugins and haven't had any issues).
I appreciate you sharing this resource. Thank you.
I do wish there was a notetag that could be made in order to make the autorun occur for combat, just because I am worried of the chance of something breaking during combat.


Well, at least one of them works! 😂

For the auto-revive, here's a completely different (and probably better) idea. You can try putting this Buffs & States Core notetag on state ID 1, i.e. the death state:

<Custom Apply Effect>
var sami = $gameActors.actor(9);
var isLeader = user.isActor() && user.index() === 0;
var hasSami = $gameParty.members().contains(sami);
var canRevive = sami.isAlive() && sami._lastRevive !== $gameSystem.battleCount();
if (isLeader && hasSami && canRevive) {
var heal = Math.floor(sami.hp / 2);
user.removeState(1); // just in case
user.gainHp(heal);
sami.gainHp(-heal);
user.startDamagePopup();
sami.startDamagePopup();
user.clearResult();
sami.clearResult();
sami._lastRevive = $gameSystem.battleCount();
user.startAnimation(49); // play anim (optional)
}
</Custom Apply Effect>

I think this one notetag should work. It means that whenever someone dies, this code should run: if the victim is the party leader, and Sami is present, is alive, and hasn't used the revive ability yet in this battle, then the effect happens.

I tried this just now. There was an error at first, but I realized that this was because the actor is "5" and not "9."
Though it would be nice to have a damage number display for Sami's health lost, this is very good.

Thank you, again, for the help.

I am now almost completely done with Sami's kit, though I do need to figure out a way to make all healing damage him aside from his lifesteal.
I was considering making it so that when he defeats a unit, he can gain back the revival ability, but then I realized, it's not going to happen, like, ever.
Oh. I don't know why it wouldn't display a damage popup, sorry. The sami.startDamagePopup() line is supposed to do that. 😴

For turning heals into damage, here's the tag for the "Undead" state from Yanfly's Tips & Tricks series:

<Custom React Effect> // Check if the action is a recovery skill. if (this.isHpRecover()) { // If it is, let's convert the value into damage! value = Math.abs(value); } </Custom React Effect>
Like the example shows, you can put that on a state and assign it as a passive to Sami (and any other actors/enemies who need this mechanic).
Oh. I don't know why it wouldn't display a damage popup, sorry. The sami.startDamagePopup() line is supposed to do that. 😴

For turning heals into damage, here's the tag for the "Undead" state from Yanfly's Tips & Tricks series:

<Custom React Effect>
// Check if the action is a recovery skill.
if (this.isHpRecover()) {
// If it is, let's convert the value into damage!
value = Math.abs(value);
}
</Custom React Effect>

Like the example shows, you can put that on a state and assign it as a passive to Sami (and any other actors/enemies who need this mechanic).

<Custom Turn End Effect>

if ($gameParty.members().contains(actor)) {

switch ($gameTroop.turnCount()) {

case 1:

actor.addState(23); break;

}

}

</Custom Turn End Effect>

Just to make sure that this runs efficiently, would this following script.
The way this works, is after turn one, they experience withdrawal. I can't tell if this will still function, because I took the first line out: var actor = $gameActors.actor(9);

Update: It does not work. I am now trying to make it so that this state will constantly alternate between buffed and unbuffed, or between one state and another state.





2.
I am also trying to figure out how I can make it so that a specific character changes their evasion rate based on their luck. For example
Actor 8 has an ability where for every 10 luck they have, it adds +1 to their evasion chance.

I looked up the issue, but only got redirected to Advanced Switches and Variables by Yanfly.

Original thread: https://forums.rpgmakerweb.com/threads/conditional-branch-js-help-1st-party-member-stateaffected.175630/