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,963
Reaction score
4,797
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
786
Reaction score
880
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,963
Reaction score
4,797
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,963
Reaction score
4,797
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,963
Reaction score
4,797
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

That moment when I am listening to another instructor teach and I am thinking…I have been doing this for almost 30 years…I know this material…I teach this material…and you are confusing the crap out of me…let alone the students. What the actual $&@#! are you talking about? :eek:
Help me make a choice. Which one makes more sense?
A. Range style 1.pngDiamond shape
B.Range style 2.png Square shape
I created a skill that can only be used if there are enemies within the player's range. When the player's range is 2, which one do you think is more appropriate to describe the range area?
Just once I would like to see some innocent person stumble upon a body in a crime show and instead of scream they sigh and just say, "Found another one."
Can we get like a RPGM VXA Pro edition with all the limits gone!!
I drew @TheoAllen 's Cecilia~

yVLlTmK.png

Forum statistics

Threads
128,358
Messages
1,193,876
Members
168,852
Latest member
xSeggy
Top