Hello,
As the title suggests, this is what I am trying to achieve.
I want this common event to execute every time the HP regeneration rate is applied to a single character.
Here is what I have put together so far in my attempt:
/*:
* @target MZ
* @plugindesc Common Event on Regeneration
* @author go_comma
*
* @param CommonEvent1
* @text Common Event when HP is recovered
* @type common_event
* @default 0
*
* @param CommonEvent2
* @text Common Event when HP is decreased
* @type common_event
* @default 0
*
* @param Variable
* @text Variable to store the battler that triggered regeneration. The index starts at 0; for actors, the actor ID is reflected directly, and for enemies, 1000 is added.
* @type variable
* @default 0
*
* @help
* Executes the specified common event when the "HP Regeneration Rate" is applied.
* By storing the target in a variable, you can also determine which character should act within the common event.
*/
(() => {
"use strict";
Game_Battler.prototype.regenerateHp = function() {
const minRecover = -this.maxSlipDamage();
const value = Math.max(Math.floor(this.mhp * this.hrg), minRecover);
if (value !== 0) {
this.gainHp(value);
// Up to here is normal behavior
const Vindex=Number(PluginManager.parameters("regenerationCommon").Variable)
Vindex!=0 && $gameVariables.setValue(Vindex,this.index()+(this.isActor() ? 0 : 1000))//If a variable is specified, store the index in the variable. Check if this is an actor or enemy, and add 1000 if it is an enemy.
const common1 = Number(PluginManager.parameters("regenerationCommon").CommonEvent1)
const common2 = Number(PluginManager.parameters("regenerationCommon").CommonEvent2)
//↓ Since I am only reserving them, they are likely being overwritten by later reservations
0<common1 && common1 < $dataCommonEvents.length && value>0 && $gameTemp.reserveCommonEvent(common1)//If a common event for recovery is specified, execute Common Event 1
0<common2 && common2 < $dataCommonEvents.length && value<0 && $gameTemp.reserveCommonEvent(common2)//If a common event for damage is specified, execute Common Event 2
//↑
}
};
})();
This does reserve the common event for each HP regeneration rate processing, but it is executed only after the regeneration processing is complete. As a result, it seems that only one common event fires, reflecting the information of the last character.
How can I modify this so that the common event fires once for each character every time the HP regeneration rate is applied?
Also, regardless of plugin knowledge, if anyone knows a method to insert a common event every time regeneration triggers for a single character, I would appreciate any information you can provide!