RMMV YEP Target Core: Targeting 3 different foes once if possible

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
391
Reaction score
178
First Language
English
I've been doing a bit of searching and I don't think I've found a method to achieve exactly what I want, I can just get pretty close.

I want to use a YEP Target Core <Custom Target Eval> to achieve the following in a skill:

Strike three times, at different targets if possible.

So, some use cases:

- If >= 3 Troop members are alive, target up to three to hit ONCE each.

- If 3 Troop members are alive, hit all three ONCE each.

- If 2 Troop members are alive, hit two ONCE each, and then select one of them as a random target for the third hit.

- If 1 Troop member is alive, this target receives all three hits.

The closest I can get to this, is a little script from Yanfly for Chain Lightning:


Code:
<Custom Target Eval>
// Adds the selected target to the target list.
targets.push(target);
// Grab the group of alive foes as candidates.
var members = foes.aliveMembers();
// Remove the target from the group of candidates.
members.splice(members.indexOf(target), 1);
// This is the number of extra targets to select with Chain Lightning.
var extraTargets = 2;
// Loop the extra targets.
while (extraTargets--) {
  // Grab a random foe from the alive foes.
  var member = members[Math.floor(Math.random() * members.length)];
  // Check to see if the member exists.
  if (member) {
    // Add the member to the group of targets.
    targets.push(member);
    // Remove the member as a viable candidate.
    members.splice(members.indexOf(member), 1);
  }
}
</Custom Target Eval>

^ This one will hit up to 2 other targets, but will not hit the same target more than once if there are less than three targets.

Just to reiterate - I need the skill to hit different targets if it can, but if it cannot, it will strike a previous target (chosen at random) until it has completed 3 hits.

Thanks!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,601
Reaction score
3,663
First Language
English
Primarily Uses
RMMV
Strike three times, at different targets if possible.
Code:
<Custom Target Eval>
// I presume your initial selection scope is All Enemies, so empty that out
targets=[];

while (targets.length<3)
{
// Get a random enemy
    var newTarget=$gameTroop.aliveMembers()[Math.randomInt($gameTroop.aliveMembers().length)];

// The enemy is not already chosen, or you've already chosen each enemy once
    if (!targets.includes(newTarget) || $gameTroop.aliveMembers().length<=targets.length)
        targets.push(newTarget);
}
</Custom Target Eval>
 

Latest Threads

Latest Posts

Latest Profile Posts

New sprites & animations for Mint and Beri are coming along!
Guh-Colorbound.gif
ScreenShot_10_5_2022_4_44_8.png
Mad O' Malley... a stick figure that's afraid of it's existence being erased. so they always start battle in an anxious state.
Before, I was drawing all the sprite work, super big and shrinking it down. Which was really time consuming if thing's changed. So instead I'm drawing the characters sketch, and then remaking it with pixel art instead.
Why are job interviews so terrifying. :kaodes:

Forum statistics

Threads
125,801
Messages
1,173,666
Members
164,964
Latest member
oliveleaf
Top