MV Target Core/Action Sequence Throwing Enemy into Another Enemy

I'm trying to make a skill that grabs an enemy and based on their weight, either throws them into another random enemy or if they are too heavy or the only member of the troop alive, they are just rammed into.

Spoiler: Custom Target Eval
Code:
<Custom Target Eval>
  if (target.isStateCategoryAffected('Heavy')) {
targets.push(member);
  }
 else
// 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), 0);
// This is the number of extra targets to select with Chain Lightning.
var extraTargets = 1;
// 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>

Spoiler: Action Sequence
Code:
<setup action>
MOVE user: target, front, 20, auto offset x -280,
wait for movement
</setup action>

<whole action>
motion sleep: user
animation 380: user, mirror
wait: 1
animation 443: user, mirror
animation wait: 9
if (target.isStateAffected(151)) || $gameTroop.aliveMembers().length <= 1
 motion swing: user
Eval: StopAnimation(user)
move user: target, back center, 15
wait for movement
action effect: target
jump user: 200, 60
move user: home, 60
wait for movement
    else
  motion sleep: user
animation 388: target
wait: 4
animation 378: target
move user: forward, -50, 10
motion missile: user
move target: point, 400, 400, 20
motion guard: target
wait for movement
animation 377: target
hp -25%: target, show
wait: 20
motion guard: user
animation 379: target
move target: point, 300, 100, 10
wait for movement
move target: point, 600, 100, 60
wait for movement
jump user: 100, 20
motion evade: user
wait for jump
motion skill: user
move target: focus, front, 15
wait for movement
motion standby: user
animation 377: target
animation wait: 3
action effect: targets
motion damage: targets
animation 384: targets
wait for animation
</whole action>

<target action>

</target action>

<follow action>
wait: 30
</follow action>

<finish action>

<finish action>
immortal: target, false
clear battle log
tint screen: 52, 105, 88, 255, 30
remove state 39: user
remove state 37: user
change switch 92: off
battleback 3 remove
tint screen: normal, 60
opacity not focus: 255%, 1
show battle hud
perform finish
wait for movement
</finish action>

I yoinked the Custom Target Eval from Yanfly's Chain Lightning tutorial and added the first few lines myself, so I'm sure I did it wrong since my understanding of javascript is perfunctory at best.

To summarize, the issues I'm having is that I can't get the grabbed target to move to the randomly targeted 2nd enemy and also if a 'Heavy' enemy is selected as the 2nd target, I think that will ruin the action sequence as well. It would probably be a lot easier if action sequences could designate individual targets by 'target1' and 'target2' or something.
An acquaintance of mine made this action sequence for my project,

See if this one work:
<setup action> Display action </setup action> <whole action> move user: enemy 2, front base, 12 wait for movement jump enemy 2: 60, 6 move enemy 2: user, head, 8, offset y +80 motion dying: enemy 2 wait: 30 ---<throw>--- motion attack: user wait: 15 jump enemy 2: 15, 24 motion dying: enemy 2 wait: 8 move enemy 2: target, front base, 8, offset x +100 wait: 8 action animation action effect wait for movement se: bow1 move enemy 2: backward, 100, 12 jump enemy 2: 30, 12 motion dying: enemy 2 wait: 20 face enemy 2: forward wait: 10 face enemy 2: backward wait: 10 face enemy 2: forward wait: 30 </whole action>

You can just edit it to suit your needs
The trick with the action sequence @ANT0NS3DG3 offered is it references enemy 2 the whole time, and there may not be that many enemies in the troop. You might use selection or requirement notetags to make the skill not usable in that case, but it's worth mentioning.

That being said, it might be the easiest way to implement your skill - there isn't any way built into action sequences to reference someone in the list of targets aside from the current one.

Also, it may not matter in this specific case depending on the skill's scope, but it's good practice to use target action when you're doing something with a specific target, not whole action.

Code:
<Custom Target Eval>
  if (target.isStateCategoryAffected('Heavy')) {
targets.push(member);
  }
You're doing this several lines before "member" is even defined, and many lines before it's given any value. So this doesn't mean anything.

You could replace "member" with "target," but it would still break the skill because "target" is already in your targets list.

From reading your description, you don't actually want to do anything special if the target is heavy - you want it to be the only target.

The rest of the code is broken because you tried to modify it but you don't use correct JavaScript syntax. When you have a conditional (if/else/else if), it only applies to the next single statement unless you create a code block with braces.

So you put the "members" variable declaration to only happen if the target isn't heavy, but the rest of it will still attempt to execute but it will all error out because it's using "members" which is undefined.

For your action sequence, this is what I was talking about above with correct usage of whole/target action. When you have more than one target in your target list, it will attempt to do the whole action on every target in the list simultaneously. That is not what you want. You should be using target action.

I suggest that you base the action sequence off of what was suggested above and entirely skip using a custom target eval.

Code:
<setup action>
if target.isStateCategoryAffected("Heavy") || $gameTroop.aliveMembers().length==1
    eval: target.alone=true
    move the user in front of the target
else
    move the user in front of enemy 2
end
</setup action>

For the rest of your action sequence you can do
Code:
if target.alone
to check whether you're dealing with ramming into the one target. In the else branch, you put the commands to deal with throwing enemy 2 into your target.
@ATT_Turan Thank you for the detailed response! And thank you @ANT0NS3DG3 for your help too.

Question though, if there’s 4 enemies, what happens if Enemy 2 is dead? Would 3 and 4 move up and become 2 and 3? Or would the sequence not work because there is no longer an enemy 2, so I’d need to add in other IDs to compensate? Or am I not understanding how these IDs work?
Question though, if there’s 4 enemies, what happens if Enemy 2 is dead?
I haven't actually used that targeting before, so I had to look it up.

By default, it would fail.

In fact, it's even worse because both your action sequence and the one @ANT0NS3DG3 posted can fail since there's no way to verify that enemy 2 isn't the same enemy as your target.

I can't immediately think of a good way to implement this, so I'm going to ponder it a bit.
Yeah, I assumed as much. Maybe there’s a way to pick a second target based on the alive troops and slap a specific state on that one and then use a common event or a troop event to damage whoever has that state once the original target is slammed on to it?

I suppose that wouldn’t solve the issue of moving the original target to the 2nd target’s position in the action sequence though. Might be easier to just send the 1st target to a point position rather than a specific enemy though it might look wonky.
I just made a little plugin that should help.

In the skill notes do:
Code:
<setup action>
if target.isStateCategoryAffected("Heavy") || $gameTroop.aliveMembers().length==1
    eval: target.alone=true
    move the user in front of the target
else
    eval: let group=$gameTroop.aliveMembers().filter(enemy => enemy!=target); group=group[Math.randomInt(group.length)]; BattleManager._targets.push(group)
end
</setup action>

Per the above, you can do if target.alone to see if they're by themself for the ram, and in an else branch you can reference target and targetnum 1 (or targetnum 0 and targetnum 1).

At the end of the target action, do
Code:
eval: BattleManager._targets.splice(1, 1);
to remove the second target so it doesn't try to do all of the target action again on it.

Let me know how all that works.
Wow, this is huge! I’ll have to play around with it some more when I get some time since I probably messed it up, but I did get an error.

Spoiler
index.php

The heavy enemy is rammed as intended, but the smaller enemies cause positioning issues and fly towards the right corner of the screen. I think it may be due to conflict from another plugin, so I’ll look into that.

Spoiler: Video


Here’s the full notebox contents in case the culprit is there.

Spoiler: Notebox
Code:
<Party Limit Cost: 0>
<Custom Cost Display>
3 \I[156]\I[156]\I[156]
</Custom Cost Display>
<Damage Formula>
// Check if the target is Heavy
if (b.isStateCategoryAffected('Heavy')) {
// Damage formula used if the target is a boss.
value = a.atk * 5 - b.def * 2;
} else {
// Damage formula used if two targets involved
value = a.atk * 4 - b.def * 2;
}
</Damage Formula>
 
 
===========================
<Max Mastery Level: 0>
===========================
<setup action>
if target.isStateCategoryAffected("Heavy") || $gameTroop.aliveMembers().length==1
eval: target.alone=true
move the user in front of the target
else
eval: let group=$gameTroop.aliveMembers().filter(enemy => enemy!=target); group=group[Math.randomInt(group.length)]; BattleManager._targets.push(group)
end
MOVE user: target, front, 20, auto offset x -280,
wait for movement
</setup action>
 
<whole action>
 
</whole action>
 
<target action>
motion sleep: user
animation 380: user, mirror
wait: 1
animation 443: user, mirror
animation wait: 9
if target.alone
motion swing: user
Eval: StopAnimation(user)
move user: target, back center, 15
wait for movement
action effect: target
jump user: 200, 60
move user: home, 60
wait for movement
else
motion sleep: user
animation 388: target
wait: 4
animation 378: target
move user: forward, -50, 10
motion missile: user
move target: point, 400, 400, 20
motion guard: target
wait for movement
animation 377: target
hp -25%: target, show
wait: 20
motion guard: user
animation 379: target
move target: point, 300, 100, 10
wait for movement
move target: point, 600, 100, 60
wait for movement
jump user: 100, 20
motion evade: user
wait for jump
motion skill: user
move target: targetnum 1, front, 15
wait for movement
motion standby: user
animation 377: target
animation wait: 3
action effect: target
action effect: targetnum 1
motion damage: target
motion damage: targetnum 1
animation 384: target
animation 384: targetnum 1
wait for animation
eval: BattleManager._targets.splice(1, 1);
</target action>
 
<follow action>
wait: 30
</follow action>
 
<finish action>
 
<finish action>
immortal: target, false
clear battle log
tint screen: 52, 105, 88, 255, 30
remove state 39: user
remove state 37: user
change switch 92: off
battleback 3 remove
tint screen: normal, 60
opacity not focus: 255%, 1
show battle hud
perform finish
wait for movement
</finish action>
You're getting errors because you copied stuff without reading it 😛

When I typed the sentence "move the user in front of the target" and the other instruction in the else branch, those are not Action Sequence commands you can leave in there.

They represent you doing whatever you want to do in those circumstances, via proper Action Sequence commands.

Fix that, try disabling the other plugin you feel is causing a conflict, and let me know if there are still problems.
@ATT_Turan I've experimented quite a bit and I'm stumped. I can get the randomopponent, randomtarget and just plain old target to work, but for some reason everytime I use targetnum 0, or targetnum 1 I get an error.

"TypeError. Targets.forEach is not a function at Window_BattleLog.showNormalAnimation (YEP_CoreEngine.js:2768:19)"

I've turned off the plugins I thought were causing the issue, but it doesn't seem to have helped. I also tried on a blank project with nothing but the Yanfly battlecore, action sequence, target, skill core and your plugin and I still get the same error.

Spoiler: Plugin Order
YEP Core Engine
YEP BattleEngineCore
YEP ActSeq1,2,3
TUR ActSeqTar
YEP TargetCore
YEP SkillCore


I shortened the action sequence to quickly test it.
Spoiler: Notebox
Code:
<Target: Target 1 Random Foes>
<Max Mastery Level: 0>
===========================
<setup action>
if target.isStateCategoryAffected("Heavy") || $gameTroop.aliveMembers().length==1
    eval: target.alone=true
    MOVE user: target, front, 20, auto offset x -280
    WAIT FOR MOVEMENT
else
    eval: let group=$gameTroop.aliveMembers().filter(enemy => enemy!=target); group=group[Math.randomInt(group.length)]; BattleManager._targets.push(group)
end
</setup action>

<whole action>

</whole action>

<target action>
  animation 37: target
WAIT FOR ANIMATION
animation 36: targetnum 1
WAIT FOR ANIMATION
  eval: BattleManager._targets.splice(1, 1);
</target action>

<follow action>
wait: 30
</follow action>

<finish action>

<finish action>
immortal: target, false
clear battle log
tint screen: 52, 105, 88, 255, 30
remove state 39: user
remove state 37: user
change switch 92: off
battleback 3 remove
tint screen: normal, 60
opacity not focus: 255%, 1
show battle hud
perform finish
wait for movement
</finish action>
I think I made an error with how I was returning the targets. I uploaded version 1.1 in the plugin thread, please download that and try it out.
That fixed it, targetnum now works as intended! Thank you for the plugin, you're amazing and I'm definitely putting a sage NPC or something named "Turan" lol.

Only issue now is that occasionally a single enemy ends up being targeted for the grab and also for the throw position, so they just hit themselves in midair, but that shouldn't be too hard to fix. I'm not sure if that's a quirk of the plugin or just the syntax within the action sequence (or even the target core <Target: Target 1 Random Foes> notetag?) though.

EDIT: I got it. In case someone googles this later on and finds this thread, I used the Chain Lightning custom target settings instead of <Target: Target 1 Random Foes> which includes the original target in the random selection as well as the other alive troops, leading to repeats being possible.

Spoiler: Notetag
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 Magnetar
var extraTargets = 1;
// 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>
You shouldn't need any targeting eval with the code I gave you. That's what the eval in the else branch does, add a second target who is not the original.

But if you got it working, awesome.

Original thread: https://forums.rpgmakerweb.com/threads/target-core-action-sequence-throwing-enemy-into-another-enemy.159404/