MZ Low Health plugin

hai i be making a fangame and im lookin for a simple plugin that plays a Sound when an actor is low on HP in battle.

probably just like in Paper Mario or Pokemon


So do you have just one actor like in Pokemon? I think you can use something like this:

const _myEdit1_BattleManager_update = BattleManager.update;

BattleManager.update = function(timeActive) {
_myEdit1_BattleManager_update.call(this, timeActive);
if ($gameActors.actor(1).hpRate() < 0.25)
$gameTemp._lowHealthBeepTimer = ($gameTemp._lowHealthBeepTimer ?? 0) + 1;
if ($gameTemp._lowHealthBeepTimer > 15) {
AudioManager.playSe({
name: 'Attack1',
volume: 100,
pitch: 100
});
$gameTemp._lowHealthBeepTimer = 0;
}
};
const _myEdit2_SceneBattle_terminate = Scene_Battle.prototype.terminate;

Scene_Battle.prototype.terminate = function() {
_myEdit2_SceneBattle_terminate.call(this);
delete $gameTemp._lowHealthBeepTimer;
};
Additionally, Turan has a plugin for low hp music if youre interested in doing something like the gen 5 low hp song. look for the danger music plugin attached.
So do you have just one actor like in Pokemon? I think you can use something like this:

const _myEdit1_BattleManager_update = BattleManager.update;

BattleManager.update = function(timeActive) {
_myEdit1_BattleManager_update.call(this, timeActive);
if ($gameActors.actor(1).hpRate() < 0.25)
$gameTemp._lowHealthBeepTimer = ($gameTemp._lowHealthBeepTimer ?? 0) + 1;
if ($gameTemp._lowHealthBeepTimer > 15) {
AudioManager.playSe({
name: 'Attack1',
volume: 100,
pitch: 100
});
$gameTemp._lowHealthBeepTimer = 0;
}
};
const _myEdit2_SceneBattle_terminate = Scene_Battle.prototype.terminate;

Scene_Battle.prototype.terminate = function() {
_myEdit2_SceneBattle_terminate.call(this);
delete $gameTemp._lowHealthBeepTimer;
};
There's 3 actors but only uses 2 party members in battle. Going for a more paper mario-esc game
Well you can just add the other dude in the conditional:
if ($gameActors.actor(1).hpRate() < 0.25 || $gameActors.actor(2).hpRate() < 0.25)
So do you have just one actor like in Pokemon? I think you can use something like this:

const _myEdit1_BattleManager_update = BattleManager.update;

BattleManager.update = function(timeActive) {
_myEdit1_BattleManager_update.call(this, timeActive);
if ($gameActors.actor(1).hpRate() < 0.25)
$gameTemp._lowHealthBeepTimer = ($gameTemp._lowHealthBeepTimer ?? 0) + 1;
if ($gameTemp._lowHealthBeepTimer > 15) {
AudioManager.playSe({
name: 'Attack1',
volume: 100,
pitch: 100
});
$gameTemp._lowHealthBeepTimer = 0;
}
};
const _myEdit2_SceneBattle_terminate = Scene_Battle.prototype.terminate;

Scene_Battle.prototype.terminate = function() {
_myEdit2_SceneBattle_terminate.call(this);
delete $gameTemp._lowHealthBeepTimer;
};
oki got home and did tried this out, and it DOES work!!

though would be nice for it to stop playing the sound if that actor is dead.

as for the other conditional, dumb question.
wouldn't it make sense to put $gameParty.members()[2]? don't need like a specific actor, i might be wrong tho (not a great coder). but thanks anyways 😀
Cool.

Yeah, try changing the beginning spot like this:
...
_myEdit1_BattleManager_update.call(this, timeActive);
const actor1 = $gameParty.members()[0];
const actor2 = $gameParty.members()[1];
if ((actor1?.isAlive() && actor1?.hpRate() < 0.25) || (actor2?.isAlive() && actor2?.hpRate() < 0.25))
...
Cool.

Yeah, try changing the beginning spot like this:
...
_myEdit1_BattleManager_update.call(this, timeActive);
const actor1 = $gameParty.members()[0];
const actor2 = $gameParty.members()[1];
if ((actor1?.isAlive() && actor1?.hpRate() < 0.25) || (actor2?.isAlive() && actor2?.hpRate() < 0.25))
...
ok this works really well!!

tysm!!

Original thread: https://forums.rpgmakerweb.com/threads/low-health-plugin.182583/