MV Trying to make a Static Skill that checks at end of turn if player is dead to Auto-revive them.

Hello everyone,

I'm trying to make a skill that has some programming attached to it where it checks for the battler being dead and that a certain state isn't applied to that battler to then remove the death state, heal 50 percent of their health and then apply that certain state so the next time it does the check and they're dead, it doesn't proc off again. I'm trying to make this an automatic thing where just having the skill causes the check to go off at every turn, no need for the skill to be activated.

My knowledge on Javascript is kinda limited, I was using the yanfly scripts and tried using buffs and states core to accomplish this task before, but I foolishly put the <Custom Turn End Effect> tag on the skill itself and not the state, which would be perfect but that only works for states and not skills according to the plugin's notetag documentation.

If there's a plugin that can do what Buffs and States does for any gameobject, where having the object present can cause the script to be ran at specific intervals, that's all I'd need to know to complete this functionality. If anyone knows of a plugin that can accomplish this, or if it can be done just within engine, I would appreciate it if I can be informed on it.

Thank you!
if you have everything else already working, then you'd use yanfly's autopassive states plugin to attach that state to the actor as a passive either directly with a notetag on the actor or through a notetag on a learned skill.

then you'd flip a switch (or write a battler property) with the battle start notetag from buffs & states, make the revival only happen if the switch is on, and then make the revival proc also turn the switch off to make it only happen once a fight

Note: if you still want the extra state to show the revival already happened and also use it to deny the revival instead of the switch, you need a plugin like yanfly's state categories so that you can set it as a state that isnt to be removed by death
Okay, maybe I'm not getting something here. I decided to make two states, State 12 for off (default) and state 11 for on, and I attached state 12 to the equipment for it to apply since the skill is actually on the equipment and it doesn't activate the passive since it's not inherently learned.


Passive Active State 12:
<Custom Respond Effect>
if(user.hp <= 0 || user.isDead()){
user.removeState(1);
user.setHP(user.mhp/2);
user.addState(11);
user.removeState(12);
}
</Custom Respond Effect>

State 11:
<Custom Leave Effect>
user.addState(12);
</Custom Leave Effect>

I went with two states because I don't want the default active state to be visible to the player, only when it procs with State 11, and then state 12 goes back into effect when state 11 is removed. I also changed it to Custom Respond Effect for State 12, since it seemed like Current Turn End Effect didn't happen globally like I would like, and realistically it sounds like Custom Respond Effect, which happens after damage calculation, seemed like the best but I'm still getting usurped by the engine's default game over state before this can apply. Any way to fix that?
Hmmm, don't capitalize the 'P' in 'HP'. I think you should also use 'target' instead of 'user' since you're the target of the action. And I don't think you can remove a passive state with 'removeState', make it switch dependent or something.
You guys are beautiful live savers. Did what rpgLord69 suggested, I was able to fit it all into one state while using Custom Passive Condition to turn it on and off, and now it works like intended! I did have to use Math.floor to do proper rounding down to half instead of having floating variables. This is what the final code looks like.

Passive Active State 12:
<Custom Passive Condition>
if(target.isStateAffected(11)){
condition = false;
} else {
condition = true;
}
</Custom Passive Condition>

<Custom Respond Effect>
if(target.hp <= 0 || target.isDead()){
target.removeState(1);
target.setHp(Math.floor(target.mhp/2));
target.addState(11);
}
</Custom Respond Effect>

Thanks guys!
A few notes for you:
When you write code, you should put it in CODE tags (the </> on the edit bar) so that it preserves indentation and brackets.

It's not wrong, but for the sake of efficient code, conditionals automatically apply to the next single code statement. You only need to create a code block if you have multiple statements. e.g. instead of
Code:
if (target.isStateAffected(11)){
condition = false;
}
just
Code:
if (target.isStateAffected(11))
    condition = false;

However, as a similar space-and-logic saver, if you ever find the only thing you're doing as the result of a conditional statement is simply setting a boolean value, you can skip the if entirely and just set the boolean to that condition. That is:
Code:
condition = !target.isStateAffected(11);

Again, not breaking anything, but it's considered correct style to have a space between if and its parenthetical condition, so as to be visually distinct from a function call.

Finally, in your Respond Effect, I can't think of any reason to check both the HP and isDead() - it's possible for HP to hit 0 before the battler refreshes and applies the death state, but I don't see how it would be possible for them to have the death state with HP > 0. That's automatically done inside of addState().

So you only need to check for target.hp <= 0
A few notes for you:
When you write code, you should put it in CODE tags (the </> on the edit bar) so that it preserves indentation and brackets.

It's not wrong, but for the sake of efficient code, conditionals automatically apply to the next single code statement. You only need to create a code block if you have multiple statements. e.g. instead of
Code:
if (target.isStateAffected(11)){
condition = false;
}
just
Code:
if (target.isStateAffected(11))
    condition = false;

However, as a similar space-and-logic saver, if you ever find the only thing you're doing as the result of a conditional statement is simply setting a boolean value, you can skip the if entirely and just set the boolean to that condition. That is:
Code:
condition = !target.isStateAffected(11);

Again, not breaking anything, but it's considered correct style to have a space between if and its parenthetical condition, so as to be visually distinct from a function call.

Finally, in your Respond Effect, I can't think of any reason to check both the HP and isDead() - it's possible for HP to hit 0 before the battler refreshes and applies the death state, but I don't see how it would be possible for them to have the death state with HP > 0. That's automatically done inside of addState().

So you only need to check for target.hp <= 0
Ah, I see. Sorry, I took like one programming class in college for my degree, so I'm not the best at it, but what you're saying does make sense. Updated the code to reflect the feedback!

Code:
<Custom Passive Condition>
condition = !target.isStateAffected(11);
</Custom Passive Condition>

<Custom Respond Effect>
if (target.hp <= 0){
target.removeState(1);
target.setHp(Math.floor(target.mhp/2));
target.addState(11);
}
</Custom Respond Effect>
There's no reason to apologize, I'm just dropping hopefully helpful advice.

Good luck with your project.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-make-a-static-skill-that-checks-at-end-of-turn-if-player-is-dead-to-auto-revive-them.174141/