JS Battle Core - Make skills target certain enemies/allies but not others.

Sup all. I need some help to get this battle-core note-tag working to only make the skill target ONE troop randomly between troops 1-4. I want the skill to ignore troop numbers 5-8. Anybody have an idea how to do this? Thanks.

<JS Targets>
code
code
targets = [?];
</JS Targets>
Code:
targets=$gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))];
Code:
targets=$gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))];
I don't think that'll work right, since it looks like targets is expected to be an array. Maybe something like this:

Code:
<JS Targets>
  const randomNum = Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length));
  targets = $gameTroop.aliveMembers().filter((member, index) => index == randomNum);
</JS Targets>

or

Code:
<JS Targets>
  targets = Array($gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))]);
</JS Targets>
I agree, I don't think this has anything to do inherently with the Battle Core or your resolution, I think it has to do with your custom image or animation.

If you can't figure it out based on that, try posting the relevant images.

Code:
targets=$gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))];

I don't think that'll work right, since it looks like targets is expected to be an array. Maybe something like this:

Code:
<JS Targets>
  const randomNum = Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length));
  targets = $gameTroop.aliveMembers().filter((member, index) => index == randomNum);
</JS Targets>

or

Code:
<JS Targets>
  targets = Array($gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))]);
</JS Targets>


Thank you both for your help. The only thing that worked (sort of) is this:

Code:
<JS Targets>

  targets = Array($gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))]);

</JS Targets>

The problem begins when the 1-4 enemies start to die. 5-8 starts getting targeted at that point. Is there a way to make it 1-4 only even if they are dead and never 5-8? Consider it like an attack that only hits the back row of enemies which in this case is 1-4.
I don't think that'll work right, since it looks like targets is expected to be an array.
Thanks, I didn't notice that.

The problem begins when the 1-4 enemies start to die. 5-8 starts getting targeted at that point. Is there a way to make it 1-4 only even if they are dead and never 5-8? Consider it like an attack that only hits the back row of enemies which in this case is 1-4.
Change all instances of aliveMembers to just members
Thanks, I didn't notice that.


Change all instances of aliveMembers to just members
New problem. The skill now targets dead enemies on 1-4 but never 5-8. How can we make it where it only targets living enemies on the 1-4 list and never 5-8?


Code:
EDIT:

<JS Targets>

  targets = Array($gameTroop.members()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))]);

</JS Targets>

This above seems to do the trick but sometimes the dead enemy will be attacked. It does seem to target the living enemies way more though.
New problem. The skill now targets dead enemies on 1-4 but never 5-8. How can we make it where it only targets living enemies on the 1-4 list and never 5-8?
Code:
<JS Targets>
randIndex=Math.randomInt(Math.min(4, $gameTroop.members().length));
if (!$gameTroop.members()[randIndex].isDead())
  targets.push($gameTroop.members()[randIndex]);
</JS Targets>

For what it's worth, you might look at a better/more integrated way to handle your rows. I think the Yanfly Row Formation plugin is compatible with FOSSIL, it would then make stuff like this much more streamlined because you'd just target row 1.
Code:
<JS Targets>
randIndex=Math.randomInt(Math.min(4, $gameTroop.members().length));
if (!$gameTroop.members()[randIndex].isDead())
  targets.push($gameTroop.members()[randIndex]);
</JS Targets>

For what it's worth, you might look at a better/more integrated way to handle your rows. I think the Yanfly Row Formation plugin is compatible with FOSSIL, it would then make stuff like this much more streamlined because you'd just target row 1.
The script above does not work. It hits multiple targets on both 1-4 and 5-8. Yeah, I have Fossil. I could try it if this doesn't work out. I'm not sure why the MZ plugins from VS don't have row support added into the Battlecore. They only have a few options for scope/targeting notetags.
The script above does not work. It hits multiple targets on both 1-4 and 5-8.
Oh, you probably have your skill's scope set to All Targets to start with. Try just adding this line...

Code:
<JS Targets>
targets=[];

randIndex=Math.randomInt(Math.min(4, $gameTroop.members().length));
if (!$gameTroop.members()[randIndex].isDead())
  targets.push($gameTroop.members()[randIndex]);
</JS Targets>

I get confused because, as I recall, the Yanfly version starts with an empty target list whereas this starts with the target list you specified in the skill's scope.
Oh, you probably have your skill's scope set to All Targets to start with. Try just adding this line...

Code:
<JS Targets>
targets=[];

randIndex=Math.randomInt(Math.min(4, $gameTroop.members().length));
if (!$gameTroop.members()[randIndex].isDead())
  targets.push($gameTroop.members()[randIndex]);
</JS Targets>

I get confused because, as I recall, the Yanfly version starts with an empty target list whereas this starts with the target list you specified in the skill's scope.
This works perfectly from my testing so far. I'll include both you and Arthran into the credits of my commercial project coming. Thank you very much for your help.

Original thread: https://forums.rpgmakerweb.com/threads/js-battle-core-make-skills-target-certain-enemies-allies-but-not-others.150786/