MV Zhonya's Hourglass Remade for MV

For yet the third time, I have come back to this section of the forum. While my conundrum seems difficult, I have actually made enough of a headway to know what I am working with, and notetags to make the effect function. At least in its most basic form.

First and foremost, this is what I am attempting to recreate, having noticed Yanfly has quite the array of Tips&Tricks to re-create other Items from the same Game:

1699453428885.png


This is the Active Ability of Zhonya's Hourglass, referenced from the game itself. For those less familiar with this specific effect, I will provide a slightly more descriptive description: Activating Stasis will prevent you from being affected by anything and everything for 2.5 Seconds at the cost of all control over your Champion for the duration, who will be incapable of doing anything themselves.

Re-creating this effect as a Consumable Item is out of the question as it would simply remove any semblance of balance within the game, ergo, I considered the option of transforming it into a Passive Effect that would trigger the "Stasis" effect in response to a fatal Blow. I achieved success, but only in part: The Stasis effect is indeed applied, and Battlers affected by Stasis cannot be targeted by anything, neither Ally nor Enemy. However, Skills and Spells that target entire troops still find a way to pierce through Stasis: Unless my Eyes have been playing tricks on me, my White Mage was able to heal the Black Mage who was forced into Stasis with a Party-Wide Healing Spell, nor was the incoming damage negated prior to the activation of the Stasis effect.

It would be for the best if I let the Notetags and Lunatic Code speak for themselves. The only one thing I have not done was convert the condition to calculate if the incoming damage would indeed be a killing blow-That is, because I am uncertain as to how to format the condition itself, so it currently applies the Stasis effect in response to an Attack if the Battler's Health has already been reduced to or below 25%.

Passive State Tied to the "Equipment" Itself:
JavaScript:
<Custom React Effect>
if(target.hpRate() <= 0.25 && !$gameSwitches.value(91))
  value = 0
  target.addState(84)
  $gameSwitches.setValue(91, true)
</Custom React Effect>
<Custom Victory Effect>
$gameSwitches.setValue(91, false)
target.removeState(84)
</Custom Victory Effect>
<Custom Escape Effect>
$gameSwitches.setValue(91, false)
target.removeState(84)
</Custom Escape Effect>
<Custom Defeat Effect>
$gameSwitches.setValue(91, false)
target.removeState(84)
</Custom Defeat Effect>

I am certain I absolutely butchered quite a few things within these codes, but to explain my original thought process: I had intended for the effect to only activate once per battle, hence my attempt to control it through Switch 91. There is no one single Notetag that incorporates every "Battle End" Scenario, so I had assumed it would be okay if I added the same condition and effect to each possible outcome. It was recommended by the Help File within the Buffs&States Core Plugin itself to remove the "Remove at the end of Battle" check in the database itself, for the use I had intended of it, and so I did. However, the Damage was not negated, despite the Stasis State being applied correctly, and the State itself will not be applied more than once per Battle as I had hoped. (Unless I am overlooking something here.)

1699454689742.png


The Stasis State itself. There is no more than what I have shown through this screenshot-and I am already prey to paranoia from seeing the size of the screenshot itself as I am writing this Opening Post. It is however a detail I feel I should add, in the event I am missing a Notetag or two to make this state work as intended.

And that is all. The Equipment itself is linked to the "Hourglass" State as its Passive State, which uses the above Code as its Notetags, and while I would like to just ask for guidance on the simple "How to correct this Problem", I would like to possibly set a Turn-Based Cooldown, rather than allowing just one use Per Battle. That eludes my problem-solving skills at present, which is the second reason I have returned a third time. Any input is very highly appreciated. Many thanks in advance.

~Noel Ardiens
Passive State Tied to the "Equipment" Itself:
JavaScript:
<Custom React Effect>
if(target.hpRate() <= 0.25 && !$gameSwitches.value(91))
  value = 0
  target.addState(84)
  $gameSwitches.setValue(91, true)
</Custom React Effect>
Just indenting lines doesn't mean anything in JavaScript. If you want more than one statement to be included in a conditional, you need to create a code block with braces.

It's also good practice to put semicolons at the end of each statement.

JavaScript:
<Custom React Effect>
if (target.hpRate() <= 0.25 && !$gameSwitches.value(91))
{
  value = 0;
  target.addState(84);
  $gameSwitches.setValue(91, true);
}
</Custom React Effect>

<Custom Victory Effect>
<Custom Escape Effect>
<Custom Defeat Effect>
Instead of all of these, why not just put it inside a Custom Battle Effect that will reset it at the beginning of each battle?

And you should only need to turn the switch off, the actual state you can set to expire at the end of battle in your database settings.
You're missing { and } in the if branch in your custom react effect.

JavaScript:
<Custom React Effect>
if(target.hpRate() <= 0.25 && !$gameSwitches.value(91))
{
  value = 0;
  target.addState(84);
  $gameSwitches.setValue(91, true);
}
</Custom React Effect>

As for the stasis state, perhaps you could set the recovery effect, physical damage rate, and magical damage rate to 0%?
As for the stasis state, perhaps you could set the recovery effect, physical damage rate, and magical damage rate to 0%?
And if that doesn't work, just give it its own Custom React Effect that sets value to 0.
Just indenting lines doesn't mean anything in JavaScript. If you want more than one statement to be included in a conditional, you need to create a code block with braces.

It's also good practice to put semicolons at the end of each statement.

Very duly noted. My brain has yet to learn this lesson despite the simpler effects I've worked with using both Semicolons and Braces. I do not know why I keep forgetting Semicolons, but this ought to be a stark reminder to myself to use them whenever possible.

Instead of all of these, why not just put it inside a Custom Battle Effect that will reset it at the beginning of each battle?

And you should only need to turn the switch off, the actual state you can set to expire at the end of battle in your database settings.

... I seriously have no idea why my brain refused to process the much simpler option. Thank you so much for simplifying it to this level. It is absolutely bewildering.

As for the stasis state, perhaps you could set the recovery effect, physical damage rate, and magical damage rate to 0%?

I had thought about it, until ATT_Turan offered a slightly simpler and more effective method, considering "Certain Hit" is an option.

And if that doesn't work, just give it its own Custom React Effect that sets value to 0.

It seems to be doing the job just fine as a safety net. Nulls "Certain Hit" types as well.

Many, many thanks to both of you for your assistance. This has solved the problem as it was, and it guarantees a one-time second chance per battle; Would there be a way to set it to have a Turn-based Cooldown, or would it just be simpler to keep it locked down by a switch?
Would there be a way to set it to have a Turn-based Cooldown
You could use another state as a cooldown.

When triggering the effect, also apply another state that lasts for however long you want the cooldown to be. Then in the if branch for the check, add !target.isStateAffected(n) (where n is the state's ID).

So the code would look something like

JavaScript:
<Custom React Effect>
if(target.hpRate() <= 0.25 && !target.isStateAffected(n))
{
  value = 0;
  target.addState(84);
  target.addState(n);
}
</Custom React Effect>
You could use another state as a cooldown.

When triggering the effect, also apply another state that lasts for however long you want the cooldown to be. Then in the if branch for the check, add !target.isStateAffected(n) (where n is the state's ID).

So the code would look something like

JavaScript:
<Custom React Effect>
if(target.hpRate() <= 0.25 && !target.isStateAffected(n))
{
  value = 0;
  target.addState(84);
  target.addState(n);
}
</Custom React Effect>

This is actually brilliant. I had not thought of using another state to function as a cooldown for anything; It opens up a lot more than it should, honestly. A quick test revealed it to work like a charm!

All that is left for me to do is figure out a way to make the "Cooldown" State persist through Knockout, and that should be easy enough on my own.

My thanks to you once again, this simple and clever solution has simply removed the last problem I was having with the Stasis effect. :hhappy:
It's a notetag in Yanfly's State Categories.

Original thread: https://forums.rpgmakerweb.com/threads/zhonyas-hourglass-remade-for-mv.162751/