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
Regular
Joined
Jul 2, 2014
Messages
12,742
Reaction score
11,348
First Language
English
Primarily Uses
RMMV
Code:
targets=$gameTroop.aliveMembers()[Math.randomInt(Math.min(4, $gameTroop.aliveMembers().length))];
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,249
Reaction score
1,941
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
Regular
Joined
Jul 2, 2014
Messages
12,742
Reaction score
11,348
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
Regular
Joined
Jul 2, 2014
Messages
12,742
Reaction score
11,348
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
Regular
Joined
Jul 2, 2014
Messages
12,742
Reaction score
11,348
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 Posts

Latest Profile Posts

Christmas decorations! !! :kaojoy:
20231209_114754.jpg
Sophie is already helping dismantle the tree...a month early, of course. Such a helpful kitten!
making horse character for game :D at the end it will have 8 directions puling wagon

2p8jdax
I'm back after a short hiatus (0-0), after playing another eden i think i've understood the fundamentals of world building a lil' bit more so ima use that for crimson evan, (btw working on a trailer teehee)
image.png

I think this is good progress.

Forum statistics

Threads
136,876
Messages
1,270,938
Members
180,642
Latest member
ricierich
Top