RMMV Trying to fix "on death" state effect using Yanfly Buffs/States core

woootbm

Super Sand Legend
Veteran
Joined
Apr 26, 2014
Messages
364
Reaction score
331
First Language
English
Primarily Uses
RMMV
Hey all,

In my game I have this state I made that checks what element is dealing the killing blow to the enemy. It looks like this:
JavaScript:
<Custom Deselect Effect>
var lethal = 1;
var nonlethal = 2;
var diplomacy = 3;
var xp = target.def;
var basexpa = $gameVariables.value(1);
var basexpb = $gameVariables.value(2);
var basexpc = $gameVariables.value(3);
if (this.isHpEffect() && target.hp == 0 && this.item().damage.elementId === lethal) {
  target.startAnimation(65);
  $gameVariables.setValue(1, basexpa +xp);
}
if (this.isHpEffect() && target.hp == 0 && this.item().damage.elementId === nonlethal) {
  target.startAnimation(60);
  $gameVariables.setValue(2, basexpb +xp);
}
if (this.isHpEffect() && target.hp == 0 && this.item().damage.elementId === diplomacy) {
  $gameVariables.setValue(3, basexpc +xp);
}
</Custom Deselect Effect>

I apologize for the ugly code. Probably a lot of unnecessary stuff in there. Anyway, this works in most cases. The problem is when I use an attack that has repeats in it. So if I have an attack that hits 10 times, and the target dies after the first hit, this will run every single time.

I've tried using target.isDead() and target.isAlive() but those don't seem to be recognized while an attack is repeating. What I think I need is something that checks if the attack is changing the target's HP (since it's stuck at 0, right?), but I don't know how to check that.

I don't think the other Yanfly notetags will work. They seem to run with the wrong timing, or something like "on removal" doesn't seem to work in the case of death.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,216
Reaction score
4,195
First Language
English
Primarily Uses
RMMV
Make a Custom React Effect, which happens before damage is dealt:
Code:
// Does the target have HP, and will the attack kill it?
if (this.isHpEffect() && target.hp>0 && value>=target.hp)
    target.wasKilled=true;

Then your conditionals inside the Deselect Effect say:
Code:
if (target.wasKilled && this.item().damage.elementId === lethal)
{
    target.startAnimation(65);
    $gameVariables.setValue(1, basexpa +xp);
    target.wasKilled=false;
}
etc.

That way, only the first hit will be true, all the rest will see that wasKilled is false and won't execute the code again.
 

woootbm

Super Sand Legend
Veteran
Joined
Apr 26, 2014
Messages
364
Reaction score
331
First Language
English
Primarily Uses
RMMV
Wow, this is such a smart way to use this plugin! I guess I just didn't think I could use more than one of those at a time? Even though I've probably done that somewhere in this or another project, derp. I also didn't think to declare a variable in one tag and use it in another, even though I've definitely done that :hswt:

Anyway, this is genius. You're a genius @ATT_Turan ! This is also a great bit of code for anyone looking to make some "on death" type effects without having to manually event stuff in the troop window. Just gotta put in another check for an immortal state if your game uses it (mine might not).
 

Latest Threads

Latest Posts

Latest Profile Posts

no longer using rm2k3
Don't you hate when you're trying to sleep and suddenly the smoke detector needs batteries? That's exactly what happened to me. Now I'm sluggish and tired after that darn thing started chirping at 11:30 at night. Man I wish I had one of those smart smoke detectors that sends a message to your phone way before it starts chirping.
Interior of a bus, may do more vehicle interiors :kaoswt2:
1670089782219.png
I can hardly believe it is the third day of Christmas and I have yet to put up decorations! Spending my morning cooking breakfast and getting them up.
https://itch.io/s/83641/1-week-sale Do you want a Roguelike game like a turn-based Hades? Get Zodiac Hunters now while it's on sale!

Forum statistics

Threads
127,016
Messages
1,183,213
Members
166,879
Latest member
Drenquire
Top