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,579
Reaction score
3,640
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

By far, the weirdest flex I've ever seen on the internet is "I don't have the attention span to read what you wrote, but I REALLY want the world to know I don't have that attention span!".
Why... the FACK... do I work in customer service?!?!
Excuse me while I go question allllll my life choices.
DamageEvil_6.png added!
index.php

Sometimes I wonder why I still try and recruit others to help with my games. It never works.

Forum statistics

Threads
125,777
Messages
1,173,414
Members
164,930
Latest member
alantangyl
Top