Making enemies only killable when hit with certain elements/resisting death unless hit with certain moves???

SO I've got a really nice combo system pretty well implemented in my RPG, and as the project moves further along Ive added more powerful attacks that are meant as stuns and/or finishers and really have a lot of weight to them. So what I'd really like is a way to make a Passive State to replicate the effect from Kingdom Hearts 2 onwards bosses have that makes them unable to be killed EXCEPT with Finishers, preferably by tying in skills to a "Finisher" element. How would I go about setting this up???

Basically, what I was hoping to do was create a Finisher element that I can plug into certain moves, so I can make sure certain bosses are weaker or more resistant to the damage of those specific moves themselves and incentivize racking up higher combos first, but having them still only be outright killed when hit with the Finisher element itself and hanging on with 1 HP otherwise. I'm using the default MV battle system with a majority of Yanfly's plugins currently plugged-in, along with the Active Chain Skills by VisuStella powering the combo system itself. If theres a solution NOT involving Element damage (maybe something Switch or Variable related or another way to build a State to respond right?) thats great, but again, I definitely would love to have this effect tied to taking damage from a specific Element for the purposes of tying well into the rest of the balancing of the game in general. But at this point, as long as I get the mechanic working right, I don't mind if its not tied to Element damage, I just thought that might be the easiest way to go, all things considered.

If anyone could help me out with this I'd really appreciate it!!! For the most part my project is really coming along at a steady pace, but theres always a few things that slow me down as I'm learning Javascript along the way, and there always seems to be something I just BARELY miss a lot of the time LOL.

P.S. before anyone links the page, I'm quite aware there is a Yanfly code called "Greater Undead" , that supposedly works this way using the Buffs & States Core and Auto Passive Effects plugins, but it's never worked right for me on it's own as-is OR after trying to tweak it further for my own project. That's part of WHY I'm making this post, to try and remedy that. Maybe I'm doing something wrong, but also it's not the first time something from Yanfly's "MV Tips & Tricks" page has had to be more heavily modified to work as intended with my projects. Admittedly I pretty much just went the lazy route this time (literally just took out the part of the code that made them take damage on healing effects like an Undead and replaced instances of the word "undead" with "finisher" tbh) but anyways heres what I had so far. If anyone can give it a once over I'd love the assist!!!
Code:
<Custom Passive Condition>
// Check if the finisher death flag has not been triggered
condition = !user._finisherDeath;
</Custom Passive Condition>

<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 boss
  var killingElements = [19, 20];
  // 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 finisher death flag to true
    target._finisherDeath = true;
    // Refresh the target
    target.refresh();
  } else {
    // Otherwise, set the target's HP to 1
    target.setHp(1);
  }
}
</Custom Respond Effect>
Do you have Yanfly's element core installed? Because otherwise this.getItemElements(); will be undefined and you should see a corresponding error in the console if you open it with F8.
Just to note it in case you want to match KH exactly, magic will also deplete a boss' last HP like a Finisher would.
Do you have Yanfly's element core installed? Because otherwise this.getItemElements(); will be undefined and you should see a corresponding error in the console if you open it with F8.
Yes, I make use of it a lot and have very few issues with it for the most part, but I will definitely be checking console stuff more often and seeing if there's something with it I'm missing when i check it later. It could actually just be something as simple as the passive state not properly reading the element I set up tbh
Just to note it in case you want to match KH exactly, magic will also deplete a boss' last HP like a Finisher would.
Very true!! Thank you for highlighting this bc it slipped my mind to include in the initial posting!! KHIIs combat has a lot of really great nuances like that. Can't even begin to describe how many times Magnet + Thunder helped me clutch encounters haha.
Anyways well before this idea came up, Id already grouped most of the offensive skills of both physical AND magical types between Light and Heavy skill types with some shared traits for each type, so the idea of retooling the Heavy-class skills to be the ones that can just actually deal killing blows to bosses just felt like a natural extension and logical next step of that design anyways tbh.

Also, thank you guys so much for the quick replies!!! I'm not on here much but this community is pretty dope 🙂
Very true!! Thank you for highlighting this bc it slipped my mind to include in the initial posting!! KHIIs combat has a lot of really great nuances like that. Can't even begin to describe how many times Magnet + Thunder helped me clutch encounters haha.
Final Form + Firaga = Totally OP. I love KH2's combat, and while I had fun playing through KH3, it can't compare on a mechanical level.

Original thread: https://forums.rpgmakerweb.com/threads/making-enemies-only-killable-when-hit-with-certain-elements-resisting-death-unless-hit-with-certain-moves.150856/