Target Core - Updating Target Array After Death During Random Skill

AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
171
First Language
English
Primarily Uses
N/A
In my game I have a skill that hits 3 random enemies. I noticed sometime after making it that if any enemy dies during the first or second hit of the skill, the now non existent enemy still has a chance of being targeted for the following hits. I'm surprised this happens as I think it defeats part of the purpose of a skill hitting multiple random enemies. The skill should capitalize on an enemy dying early in the skill at the trade-off of the player not knowing who it will hit. This is how I've seen random skills handled in RPGs at least.

What I would like is to make use of the <Custom Target Eval> to have skills that hit multiple random targets update the target array mid skill if an enemy dies. So on a 3 random target skill: if the first hit of the skill kills enemy A, then enemy A won't get targeted for the remainder of the hits. This also means that enemy A could be targeted 3 times if enemy A is alive for the entire skill.

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 = 3;
// 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>

The above code is from Yanfly's chain lightning trick. After an enemy gets hit by a skill with this code, other random enemies can be hit by the skill afterwards by the skill repeating itself on a number of random targets. In the code's case it's 3 other enemies. But the code makes it so that the same enemy can't be targeted twice by the randomness. It's not quite the effect I want, but it's sort of close.

Here's what I want it to do:
1. Create an array with 3 targets, chosen at random.
2. Hit the first target in the array then remove it if it has 0 HP.
3. Hit the next, then remove it if it has 0 HP.
4. Hit the last, remove it.
 
Last edited:

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
811
Reaction score
353
First Language
English
Primarily Uses
N/A
I think if you remove the last member.splice line, it should work fine.
 

AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
171
First Language
English
Primarily Uses
N/A
I think if you remove the last member.splice line, it should work fine.

I think that solved it (or am pretty sure at least, when I set the skill up but removed the member splicing line it's appeared to work consistently).
Thanks for the help Maliki79, I'm giving you a credit in my game for technical support. This problem legitimately rustled my jimmies.

Edit:
Damn, okay well now it's consistently trying to target dead enemies still. But, compared to before I tried your edit suggestion, it doesn't play the skill animation/damage the target (it still seems to count as one of the attacks though). The camera commands in the skill's action sequence still focus on the target whether or not they're alive. SO it's still somewhat of an improvement.
 
Last edited:

Maliki79

Veteran
Veteran
Joined
Mar 13, 2012
Messages
811
Reaction score
353
First Language
English
Primarily Uses
N/A
Ah... I think the reason may be the plugin only evals the targets once. I don't use the plugin so I can't say for sure. I'd have to dl it to see.
Maybe make an extension to do what you need.
 

AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
171
First Language
English
Primarily Uses
N/A
Would you know anyone who'd know how to do it? (or would you?)

Around the time I made this post I asked around in a few RPG Maker Discord servers and no-one seemed to know how to solve it.
 

Latest Threads

Latest Posts

Latest Profile Posts

Snarkyfork wrote on Trihan's profile.
Hey man, I saw you mention that you do MV javascript work? Just wanted to confirm it before I put you on speed dial. =)
"Man is made by his belief. As he believes, so he is."-Krishna
FastFood in my country is neither fast nor cheap like it's expected to be, but people still buy a lot of it. I don't want to imagine how much of it people would eat if it was.
Started finishing up my bosses and characters...I don't know how long...but its going to take long...

Forum statistics

Threads
107,758
Messages
1,031,946
Members
139,901
Latest member
jekken
Top