Okay, this is an interesting and challenging request! You want to completely decouple enemy attacks from the standard turn-based system in RPG Maker MV, making them act on their own random timers.
This requires overriding several core parts of the battle system:
Game_Enemy: To give each enemy its own attack timer and a method to initiate a real-time attack.
BattleManager: To stop the standard enemy turn processing and instead manage a queue of real-time enemy actions.
Scene_Battle: To properly handle the end of these real-time actions and reset flags.
Here's a plugin script that accomplishes this.
Plugin: EnemyRealtimeAttack.js
Save this code as a .js file (e.g., EnemyRealtimeAttack.js) and place it in your project's js/plugins folder. Then, enable it in the RPG Maker MV Plugin Manager. Make sure it's placed below any other plugins that might significantly alter battle mechanics (like ATB systems), unless you specifically want this to override them.
/*:
* @plugindesc Makes enemies attack randomly every 4-6 seconds, ignoring player turns.
* @author YourName (Adapted from RPG Maker MV Core)
*
* @param Min Attack Delay
* @type number
* @min 60
* @default 240
* @desc Minimum delay in frames (60 frames = 1 second) before an enemy attacks again. (4 seconds)
*
* @param Max Attack Delay
* @type number
* @min 60
* @default 360
* @desc Maximum delay in frames (60 frames = 1 second) before an enemy attacks again. (6 seconds)
*
* @help
* This plugin modifies the default enemy attack mechanic in RPG Maker MV.
*
* Key Features:
* - Enemies will attack randomly every X to Y seconds (configurable),
* regardless of whether it's the player's turn or if the player is choosing actions.
* - They will use a random skill from their learned skills.
* - Animations and skill effects will play as normal.
* - This only affects enemies; actors' turns and behavior remain unchanged.
*
* How it works:
* 1. Each active enemy in battle gets its own timer.
* 2. When an enemy's timer runs out, it picks a random skill and a random
* alive actor, then queues this action for the BattleManager.
* 3. The BattleManager processes these queued actions one by one, ensuring
* animations and effects play correctly.
* 4. After an enemy performs an attack, its timer is reset.
* 5. The default "enemy action phase" in BattleManager is effectively
* disabled for enemies, as they now attack dynamically.
*
* Plugin Parameters:
* Min Attack Delay: The shortest time (in frames) an enemy will wait
* before attempting to attack again. (Default: 240 frames = 4 seconds)
* Max Attack Delay: The longest time (in frames) an enemy will wait
* before attempting to attack again. (Default: 360 frames = 6 seconds)
*
* Important Notes:
* - This plugin directly overrides core BattleManager and Game_Enemy methods.
* - It might conflict with other plugins that extensively modify the battle
* turn order or enemy AI. Place this plugin below such plugins if
* you want its behavior to take precedence.
* - Enemies choose from *all* their learned skills. If you want them to
* only use certain skills, you'd need to modify the `performRealtimeAttack`
* function in the script to filter skills (e.g., exclude healing skills for
* enemies that should only attack).
*/
(function() {
// --- Plugin Parameters ---
var parameters = PluginManager.parameters('EnemyRealtimeAttack');
var minAttackDelay = parseInt(parameters['Min Attack Delay'] || 240);
var maxAttackDelay = parseInt(parameters['Max Attack Delay'] || 360);
// --- Game_Enemy Overrides ---
// Alias the original initialize to add new properties for enemy
var _Game_Enemy_initialize = Game_Enemy.prototype.initialize;
Game_Enemy.prototype.initialize = function(enemyId, x, y) {
_Game_Enemy_initialize.apply(this, arguments);
this._realtimeAttackTimer = 0;
this._isPerformingRealtimeAttack = false; // Flag to prevent multiple attacks queueing from this enemy
this.resetRealtimeAttackTimer();
};
// Resets the attack timer to a random value within the defined range
Game_Enemy.prototype.resetRealtimeAttackTimer = function() {
this._realtimeAttackTimer = Math.randomInt(maxAttackDelay - minAttackDelay) + minAttackDelay;
};
// Alias the original update method for enemies
var _Game_Enemy_update = Game_Enemy.prototype.update;
Game_Enemy.prototype.update = function() {
_Game_Enemy_update.apply(this, arguments);
// Only process if in battle, enemy is appeared, alive, and BattleManager isn't busy with another real-time action
if ($gameParty.inBattle() && this.isAppeared() && this.isAlive() && !BattleManager._isRealtimeActionProcessing) {
this._realtimeAttackTimer--;
if (this._realtimeAttackTimer <= 0 && !this._isPerformingRealtimeAttack) {
this.performRealtimeAttack();
}
}
};
// Method for an enemy to perform a real-time attack
Game_Enemy.prototype.performRealtimeAttack = function() {
var subject = this;
var skills = subject.skills(); // Get all learned skills for this enemy
if (skills.length === 0) return; // No skills, can't attack
var action = new Game_Action(subject);
// Randomly pick a skill from the enemy's available skills
var skill = skills[Math.randomInt(skills.length)];
action.setSkill(skill.id);
// Find a random alive actor as target
var target = $gameParty.randomTarget();
if (!target) return; // No target, can't attack
action.setTarget(target.index());
// Set the flag to indicate this enemy is currently initiating an attack
this._isPerformingRealtimeAttack = true;
// Queue this action for the BattleManager to process
BattleManager.queueRealtimeEnemyAction(action, subject);
};
// --- BattleManager Overrides ---
// Alias initMembers to add new properties for BattleManager
var _BattleManager_initMembers = BattleManager.initMembers;
BattleManager.initMembers = function() {
_BattleManager_initMembers.apply(this, arguments);
this._realtimeEnemyActionQueue = []; // Queue for real-time enemy actions
this._isRealtimeActionProcessing = false; // Flag to indicate if a real-time action is being processed
};
// Override startEnemyActions to do nothing for regular turns
// Enemies will attack dynamically via their individual timers
BattleManager.startEnemyActions = function() {
// Do nothing here, as enemies attack dynamically via their Game_Enemy.update method.
// We still need to call endAction to proceed to the next phase (actor command input).
this.endAction();
};
// New method to queue real-time enemy actions
BattleManager.queueRealtimeEnemyAction = function(action, subject) {
this._realtimeEnemyActionQueue.push({ action: action, subject: subject });
};
// Alias BattleManager's update method to process the real-time action queue
var _BattleManager_update = BattleManager.update;
BattleManager.update = function() {
_BattleManager_update.apply(this, arguments); // Call original update to maintain other battle logic
// If in battle phase, not busy, no real-time action is currently processing,
// and there are actions in the queue, then process one.
if (this._phase === 'battle' && !this.isBusy() && !this._isRealtimeActionProcessing && this._realtimeEnemyActionQueue.length > 0) {
this.processRealtimeEnemyAction();
}
};
// Method to process a queued real-time enemy action
BattleManager.processRealtimeEnemyAction = function() {
var actionData = this._realtimeEnemyActionQueue.shift();
if (!actionData) return;
var action = actionData.action;
var subject = actionData.subject;
// Ensure the subject is still valid (alive and appeared)
if (!subject || !subject.isAlive() || !subject.isAppeared()) {
if (subject) {
subject._isPerformingRealtimeAttack = false; // Reset flag if subject is invalid
subject.resetRealtimeAttackTimer(); // Reset timer
}
return;
}
this._isRealtimeActionProcessing = true; // Set flag that a real-time action is in progress
this._currentSubject = subject; // Set current subject for BattleManager's internal use
this._currentAction = action; // Set current action
subject.requestMotion("chant"); // Optional: show enemy preparing to attack
subject.startAction(); // Begin action phase for the enemy visually (e.g., in battle log)
this.invokeAction(subject, action); // Perform the actual skill execution
};
// --- Scene_Battle Overrides ---
// Alias endAction to handle resetting real-time attack flags
var _Scene_Battle_endAction = Scene_Battle.prototype.endAction;
Scene_Battle.prototype.endAction = function() {
var subject = BattleManager._currentSubject; // Get the subject of the action that just ended
_Scene_Battle_endAction.apply(this, arguments); // Call original endAction
// If the action that just ended was a real-time enemy action
if (BattleManager._isRealtimeActionProcessing) {
if (subject && subject.isEnemy()) {
subject._isPerformingRealtimeAttack = false; // Clear enemy's performing flag
subject.resetRealtimeAttackTimer(); // Reset enemy's timer for next attack
}
BattleManager._isRealtimeActionProcessing = false; // Clear BattleManager's processing flag
BattleManager._currentSubject = null; // Clear current subject
BattleManager._currentAction = null; // Clear current action
}
};
// Optional: Adjust how the battle log displays subject names
// This prevents the enemy's name from briefly appearing as a "turn" subject
// when they perform a real-time attack, as it's not a formal turn.
var _Window_BattleLog_displaySubject = Window_BattleLog.prototype.displaySubject;
Window_BattleLog.prototype.displaySubject = function(subject) {
if (BattleManager._isRealtimeActionProcessing && subject.isEnemy()) {
// Do nothing if it's a real-time enemy action
} else {
_Window_BattleLog_displaySubject.apply(this, arguments);
}
};
// Optional: Hide the enemy command window if using ATB or something similar
// to avoid confusion if the enemy phase is skipped.
var _Scene_Battle_createEnemyWindow = Scene_Battle.prototype.createEnemyWindow;
Scene_Battle.prototype.createEnemyWindow = function() {
_Scene_Battle_createEnemyWindow.apply(this, arguments);
// No explicit hide here, as the startEnemyActions override naturally handles it.
// If you see a flickering enemy selection window, you might uncomment this:
// this._enemyWindow.hide();
};
})();
How to Install and Use:
- Save the Code: Open a plain text editor (like Notepad, Sublime Text, VS Code, etc.). Copy the entire code block above and paste it into the editor. Save the file as
EnemyRealtimeAttack.js (or any other descriptive name ending in .js).
- Place in Project: Navigate to your RPG Maker MV project folder. Inside it, go to
js/plugins. Paste your EnemyRealtimeAttack.js file there.
- Enable in RPG Maker MV:
- Open your RPG Maker MV project.
- Go to "Tools" -> "Plugin Manager..." (or click the puzzle piece icon in the toolbar).
- Double-click an empty row to open the Plugin Editor.
- For "Name", select
EnemyRealtimeAttack from the dropdown list.
- Set "Status" to
ON.
- You can adjust the "Min Attack Delay" and "Max Attack Delay" parameters here to change the random timing.
- Click "OK" and then "Apply" in the Plugin Manager.
- Test Your Game: Run a battle in your game. You should now observe enemies attacking independently of player turns, using their skills randomly.
Explanation of Changes:
Game_Enemy.prototype.initialize & update: Each Game_Enemy now has a _realtimeAttackTimer and a _isPerformingRealtimeAttack flag. In its update loop (which runs every frame in battle), it decrements this timer. When the timer hits zero and the enemy isn't already attacking, it calls performRealtimeAttack.
Game_Enemy.prototype.performRealtimeAttack: This function selects a random skill from the enemy's learned skills and a random alive actor target. It then creates a Game_Action object and hands it over to the BattleManager by calling BattleManager.queueRealtimeEnemyAction. It also sets its _isPerformingRealtimeAttack flag to true to prevent itself from queuing another action until the current one is finished.
BattleManager.prototype.startEnemyActions: This crucial override disables the standard enemy turn phase. Instead of making enemies act, it simply calls this.endAction(), which quickly moves the battle state to the player command input phase.
BattleManager.prototype.initMembers & update: The BattleManager now has a _realtimeEnemyActionQueue and a _isRealtimeActionProcessing flag. Its update method constantly checks this queue. If there are actions waiting and the BattleManager isn't currently busy processing another real-time action, it takes the next action from the queue and calls processRealtimeEnemyAction.
BattleManager.prototype.processRealtimeEnemyAction: This method is responsible for taking a queued action, setting _isRealtimeActionProcessing to true, setting the _currentSubject and _currentAction (which is important for the battle log and animations), requesting a "chant" motion (optional visual feedback), and finally calling this.invokeAction(subject, action) to execute the skill.
Scene_Battle.prototype.endAction: This is where the cleanup happens. After any action (player or enemy) finishes its animation and effects, this method is called. We've aliased it to check if the action that just finished was a _isRealtimeActionProcessing enemy action. If so, it resets the _isPerformingRealtimeAttack flag on the enemy and clears the _isRealtimeActionProcessing flag on , allowing the next real-time action to be processed or the enemy's timer to start counting down again.
This setup should give you the dynamic, real-time enemy attacks you're looking for, without altering your actors' behavior.