MV YEP_AutoPassiveStates / Greater Undead JavaScript Support

I am attempting to design an enemy that has to be frozen and then physically attacked to kill it, similar to Metroids in Metroid for Nintendo. I realize this will take an auto-passive state (124) specific to the enemy and that once placed in FROZEN state (125), any physical attack (elements 1, 10, 11, 16, 17, 18), ideally, will kill it. I also know that my current script does not achieve the desired effect, but I lack the JavaScripting scripting knowledge to reach the final result.

Desired outcome breakdown is below:
1. Enemy is always in auto-passive state 124 (I currently have no script written for this state). It is invincible unless the player uses ICE element 3 on it.

2. Player uses ICE element (3) on the enemy.

3. ICE element causes the enemy to be placed in a FROZEN state 125, reducing the enemy's HP to 0. I used the Yanfly Greater Undead JavaScript (at the bottom of the post).

4. If the player physically attacks (elements 1, 10, 11, 16, 17, 18) the enemy while it is FROZEN, it dies.

4.a. If a player uses element 3 on the enemy while it is in FROZEN state 125, it resets the state 125 timer.

4.b. If the player uses any other element on the enemy other than 1, 3, 10, 11, 16, 17, or 18, the enemy's HP returns to what it was before state 125 was applied, which should be max-HP.

Community assistance is greatly appreciated. Thanks!

FROZEN state 125 JavaScript:
JavaScript:
<Custom Passive Condition>
// Check if the undead death flag has not been triggered
condition = !user._undeadDeath;
</Custom Passive Condition>

<Custom React Effect>
// Check if this action recovers HP
if (this.isHpRecover()) {
  // Make it deal damage instead
  value = Math.abs(value);
}
</Custom React Effect>

<Custom Respond Effect>
// Check if the target's HP is 0 or less
if (target.hp <= 0) {
  // Get this action's elements
  var elements = this.getItemElements();
  // Create a list of the elements that can kill this undead
  var killingElements = [1, 10, 11, 16, 17, 18];
  // Set the initial kill flag to false
  var killed = false;
  // Loop through the killing elements
  while (killingElements.length > 0) {
    // Get the currently looped killing element
    var elementId = killingElements.shift();
    // Check if the action's elements have a killing element
    if (elements.contains(elementId)) {
      // If it does, set the kill flag to true
      killed = true;
    }
  }
  // Check if the kill flag has activated
  if (killed) {
    // Set the undead death flag to true
    target._undeadDeath = true;
    // Refresh the target
    target.refresh();
  } else {
    // Otherwise, set the target's HP to 1
    target.setHp(1);
  }
}
</Custom Respond Effect>
It would be helpful to know what the current behavior you're experiencing is. Have you placed console.log statements in various elements of the control flow to see if the program is executing all the blocks of code when you expect them to? Have you logged the various state changes you are making to see if they are ending up the way you expect them to? Is the engine perhaps overwriting them later?

Also, a minor nitpick, you have a while loop where a for loop would be much more appropriate (and also clearer). Example revision:

JavaScript:
for (const elementId of killingElements) {
    if (elements.contains(elementId) {
        killed = true;
    }
}
Have you looked at Yanfly's Freeze Tip & Trick? It seems to be very close already to what you want to achieve.


You could simply start the enemy with an Immortal state on, then on the attack that triggers the shattering include a line to remove that state. Thus they can't be killed any other way.
The skill is still in development, it would be pointless to play-test it now.
It would be helpful to know what the current behavior you're experiencing is. Have you placed console.log statements in various elements of the control flow to see if the program is executing all the blocks of code when you expect them to? Have you logged the various state changes you are making to see if they are ending up the way you expect them to? Is the engine perhaps overwriting them later?

Also, a minor nitpick, you have a while loop where a for loop would be much more appropriate (and also clearer). Example revision:

JavaScript:
for (const elementId of killingElements) {
    if (elements.contains(elementId) {
        killed = true;
    }
}
Have you looked at Yanfly's Freeze Tip & Trick? It seems to be very close already to what you want to achieve.


You could simply start the enemy with an Immortal state on, then on the attack that triggers the shattering include a line to remove that state. Thus they can't be killed any other way.
Turan, you never let me down. Ah, good idea. I will play around with it and get back to you.
Have you looked at Yanfly's Freeze Tip & Trick? It seems to be very close already to what you want to achieve.


You could simply start the enemy with an Immortal state on, then on the attack that triggers the shattering include a line to remove that state. Thus they can't be killed any other way.
Turan, it worked! Thank you again! SOLVED.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/yep_autopassivestates-greater-undead-javascript-support.152681/