3 Random Different Enemies Targeted as opposed to 3 Random Targets

Hi everyone,

I'm trying to create a skill that can target UP TO 3 enemies, ONCE each - if that makes sense. Meaning, the damage is only inflicted once on each enemy the skill targets, as opposed to the damage potentially inflicting on the same target twice.

This would of course mean that the battle troop needs to contain 3 or more enemies for the skill to be used to its full advantage, otherwise only 1 or 2 enemies would receive damage (depending on the troop size).

Plugin solutions are welcome, but I'd rather they be YEP plugins. I did have a look through Target Core but I couldn't find anything immediately useful that I could see, unless I could use a Lunatic code solution (but I don't know code).

Perhaps an action sequence would be the best way to tackle this? Still, I can't quite get my head around how I would make sure the enemies are different each time the skill executes.
So something like this? http://www.yanfly.moe/wiki/Chain_Lightning_(MV_Plugin_Tips_&_Tricks)

Only difference is that you don't use the damage notetags and just change "extraTargets" to 2.

JavaScript:
<Custom Target Eval>
// Adds the selected target to the target list.
targets.push(target);
// Grab the group of alive foes as candidates.
var members = foes.aliveMembers();
// Remove the target from the group of candidates.
members.splice(members.indexOf(target), 1);
// This is the number of extra targets to select with Chain Lightning.
var extraTargets = 2;
// Loop the extra targets.
while (extraTargets--) {
  // Grab a random foe from the alive foes.
  var member = members[Math.floor(Math.random() * members.length)];
  // Check to see if the member exists.
  if (member) {
    // Add the member to the group of targets.
    targets.push(member);
    // Remove the member as a viable candidate.
    members.splice(members.indexOf(member), 1);
  }
}
</Custom Target Eval>
Right, thanks @zaraku that's great - however doesn't it mean that the player still has to specify the first target?

EDIT: Apologies for that brain fart, I just need to change the target scope to 1 Random Enemy and it works beautifully.

One thing though, is there anyway to change the "1 Random Enemy" text in a specific instance, or only in all instances?
One thing though, is there anyway to change the "1 Random Enemy" text in a specific instance, or only in all instances?
Unfortunately I can't help you with changing the text, but if you prefer "3 Random Enemies" then you can switch to that scope and then use this modified notetag:

Code:
<Custom Target Eval>
// Grab the group of alive foes as candidates.
var members = foes.aliveMembers();
// Remove the target from the group of candidates.
members.splice(members.indexOf(target), 1);
// This is the number of extra targets to select with Chain Lightning.
var extraTargets = 3;
// Loop the extra targets.
while (extraTargets--) {
  // Grab a random foe from the alive foes.
  var member = members[Math.floor(Math.random() * members.length)];
  // Check to see if the member exists.
  if (member) {
    // Add the member to the group of targets.
    targets.push(member);
    // Remove the member as a viable candidate.
    members.splice(members.indexOf(member), 1);
  }
}
</Custom Target Eval>
Oh that would be great! Thank you!
Hi again @zaraku - thanks for that last script, but it doesn't seem it works when there are only 2 enemies available in the target scope - as it only performs the skill on 1 of the enemies when the target scope is set to 3 Random Enemies. Any idea why this would be?
Hi again @zaraku - thanks for that last script, but it doesn't seem it works when there are only 2 enemies available in the target scope - as it only performs the skill on 1 of the enemies when the target scope is set to 3 Random Enemies. Any idea why this would be?
Apologies, I didn't test all use cases. Apparently the first notetag that I posted also works with 3 random enemies scope, does it work on your end as well?
@thepsyche try this:

JavaScript:
<Custom Target Eval>
// Grab the group of alive foes as candidates.
var members = foes.aliveMembers();
// Remove the target from the group of candidates.
members.splice(members.indexOf(target), 0);
// This is the number of extra targets to select with Chain Lightning.
var extraTargets = 4;
// Loop the extra targets.
while (extraTargets--) {
  // Grab a random foe from the alive foes.
  var member = members[Math.floor(Math.random() * members.length)];
  // Check to see if the member exists.
  if (member) {
    // Add the member to the group of targets.
    targets.push(member);
    // Remove the member as a viable candidate.
    members.splice(members.indexOf(member), 1);
  }
}
</Custom Target Eval>

where "var extraTargets = 4;" is a number of enemy and "members.splice(members.indexOf(target), 0);" set at "0" for correct your problem 🙂

Original thread: https://forums.rpgmakerweb.com/threads/3-random-different-enemies-targeted-as-opposed-to-3-random-targets.125571/