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,576
Reaction score
11,044
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,228
Reaction score
1,896
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,576
Reaction score
11,044
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,576
Reaction score
11,044
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,576
Reaction score
11,044
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

In twitter, square phoenix had successfully prompted chatgpt to make the mini game watermelon pangpang.

drew some stuff to see how frontview might look. not entirely sold on or off of it yet. "could" work, but something feels missing.
Shower Thoughts: ". . . Scammers would be OP in the Elder Scrolls. They could just get speech 100 and blatantly ask everyone for all of their money, and everyone would think it's a great investment. And then after being robbed blind, they'd say, with a smile on their face, 'need something?' "
Day #2 for advent is compiled. Please, go to their threads to share love! But, if you wanna talk to me…what’s your favorite Christmas carol or holiday song?

Forum statistics

Threads
136,691
Messages
1,268,810
Members
180,403
Latest member
Gremoooroo
Top