How to Address an Actor's HP for Conditional Branch

Hi, trying to make a revival item through a common event.
1733903474558.png
The goal is to address the Knockout State of the character instead of having the event check for whichever specific actor it is.

If I have to check the Knockout State for every character, it'd require a lot of copypasting and frankly seems kind of messy. If that's the only way to do it, then so be it, but I feel like there's a much, much simpler way to do this, and I think that's having something along the lines of:

If (target) is affected by Knockout:
remove state of knockout
change HP to 1


How can I do something like this? Thank you.
Screenshot 2024-12-11 162230.png
Hi, trying to make a revival item through a common event.
Why? There are Effects to do this built in, like the revival item that comes in the default database when you make a new project.

If it's about that Dark and Stormy switch, it's much simpler to disable the player's ability to use the item when that switch is on than to go through all this.
Why? There are Effects to do this built in, like the revival item that comes in the default database when you make a new project.

If it's about that Dark and Stormy switch, it's much simpler to disable the player's ability to use the item when that switch is on than to go through all this.
There were so many solutions in the last thread that I feel like I kind of got lost on which one you're referring to unfortunately. This method would be using plugins right?
There were so many solutions in the last thread that I feel like I kind of got lost on which one you're referring to unfortunately. This method would be using plugins right?
Have you tried using the script above?


Code:
const stateId = 10; //Change to your knockout status ID
$gameParty.members().forEach(member => {
    if (member.isStateAffected(stateId)) {
        member.removeState(stateId);
        member.setHp(1);
    }
});
Have you tried using the script above?


Code:
const stateId = 10; //Change to your knockout status ID
$gameParty.members().forEach(member => {
    if (member.isStateAffected(stateId)) {
        member.removeState(stateId);
        member.setHp(1);
    }
});
If I could upload a video I would, but while it did "revive" and give 1 HP back, it:

-revived anyone else who died as well
-did not revert MOG's battlehud portrait back to its alive state


Thank you for your time.
If you are just looking for the first member in your party order affected by the state, use find():
JavaScript:
const member = $gameParty.members().find(m => m.isStateAffected(1));
if (member) {
    member.removeState(1);
    // member.setHp(1);
};
.removeState() already has a revive function in it to restore the hp to 1 if your state id matches the deathstate id (usually 1 for knockout), but it doesn't hurt to set the hp to 1, either.

I suppose in case you have something that knocks out the actor without taking their HP to 0 or below, throwing that setHp function can compensate for that.

MOG's battle hud might require a refresh of some sort, I think (can't remember at the moment).
If you are just looking for the first member in your party order affected by the state, use find():
JavaScript:
const member = $gameParty.members().find(m => m.isStateAffected(1));
if (member) {
    member.removeState(1);
    // member.setHp(1);
};
.removeState() already has a revive function in it to restore the hp to 1 if your state id matches the deathstate id (usually 1 for knockout), but it doesn't hurt to set the hp to 1, either.

I suppose in case you have something that knocks out the actor without taking their HP to 0 or below, throwing that setHp function can compensate for that.

MOG's battle hud might require a refresh of some sort, I think (can't remember at the moment).
Thanks for replying, I'm really just trying to address the One specific actor being targeted at that moment.
Thanks for replying, I'm really just trying to address the One specific actor being targeted at that moment.
Ah, my apologies. I did read what you wrote but came back to my reply later and forgot that you needed the target from the common event rather than just whoever was in the party.

Use this in your comon event:
JavaScript:
const id = $gameParty._targetActorId;
if (id) $gameActors.actor(id).removeState(1);
There are already conditional checks and hp sets in .removeState() so this should work (please test - it's late here and I feel like I missed something haha)
Hi, thanks again for the correction. Unfortunately, the effect animation will show, but the HP will stay at 0, and the character is still shown as dead...

Ah, my apologies. I did read what you wrote but came back to my reply later and forgot that you needed the target from the common event rather than just whoever was in the party.

Use this in your comon event:
JavaScript:
const id = $gameParty._targetActorId;
if (id) $gameActors.actor(id).removeState(1);
There are already conditional checks and hp sets in .removeState() so this should work (please test - it's late here and I feel like I missed something haha)

Original thread: https://forums.rpgmakerweb.com/threads/how-to-address-an-actors-hp-for-conditional-branch.173828/