MZ How to check if states have expired?

I am trying to find if there is a way to check if certain states have expired.
As you see below, I am making a skill that changes the environment (in this case, display a rain effect once skill is activated) and I want it to erase the effect once the state has expired. (Or once the battle has ended.)
Is there any way to do this?
bandicam 2026-03-23 16-43-23-562.jpg
If a state is expired, then you no longer have the state, so it's simply using a Conditional Branch command to check "If Actor X has State Y"? Or am I misunderstanding the question?
If a state is expired, then you no longer have the state, so it's simply using a Conditional Branch command to check "If Actor X has State Y"? Or am I misunderstanding the question?
I want it to apply for both actors and enemies using this skill.
There is a conditional branch for If Enemy X has State Y. You can call it from Battle Events from Troops at least.
I don't own MZ, but I'm sure you can run that in script calls.

Works in MV, should work in MZ:
$gameParty.members().some(function(member){ return member.isStateAffected(stateId) });

New method that MZ should be using:
$gameParty.members().some(m => m.isStateAffected(stateId))

Either way, for enemies, start with: $gameTroop.members()
No script calls required – you can just use conditional branch statements. That said, the script call is a lot more compact – you'd need 16 branches for enemies and 2 branches for every actor that could possibly be in the party.

You probably also need a plugin that runs events before the battle ends. Normally, the moment all the enemies are defeated, the battle ends immediately without processing any further events.
No script calls required – you can just use conditional branch statements. That said, the script call is a lot more compact – you'd need 16 branches for enemies and 2 branches for every actor that could possibly be in the party.

You probably also need a plugin that runs events before the battle ends. Normally, the moment all the enemies are defeated, the battle ends immediately without processing any further events.
Are there any plugins that allow you to run a common event on battle end?
The plugin series SunMZ_0_CoreRpg.js
includes this functionality, but I cannot guarantee its compatibility with VisuStella MZ.
Are there any plugins that allow you to run a common event on battle end?
I don't know about a common event, but there are definitely some that allow regular troop events to run at the end of the battle.
Are there any plugins that allow you to run a common event on battle end?
Galv's plugin: https://galvs-scripts.com/2020/10/21/mz-auto-common-events/

Along with this patch. Just save the code with the same name at the top in a .js file from notepad. And let me know if it doesn't work.

Spoiler: Code
JavaScript:
//-----------------------------------------------------------------------------
//  GALV_AutoCommonEventsMZ_BattleEnd_Patch.js
//-----------------------------------------------------------------------------
//  Version 1.0 - Release
//-----------------------------------------------------------------------------
//  REQUIRES: GALV_AutoCommonEventsMZ.js (v1.4) loaded BEFORE this plugin.
//
//  https://galvs-scripts.com/2020/10/21/mz-auto-common-events/
//
//-----------------------------------------------------------------------------

/*:
 * @plugindesc Adds a 'Battle End' common event to Galv's Auto Common Events MZ.
 * Requires GALV_AutoCommonEventsMZ.js loaded above this plugin.
 * @target MZ
 * @author (patch)
 * @base GALV_AutoCommonEventsMZ
 *
 * @param battleEnd
 * @text Battle End Common Event
 * @desc Common event id run when a battle ends, regardless of outcome
 * (victory, escape, or losable defeat). Runs in the battle scene.
 * @type common_event
 * @default 0
 *
 * @help
 *   Galv's Auto Common Events MZ - Battle End Patch
 * ----------------------------------------------------------------------------
 * Place this plugin BELOW GALV_AutoCommonEventsMZ.js in the plugin list.
 *
 * This patch adds one new trigger type to Galv's Auto Common Events:
 *
 *   'battleEnd'  - Runs at the end of every battle, in the battle scene,
 *                  before the player is returned to the map. Fires on
 *                  victory, escape, and defeat (when the party can lose).
 *                  Does NOT fire if a Game Over common event is set and
 *                  the party suffers a non-losable defeat.
 *
 * You can also change the event id at runtime with Galv's script call:
 *
 *     Galv.ACE.id(x, 'battleEnd');
 *
 * ----------------------------------------------------------------------------
 */

var Imported = Imported || {};

(function() {

'use strict';

if (!Imported.Galv_AutoCommonEvents) {
    console.error(
        '[GALV ACE - Battle End Patch] ERROR: GALV_AutoCommonEventsMZ.js was ' +
        'not found. Please add it to your plugin list ABOVE this patch.'
    );
    return;
}

Imported.Galv_AutoCommonEvents_BattleEndPatch = true;

const PATCH_PLUGIN_NAME = 'GALV_AutoCommonEventsMZ_BattleEnd_Patch';
const PATCH_PARAMS = PluginManager.parameters(PATCH_PLUGIN_NAME);

//  GAME SYSTEM
const _Game_System_buildAutoCommonEvents = Game_System.prototype.buildAutoCommonEvents;
Game_System.prototype.buildAutoCommonEvents = function() {
    _Game_System_buildAutoCommonEvents.call(this);
    this._autoCommonEventIds['battleEnd'] = Number(PATCH_PARAMS['battleEnd']) || 0;
};

//  BATTLE MANAGER
const BATTLE_RESULT_DEFEAT = 2;

const _BattleManager_endBattle = BattleManager.endBattle;
BattleManager.endBattle = function(result) {
    // Skip on game over
    const isDefeatedWithGameOver = (result === BATTLE_RESULT_DEFEAT) && Galv.ACE.exists('gameOver') && !this._canLose;
    if (!isDefeatedWithGameOver) Galv.ACE.runId('battleEnd');
    _BattleManager_endBattle.call(this, result);
};

})();
Galv's plugin: https://galvs-scripts.com/2020/10/21/mz-auto-common-events/

Along with this patch. Just save the code with the same name at the top in a .js file from notepad. And let me know if it doesn't work.

Spoiler: Code
JavaScript:
//-----------------------------------------------------------------------------
//  GALV_AutoCommonEventsMZ_BattleEnd_Patch.js
//-----------------------------------------------------------------------------
//  Version 1.0 - Release
//-----------------------------------------------------------------------------
//  REQUIRES: GALV_AutoCommonEventsMZ.js (v1.4) loaded BEFORE this plugin.
//
//  https://galvs-scripts.com/2020/10/21/mz-auto-common-events/
//
//-----------------------------------------------------------------------------

/*:
 * @plugindesc Adds a 'Battle End' common event to Galv's Auto Common Events MZ.
 * Requires GALV_AutoCommonEventsMZ.js loaded above this plugin.
 * @target MZ
 * @author (patch)
 * @base GALV_AutoCommonEventsMZ
 *
 * @param battleEnd
 * @text Battle End Common Event
 * @desc Common event id run when a battle ends, regardless of outcome
 * (victory, escape, or losable defeat). Runs in the battle scene.
 * @type common_event
 * @default 0
 *
 * @help
 *   Galv's Auto Common Events MZ - Battle End Patch
 * ----------------------------------------------------------------------------
 * Place this plugin BELOW GALV_AutoCommonEventsMZ.js in the plugin list.
 *
 * This patch adds one new trigger type to Galv's Auto Common Events:
 *
 *   'battleEnd'  - Runs at the end of every battle, in the battle scene,
 *                  before the player is returned to the map. Fires on
 *                  victory, escape, and defeat (when the party can lose).
 *                  Does NOT fire if a Game Over common event is set and
 *                  the party suffers a non-losable defeat.
 *
 * You can also change the event id at runtime with Galv's script call:
 *
 *     Galv.ACE.id(x, 'battleEnd');
 *
 * ----------------------------------------------------------------------------
 */

var Imported = Imported || {};

(function() {

'use strict';

if (!Imported.Galv_AutoCommonEvents) {
    console.error(
        '[GALV ACE - Battle End Patch] ERROR: GALV_AutoCommonEventsMZ.js was ' +
        'not found. Please add it to your plugin list ABOVE this patch.'
    );
    return;
}

Imported.Galv_AutoCommonEvents_BattleEndPatch = true;

const PATCH_PLUGIN_NAME = 'GALV_AutoCommonEventsMZ_BattleEnd_Patch';
const PATCH_PARAMS = PluginManager.parameters(PATCH_PLUGIN_NAME);

//  GAME SYSTEM
const _Game_System_buildAutoCommonEvents = Game_System.prototype.buildAutoCommonEvents;
Game_System.prototype.buildAutoCommonEvents = function() {
    _Game_System_buildAutoCommonEvents.call(this);
    this._autoCommonEventIds['battleEnd'] = Number(PATCH_PARAMS['battleEnd']) || 0;
};

//  BATTLE MANAGER
const BATTLE_RESULT_DEFEAT = 2;

const _BattleManager_endBattle = BattleManager.endBattle;
BattleManager.endBattle = function(result) {
    // Skip on game over
    const isDefeatedWithGameOver = (result === BATTLE_RESULT_DEFEAT) && Galv.ACE.exists('gameOver') && !this._canLose;
    if (!isDefeatedWithGameOver) Galv.ACE.runId('battleEnd');
    _BattleManager_endBattle.call(this, result);
};

})();
I tried testing it, but it doesn't seem to run the event properly.
I don't know if this is an issue with the event itself or if both plugins (AutoCommonEvents + patch) are interfering with VisuStellaMZ.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-states-have-expired.182992/