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

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
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>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,947
Reaction score
4,789
First Language
English
Primarily Uses
RMMV
Code:
targets=$gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))];
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
784
Reaction score
878
First Language
English
Primarily Uses
RMMZ
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>
 
Last edited:

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,947
Reaction score
4,789
First Language
English
Primarily Uses
RMMV
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
 

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
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.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,947
Reaction score
4,789
First Language
English
Primarily Uses
RMMV
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.
 

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,947
Reaction score
4,789
First Language
English
Primarily Uses
RMMV
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.
 

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
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.
 

Latest Threads

Latest Profile Posts

Upgrading from VX Ace to MV has gone from a cute suggestion to outright required.

Things can only go up from here - I kinda hated being constrained to 640x480 resolution. :LZSwink:
Now that I have linklists on large trees and cars, is there any theme that would interest you?
Debugging multiplayer issues... I'm having fun, right?
yay_streaming.jpg

For just starting streaming on the 10th... Definitely not the worst. :LZScheeze:

Granted I need 333.34 hours a month on average to achieve money. So I don't really expect that, but it sure has helped my game dev go much faster.
Proud on how this map turned out.

FnmhDLIXgAAOvIC

Forum statistics

Threads
128,332
Messages
1,193,684
Members
168,817
Latest member
Clust3rPepis
Top