I'm wondering, is there a plugin to make it so that a skill can select multiple targets? Not just random enemies, but you get to select each specific target. I looked at Yanfly Target and Select core but as far as I could tell they don't seem to offer this. Is anyone willing to make a quick plugin that does this?
Have Skill Select Multiple Targets?
JS Plugin RequestsEDIT: Please find the most up-to-date version of this Plugin at this thread.
Give this a try:
To use it, have the scope of your skill or item be set to either 1 enemy or 1 ally. If you use a scope that doesn't open up the actor selection window or the enemy selection window, then this Plugin will not work.
In the note box of the skill or item, put <multipleTargets: x>, where x is the number of targets you want to be able to select. For example, in a default project, if you put <multipleTargets: 4> in the note box for the heal skill, then you will be able to select 4 targets.
If you select a target that is no longer valid by the time the battler's action begins, then a random target will be selected instead. As an example, if Harold chooses to heal Harold, Therese, Marsha, and Lucius, but Marsha dies before Harold's turn comes up, then Harold will heal Harold, Therese, a random living party member, and Lucius.
Code:
/*:
* @plugindesc This plugin allows the user to mark a skill as capable of selecting multiple
* single targets, so that it repeats, but not against random enemies.
* @author Zevia
*
* @help For a skill or item, make sure the scope is either 1 enemy or 1 ally. This
* plugin won't work with other scopes. In the skill or item's notebox, put
* <multipleTargets: x>, where x is the number of targets you want the skill to
* affect and allow selection for. For example, if you put <multipleTargets: 4>,
* then the skill will let you select 4 targets.
*/
(function(module) {
'use strict';
var SKILL_DATA_CLASS = 'skill';
module.Zevia = module.Zevia || {};
var SelectMultipleTargets = module.Zevia.MultipleTargets = {};
SelectMultipleTargets.resetTargets = function() {
BattleManager.inputtingAction()._multipleTargets = [];
};
Scene_Battle.prototype.okHandler = function(activeWindow, index) {
var action = BattleManager.inputtingAction();
action.setTarget(index);
var isForFriend = action.isForFriend();
if (index >= 0) {
action._multipleTargets = (action._multipleTargets || []).concat(isForFriend ? $gameParty.battleMembers()[index] : $gameTroop.members()[index]);
}
var item = action._item;
var ability = item._dataClass === SKILL_DATA_CLASS ? $dataSkills[item._itemId] : $dataItems[item._itemId];
var multipleTargets = ability.meta.multipleTargets;
var maxTargets = multipleTargets && parseInt(multipleTargets.match(/\d+/));
if (!multipleTargets || isNaN(maxTargets) || action._multipleTargets.length === maxTargets) {
activeWindow.hide();
this._skillWindow.hide();
this._itemWindow.hide();
this.selectNextCommand();
return;
}
activeWindow.activate();
};
SelectMultipleTargets.onEnemyOk = Scene_Battle.prototype.onEnemyOk;
Scene_Battle.prototype.onEnemyOk = function() {
this.okHandler.call(this, this._enemyWindow, this._enemyWindow.enemyIndex());
};
SelectMultipleTargets.onActorOk = Scene_Battle.prototype.onActorOk;
Scene_Battle.prototype.onActorOk = function() {
this.okHandler.call(this, this._actorWindow, this._actorWindow.index());
};
SelectMultipleTargets.onActorCancel = Scene_Battle.prototype.onActorCancel;
Scene_Battle.prototype.onActorCancel = function() {
SelectMultipleTargets.onActorCancel.call(this);
SelectMultipleTargets.resetTargets();
};
SelectMultipleTargets.onEnemyCancel = Scene_Battle.prototype.onEnemyCancel;
Scene_Battle.prototype.onEnemyCancel = function() {
SelectMultipleTargets.onEnemyCancel.call(this);
SelectMultipleTargets.resetTargets();
};
Game_Action.prototype.confirmTargets = function() {
var isForDeadFriend = this.isForDeadFriend();
var isForFriend = this.isForFriend();
var item = this.item();
var ability = item._dataClass === SKILL_DATA_CLASS ? $dataSkills[item._itemId] : $dataItems[item._itemId];
for (var i = 0; i < this._multipleTargets.length; i++) {
if (!isForDeadFriend && this._multipleTargets[i].isDead()) {
if (isForFriend) {
this._multipleTargets[i] = $gameParty.randomTarget();
} else {
this._multipleTargets[i] = $gameTroop.randomTarget();
}
} else if (isForDeadFriend && !this._multipleTargets[i].isDead()) {
this._multipleTargets[i] = $gameParty.randomDeadTarget();
}
}
return this._multipleTargets;
};
SelectMultipleTargets.targetsForOpponents = Game_Action.prototype.targetsForOpponents;
Game_Action.prototype.targetsForOpponents = function() {
if (this._multipleTargets && this._multipleTargets.length) { return this.confirmTargets(); }
return SelectMultipleTargets.targetsForOpponents.call(this);
};
SelectMultipleTargets.targetsForFriends = Game_Action.prototype.targetsForFriends;
Game_Action.prototype.targetsForFriends = function() {
if (this._multipleTargets && this._multipleTargets.length) { return this.confirmTargets(); }
return SelectMultipleTargets.targetsForFriends.call(this);
};
})(window);
To use it, have the scope of your skill or item be set to either 1 enemy or 1 ally. If you use a scope that doesn't open up the actor selection window or the enemy selection window, then this Plugin will not work.
In the note box of the skill or item, put <multipleTargets: x>, where x is the number of targets you want to be able to select. For example, in a default project, if you put <multipleTargets: 4> in the note box for the heal skill, then you will be able to select 4 targets.
If you select a target that is no longer valid by the time the battler's action begins, then a random target will be selected instead. As an example, if Harold chooses to heal Harold, Therese, Marsha, and Lucius, but Marsha dies before Harold's turn comes up, then Harold will heal Harold, Therese, a random living party member, and Lucius.
The plugin has an issue where it occasionally crashes because "isDead" is not defined. Do you know how to fix that? I think the plugin works otherwise.
I'll take a look after work and see what I can come up with.
The first step of fixing most reported issues is reproducing it, so it would be very helpful if you could figure out how to reliably cause that error to occur. Also, if you could hit F8 when it does and take a screenshot of the console, that would give me more information.
I suspect it has to do with the logic where the Plugin tries to reselect targets because the original one is invalid (like trying to heal or damage someone that died).
EDIT: I've been trying for about 30 minutes with skills that target allies, items that target allies, skills that target enemies, and items that target enemies to produce an error and I'm unable to.
Unfortunately, I can't really fix the issue if I can't reproduce it, so the next time it happens, can you please:
1. Let me know what you were doing right before it happened (were you targeting enemies or allies? Did an enemy or ally that you targeted die before the action actually happened?)
2. Hit F8 to open up the dev console and take a screenshot of it
3. Show me a screenshot of the skill or item you used just before the error occurred
EDIT 2: I encountered an issue where isDead was trying to be called as a method of undefined and have resolved it. I believe this is the problem @Protagonist7 may have been speaking of. The post with the Plugin has been modified with the update.
The first step of fixing most reported issues is reproducing it, so it would be very helpful if you could figure out how to reliably cause that error to occur. Also, if you could hit F8 when it does and take a screenshot of the console, that would give me more information.
I suspect it has to do with the logic where the Plugin tries to reselect targets because the original one is invalid (like trying to heal or damage someone that died).
EDIT: I've been trying for about 30 minutes with skills that target allies, items that target allies, skills that target enemies, and items that target enemies to produce an error and I'm unable to.
Unfortunately, I can't really fix the issue if I can't reproduce it, so the next time it happens, can you please:
1. Let me know what you were doing right before it happened (were you targeting enemies or allies? Did an enemy or ally that you targeted die before the action actually happened?)
2. Hit F8 to open up the dev console and take a screenshot of it
3. Show me a screenshot of the skill or item you used just before the error occurred
EDIT 2: I encountered an issue where isDead was trying to be called as a method of undefined and have resolved it. I believe this is the problem @Protagonist7 may have been speaking of. The post with the Plugin has been modified with the update.
Original thread: https://forums.rpgmakerweb.com/threads/have-skill-select-multiple-targets.104337/