MZ [RMMZ] Question about DMG and Death Check/Timing

Hello everyone! I was testing some in-battle stuff (SV), and realized that when hitting an enemy and its HP reaches zero, the enemy dies at the same time as the attack makes its impact and DMG numbers shown. My point being, it all happens a bit too fast and all at once. I would like it delayed a little bit (something about tension is fun, wondering if you finally defeated a boss or not!) Is it reasonably possible to alter? I would personally have it so that after the damage numbers are gone, THEN the game checks if the HP are 0 for anyone and death ensues (if applicable). 1 second delay after the initial impact would seem right. If it isnt possible, its not a big issue.

If plugins are needed, I'd appreciate avoiding anything V.Stella related. Thank you. 🙂
Greetings!

I did a little digging to help out, and found what is likely the code you'd need to modify in order to get what you want.

Both of these functions are located in rmmz_objects.js. As to exactly how to implement a delay in the processing of these functions, that's a little more complicated; maybe someone else can assist.

But basically all you would need to do is to create your own plugin that aliases one of these functions and adds in the delay ->

Game_BattlerBase.prototype.addNewState = function(stateId) {
if (stateId === this.deathStateId()) {
this.die();
}
const restricted = this.isRestricted();
this._states.push(stateId);
this.sortStates();
if (!restricted && this.isRestricted()) {
this.onRestrict();
}
};

OR

Game_Battler.prototype.refresh = function() {
Game_BattlerBase.prototype.refresh.call(this);
if (this.hp === 0) {
this.addState(this.deathStateId());
} else {
this.removeState(this.deathStateId());
}
};

Maybe this will be enough for you to go on, or enough for someone else to come along and finish the work.

Either way, I hope it helps 🙂.

-Niniann
You can increase the collapse effect duration and make the graphical effects start only after the duration is low (you should make changes to boss collapse method too):

Sprite_Enemy.prototype.startCollapse = function() {
this._effectDuration = 90;
this._appeared = false;
};

Sprite_Enemy.prototype.updateCollapse = function() {
if (this._effectDuration < 30) {
this.blendMode = 1;
this.setBlendColor([255, 128, 128, 128]);
this.opacity *= this._effectDuration / (this._effectDuration + 1);
}
};
Addendum:

a somewhat related problem is that the battle-end triggers and closes the screen on the last enemy killed, BEFORE any troop event conditioned on that enemy HP=0 can run.

But there is an evented workaround for that:
If a troop event on turn 0 gives every enemy an immortal state, and the troop events conditioned on HP=0 for every enemy remove that state only after they completed their work - then you could use a troop event for the boss on what happenes to be his "death"-sequence.
Ill make tests on my end based off what you all suggested and well explained, later on (tomorrow night or later). Ahead of time, thank you.
Made tests using @rpgLord69's solution, and it worked in delaying the death animation (easy to understand + edit the .JS too). The thing is, the <collapse> SFX still happens at the same time as the damage being dealt. With this in mind, I thought a solution could be to add dead-air in the <collapse> SFX file itself via Audacity. Maybe not ideal, but its very easy to do and will serve the intent/illusion well enough.

Wolf talked about doing the same for bosses... I understand that it should affect the same file (rmmz_sprites.js). I see the following if searching the term boss in the original .js:
Code:
Sprite_Enemy.prototype.startBossCollapse = function() {
    this._effectDuration = this.bitmap.height;
    this._appeared = false;
};
Would it be enough for me to copy the same name-code provided above using "startBossCollapse" + "updateBossCollapse" names/words as well? Would this be able to cover both cases safely? Example:
Spoiler: Potential Final .JS Plugin
Code:
Sprite_Enemy.prototype.startCollapse = function() {
    this._effectDuration = 90;
    this._appeared = false;
};

Sprite_Enemy.prototype.updateCollapse = function() {
    if (this._effectDuration < 30) {
    this.blendMode = 1;
    this.setBlendColor([255, 128, 128, 128]);
    this.opacity *= this._effectDuration / (this._effectDuration + 1);
    }
};


Sprite_Enemy.prototype.startBossCollapse = function() {
    this._effectDuration = 90;
    this._appeared = false;

};

Sprite_Enemy.prototype.updateBossCollapse = function() {
    if (this._effectDuration < 30) {
    this.blendMode = 1;
    this.setBlendColor([255, 128, 128, 128]);
    this.opacity *= this._effectDuration / (this._effectDuration + 1);
    }
};




Related to what @Andar says: I see/hear the victory screen & its theme is brought at the moment the collapse is triggered (at 0HP). Well... I thought maybe I could add dead-air delay in the victory theme too. I'll think about it.
Oh yeah forgot about the collapse sound effects. I guess you could take them off from Game_Enemy.prototype.performCollapse and instead add them to the updateCollapse methods.

And for the boss collapse I think make checks for the effect duration too (added +60 to effect duration), like:

Sprite_Enemy.prototype.startBossCollapse = function() {
this._effectDuration = this.bitmap.height + 60;
this._appeared = false;
};

Sprite_Enemy.prototype.updateFrame = function() {
Sprite_Battler.prototype.updateFrame.call(this);
if (this._effectType === "bossCollapse" && this._effectDuration <= this.bitmap.height) {
this.setFrame(0, 0, this.bitmap.width, this._effectDuration);
} else {
this.setFrame(0, 0, this.bitmap.width, this.bitmap.height);
}
};

Sprite_Enemy.prototype.updateBossCollapse = function() {
if (this._effectDuration <= this.bitmap.height) {
this._shake = (this._effectDuration % 2) * 4 - 2;
this.blendMode = 1;
this.opacity *= this._effectDuration / (this._effectDuration + 1);
this.setBlendColor([255, 255, 255, 255 - this.opacity]);
if (this._effectDuration % 20 === 19) {
SoundManager.playBossCollapse2();
}
}
};
This seems to work really well for bosses! Its timing alongside the chiptune-ish explosion sound I added to it previously fits perfectly. I dont even need to alter anything for bosses there... Thank you wolfie (and the rest too). 😍 Now back to the fun stuff, map editing.
Closed at OP's request.

Original thread: https://forums.rpgmakerweb.com/threads/rmmz-question-about-dmg-and-death-check-timing.181710/