MV Yanfly Selection Control help needed

I'm using Yanfly's plugins, the relevant ones here being Selection Control, Row Formation, and Target Core.
My project's battle system has two rows for combatants, a front row and a back row, set up in Row Formation. Each has a state associated with it.

I'm having trouble with the <melee> and <ranged> settings on items and weapons and how that interacts with the rows. I'm essentially trying to copy Etrian Odyssey, in which a party member in the front row with a melee weapon can target enemies on both rows (though back row enemies have a defense bonus), while if you have a melee weapon while in the back row you are only able to target front row enemies. Notably, this is only true for the basic attack action- skills are an entirely separate question. The easiest way to implement this seems to be to basically ignore the whole melee/ranged thing altogether and just restrict the available targets when they're using basic attacks from the second row.

So my question is this- what do i put into the notebox for the basic attack action that would allow this interaction? Basically I want to check if the weapon used is of a certain weapon type. if this is true, and if the actor is in the second row (the rows have unique states to them, so i can just check for the state the second row has attached to it), then i want to limit their potential targets to the first row (and the first row also has a unique state to it so i can also just check for that).

here's the example code off of yanfly's site for the Selection Control plugin
Code:
Skill and Item Notetags:

  <Custom Select Condition>
   if (target.name() === 'Harold') {
     condition = true;
   } else {
     condition = false;
   }
  </Custom Select Condition>
  The 'condition' variable determines if the condition will pass or not. If
  the variable returns 'true', the condition will pass. If the variable is
  'false', the condition will fail and the target will not be a valid target
  for the action. Even if the <Custom Select Condition> notetag passes, all
  other selection conditions must pass, too.

as far as I understand, the above checks if the target is named harold, and if that's true it flags said entity as targetable for whatever skill this tag is placed in.

and here's one of the examples from the target core plugin:

Code:
For users that are proficient with JavaScript, these notetags can be used to
make custom target selections. For the targeting aspect, this will refer to
the skill/item's current scope and the targets made here will be made
independent of the scope with the exception of the target, where if a target
is selected, it will become the 'target' value.

  <Custom Target Eval>
  for (var i = 0; i < foes.aliveMembers().length; ++i) {
    var member = foes.aliveMembers()[i];
    if (member.level % 3 === 0) targets.push(member);
  }
  </Custom Target Eval>
  The 'targets' variable is an array that determines which are the targets
  to be used during the selection process. Push the desired targets into
  the 'targets' array.

and lastly, here's some script calls that the row formation plugin gives

Code:
For those with JavaScript proficiency, you can make use of some of these
newly added functions when you do an eval check for the battler info:

battler.row()
This will return the row the battler is currently resided in.

battler.rowIndex()
This will return the battler's index in relation to the other battlers of
the same team in the same row.

battler.isRowLocked()
This will return a true/false if the battler is row locked.

battler.setRow(x)
This will set the battler's row to x. In battle, this will visually move
the battler there, unless the battler is the active battler.

battler.alterRow(x)
This will alter the battler's row by x. In battle, this will visually move
the battler there, unless the battler is the active battler.

$gameParty.rowSize(x)
$gameTroop.rowSize(x)
This will return the number of members found in that group in row x.

$gameParty.rowAliveSize(x)
$gameTroop.rowAliveSize(x)
This will return the number of alive members found in that group in row x.

$gameParty.rowDeadSize(x)
$gameTroop.rowDeadSize(x)
This will return the number of dead members found in that group in row x.

$gameParty.rowMembers(x)
$gameTroop.rowMembers(x)
This will return each member of the group in row x.

$gameParty.rowAliveMembers(x)
$gameTroop.rowAliveMembers(x)
This will return each alive member of the group in row x.

$gameParty.rowDeadMembers(x)
$gameTroop.rowDeadMembers(x)
This will return each dead member of the group in row x.

$gameParty.updateRows();
$gameTroop.updateRows();
This is a special command. This will check each row in the party. If a row
is empty and/or doesn't have any alive members, all the remaining members
behind that row will move forward one row until all the empty rows are gone.

if I could figure out how to use conditional statements in a skill or state notebox and just use the plugin tags instead of javascript i'd be able to implement this myself, but i dont know how to do that.

I feel like I should be able to just do something like this and post it in the basic attack skill notebox, but it doesnt work.

Code:
<Custom Select Condition>
   if (battler.row() = 2, target.row() = 1, battler.isWtypeEquipped(1,2,3)){
     condition = true;
   } else {
     condition = false;
   }
  </Custom Select Condition>

I wish i knew more javascript, i just have vague memories of a c++ class from a long time ago, so while i understand stuff like booleans and needing to ; the ends of lines i dont know any of the basic javascript function calls and commands. it could also be something as simple as not doubling the == for whatever that does

(oh, maybe the $gameTroop.rowAliveMembers(x) would work here? but that returns a number, not a boolean... i dont know what the standard $prefix script calls are in rpgmaker and its hard to find a reference page)

EDIT: found the script calls reference! I still dont know how to use them properly but its certainly helpful
Code:
   if (battler.row() = 2, target.row() = 1, battler.isWtypeEquipped(1,2,3)){
The syntax on this is just all incorrect. You're assigning values with = instead of checking for them to be equal using ==, you're inserting commas that don't mean anything into the if condition and you're also passing too many arguments into wTypeEquipped(), which won't mean anything (not to mention "battler" is not a valid variable in that notetag).

So, good idea, but no cigar 😉

i dont know what the standard $prefix script calls are in rpgmaker and its hard to find a reference page)
In addition to the script call list which you found, there's also
but that's not going to be a huge help to you unless you do some JavaScript tutorials to get the basics of syntax back into your head.

So this should do what you want, presuming 1, 2, and 3 are your melee weapon types, and all other weapon types can freely target all enemies.
Code:
<Custom Select Condition>
condition=true;

if ([1, 2, 3].some(weapon => user.isWtypeEquipped(weapon)))
    condition=user.row()==1 ? true : target.row()==1;
</Custom Select Condition>

I haven't tested it, let me know if you run into any problems.
The syntax on this is just all incorrect. You're assigning values with = instead of checking for them to be equal using ==, you're inserting commas that don't mean anything into the if condition and you're also passing too many arguments into wTypeEquipped(), which won't mean anything (not to mention "battler" is not a valid variable in that notetag).

So, good idea, but no cigar 😉


In addition to the script call list which you found, there's also
but that's not going to be a huge help to you unless you do some JavaScript tutorials to get the basics of syntax back into your head.

So this should do what you want, presuming 1, 2, and 3 are your melee weapon types, and all other weapon types can freely target all enemies.
Code:
<Custom Select Condition>
condition=true;

if ([1, 2, 3].some(weapon => user.isWtypeEquipped(weapon)))
    condition=user.row()==1 ? true : target.row()==1;
</Custom Select Condition>

I haven't tested it, let me know if you run into any problems.
It works! thanks a ton! Its good to know that even if the syntax was all wrong, at least the idea going into it was sound. I'm gonna try to go review that later.

Now my new, somewhat related issue is this- $gameTroop.updateRows(); checks if a row is empty and if this is the case, it shoves everyone in a row behind that and moves them forward one.

For the party specifically I dont want to use the party side .updateRows(); because in the case of the front line dying and the back line staying alive, I'd want the back line to swap with the front row rather than just move forward. This is so in the case of the party front row dying and then being revived it doesnt overpopulate the front row.

$gameTroop.updateRows(); works perfectly fine for me in terms of enemy functionality, enemies can have as many members in a row as they want

so my current idea- use the Base Troop Events plugin, put a $gameTroop.updateRows(); script call in there, and construct a "in case of player row death" script to also put in there. that way it's just in every fight by default. (ill have to see if i can still put events on specific troops for like boss fights but we'll get to that later. I can just omit Base Troop Events if its inconvenient.)

For the party though, I dont know how to construct the switch row part- if i use $gameParty.updateRows(). itll shove everyone onto the front row, but if i then follow that with a $gameParty.rowDeadMembers() itd result in edge cases where if the back row had a dead member before the front line dies it messes up the swap aspect and just shoves all the corpses into the back row.

Can I get some help making this next bit of javascript so i can put it in a script call?

The Goal is to swap the actors assigned to row 1 and row 2 in the case of row 1's members being dead. I have a party size of 5 and only up to 3 actors should be in a row at a time (but that limit is the result of a workaround that doesnt prevent them from being assigned to a row by other means. like this.)

so

if ($gameParty.rowAliveSize(1) == 0) then it'd check the row 2 actors by using $gameParty.rowMembers(2); and store those IDs. then it checks $gameParty.rowMembers(1), then applies battler.alterRow(+1) to those actors, and then applies battler.alterRow(+-1) to the stored IDs of row 2.

Alternatively,
if ($gameParty.rowAliveSize(1) == 0) then store the members of row 1, then run $gameParty.updateRows(), then take the stored actor IDs and apply battler.alterRow(+1) or battler.setRow(2) to each. (i fear this one wouldnt shove dead backrow members forward but it saves some time compared to the others)

alternatively alternatively
if no alive row 1 members, loop through the actor ids, if battler.row() == 1, then battler.alterRow(+1), else battler.alterRow(+-1) (or use battler.setrow(x))

this wont stop the ability to assign a dead actor into row 1, i think. i wonder if i can put "row 1 must have at least one living actor assigned to it" as a condition in the row menu in the plugin itself because that solves a potential issue too
You could do this in a few ways. For the most seamless approach, I'd use Yanfly's Buffs and States, and put this into your state 1 notes:
Code:
<Custom Apply Effect>
if (user.isActor())
{
    if (user.row()==1 && $gameParty.rowAliveSize(1)==0 && $gameParty.rowAliveSize(2)<0)
    {
        var row1=$gameParty.rowMembers(1);
        var row2=$gameParty.rowMembers(2);

        for (var i=0; i<row1.length; i++)
            row1[i].setRow(2);

        for (i=0; i<row2.length; i++)
            row2[i].setRow(1);
    }
}
</Custom Apply Effect>
You could do this in a few ways. For the most seamless approach, I'd use Yanfly's Buffs and States, and put this into your state 1 notes:
Code:
<Custom Apply Effect>
if (user.isActor())
{
    if (user.row()==1 && $gameParty.rowAliveSize(1)==0 && $gameParty.rowAliveSize(2)<0)
    {
        var row1=$gameParty.rowMembers(1);
        var row2=$gameParty.rowMembers(2);

        for (var i=0; i<row1.length; i++)
            row1[i].setRow(2);

        for (i=0; i<row2.length; i++)
            row2[i].setRow(1);
    }
}
</Custom Apply Effect>
Thanks a ton! You're a lifesaver!

edit: it wasnt working, then i saw that $gameParty.rowAliveSize(2)<0 is a typo, should be $gameParty.rowAliveSize(2)>0 and now it works. thanks for the help!
Gah, sorry about that. Glad it's working for you now.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-selection-control-help-needed.152435/