Target Any Scope

RPG Maker provides some skill and item scopes like “for one ally” or “for all enemies” but there isn’t really an option to target anyone or everyone.

This plugin provides you with the ability to do so with a simple note tag!
Check out this video for a demonstration on how it looks in-game




Download

Get it here: https://himeworks.com/2020/08/target-any-scope/
Terms of Use: https://himeworks.com/terms-of-use/
Not bad! I will definitely use this to create background environmental hazards that affect both enemies and heroes.

Just a heads up I think you left left a console.log() at lines 83 and 112 by mistake
like a bit of pokemon skill "explode" or "sacrafice" that dmg all , itself and all surroundings.
also very usefull for earthquake, (not effective on flying type count,the cast wont be
affecting and the rest around it does, not sure if it's do able, but something that alot
of dev's can use 🙂

can you also use a skill with target 4 enemies, or select 6 targets for example?
help please. get this error when targeting one friend. anyone.

Code:
TypeError: Cannot read properties of undefined (reading 'friendsUnit')
    at Game_Action.targetsForAny (HIME_TargetAnyScope.js:154:26)
    at Game_Action.targetsForOpponents (HIME_TargetAnyScope.js:123:19)
    at Game_Action.makeTargets (rpg_objects.js:1448:24)
    at BattleManager.startAction (rpg_managers.js:2509:26)
    at BattleManager.processTurn (rpg_managers.js:2437:18)
    at BattleManager.updateTurn (rpg_managers.js:2425:14)
    at BattleManager.update (rpg_managers.js:2250:18)
    at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265:23)
    at Scene_Battle.update (rpg_scenes.js:2257:14)
    at SceneManager.updateScene (rpg_managers.js:2024:25)
SceneManager.catchException @ rpg_managers.js:1949

on a fresh new mv installation.
Same as the previous poster, I also get the same error "cannot read property 'friendsUnit' of undefined. Except my lines are 124 and 154. I've marked them in the snippets below.

Code:
    var TH_GameAction_targetsForOpponents = Game_Action.prototype.targetsForOpponents;
    Game_Action.prototype.targetsForOpponents = function() {
        if (this.isForAny()) {
            return this.targetsForAny(); //this is line 124
        }
        return TH_GameAction_targetsForOpponents.call(this);
    }

Code:
    Game_Action.prototype.targetsForAny = function() {
        var targets = [];
        var battlers = BattleManager.allBattleMembers();
        if (this.isForAnyAll()) {

            // hardcodeonly alive members
            for (var i = 0; i < battlers.length; i++) {
                var battler = battlers[i];
                if (battler.isAlive()) {
                    targets.push(battler);
                }
            }

        } else if (this.isForAnyOne()) {
            var battler = battlers[this._targetIndex];
            // assume we target next friend
            var unit = battler.friendsUnit(); //this is line 154
            targets.push(unit.smoothTarget(battler.index()));
        }
        return targets;
    }

From what I can see friendsUnit looks properly defined? But hey, I'm not a programmer! I just stumble around this stuff haha.
From what I can see friendsUnit looks properly defined?
The error is "cannot read property 'friendsUnit' of undefined". The implication isnt that friendsUnit() is undefined, but that battler is undefined. that would realistically necessitate this._targetIndex either being undefined, -1, or -2.

does this error happen when the plugin is the only plugin installed?
Ah interesting. I tried it out in a new, blank project and the error still occurs. Strangely, it doesn't always occur immediately but sometimes after selecting different targets a couple times, both on a fresh project and on my current project.
I got that error when an enemy used a <scope: any one> attack. I'm not sure if that is what causes the issue, but I swapped the skill out for a copy without the tag because it was a boss that I didn't want to target itself, and it ended up working.
If that is the case, you can use two copies, one that targets 1 enemy and one that targets 1 ally, and put them both in the enemy's action pattern to get around it.

Another issue I ran into was that when there are dead troop or party members the target indexes get all mixed up. e.g. Bat A is killed. Bat C is selected as target. Spell is cast on Bat B.

I was able to fix this one by adding this function:
Code:
  Scene_Battle.prototype.aliveGuys = function() {
    var targets = [];
    var battlers = BattleManager.allBattleMembers();
    for (var i = 0; i < battlers.length; i++) {
      var battler = battlers[i];
      if (battler.isAlive()) {
        targets.push(battler);
      }
    }
    return targets;
  }

And then replacing BattleManager.allBattleMembers() with Scene_Battle.prototype.aliveGuys() in the following two functions:
Code:
  Game_Action.prototype.targetsForAny = function() {
    var targets = [];
    var battlers = Scene_Battle.prototype.aliveGuys();
    if (this.isForAnyAll()) {
   
      // hardcodeonly alive members
      for (var i = 0; i < battlers.length; i++) {
        var battler = battlers[i];
        if (battler.isAlive()) {
          targets.push(battler);
        }
      }
     
    }
    else if (this.isForAnyOne()) {
      var battler = battlers[this._targetIndex];
      // assume we target next friend
      var unit = battler.friendsUnit();
      targets.push(unit.smoothTarget(battler.index()));
    }
    return targets;
  }
 
  Window_BattleAll.prototype.refresh = function() {
    this._enemies = []
    var battlers = Scene_Battle.prototype.aliveGuys();
    for (var i = 0; i < battlers.length; i++) {
      var battler = battlers[i];
      if (battler.isAlive()) {
        this._enemies.push(battler);
      }
    }

Original thread: https://forums.rpgmakerweb.com/threads/target-any-scope.125810/