MV Yanfly's Row Formation question about troops swapping positions.

Is it possible to make a Troop swap positions?

Let's say I have 4 enemies each in their own row:

4 3 2 1 (this is the starting order)

I then want to move the enemy in row 1 to row 2 but since there's an enemy already in row 2 then they swap places:

4 3 1 2 (this would be the new order)

Is this possible or am I starting to push up against the limits of what this plugin can do?

Thanks for the help, and have a great day!
You can use a Script command:
Code:
let orig1=$gameTroop.rowMembers(1);
$gameTroop.rowMembers(2).forEach(enemy => enemy.setRow(1));
orig1.forEach(enemy => enemy.setRow(2));

I know your example only has one enemy per row, but I wrote it to be compatible with multiple enemies in case anyone else comes across it.
You can use a Script command:
Code:
let orig1=$gameTroop.rowMembers(1);
$gameTroop.rowMembers(2).forEach(enemy => enemy.setRow(1));
orig1.forEach(enemy => enemy.setRow(2));

I know your example only has one enemy per row, but I wrote it to be compatible with multiple enemies in case anyone else comes across it.

This worked really well! Thank you so much!

What I did was I used your code to make a Common Event and added your code as a Script. I then created Skill called "PUSH" that called on that Common Event so when the player chooses the Skill "PUSH" it pushes the enemy out of Row 1 and swaps them with the enemy that was in Row 2.

Thinking ahead, I could create a number of Skills that each have different effects, say like pushing the enemy in Row 2 into Row 3, or from Row 3 into Row 4. Or it could go the other way with a skill called PULL which just does the opposite.

But would it be possible for the code to account for multiple positions like this?

For example, if on round one the player chooses to swap the enemies in Rows 1 and 2 (which already works with your code solution), but then on the next round they want to swap the enemies in Row 3 and 4 or Row 2 and 3?

Would that involve something like multiple let statements that assigns each enemy to their row so it can keep track of who was moved around:

let orig1=$gameTroop.rowMembers(1); let orig2=$gameTroop.rowMembers(2); let orig3=$gameTroop.rowMembers(3); let orig4=$gameTroop.rowMembers(4);

and then creating a check to see who is in a new position and then moving the orig(x) enemy to the now vacant spot?

I'm very new to coding so excuse me if I'm way off track.

And sorry if this is asking too much of you, you've already been a huge help and I really appreciate you taking the time to help me get this far. I was just surprised my original idea was even possible but then you solved the issue and I started thinking how this solution might be expanded.

EDIT:

By the way I got your code as it's currently working to work on allies to.

What I did was I created a new Common Event called PUSH 2 and added this code as a Script:

let orig1=$gameParty.rowMembers(1); $gameParty.rowMembers(2).forEach(user => user.setRow(1)); orig1.forEach(user => user.setRow(2));

I then created a Skill called PUSH 2 (I already had PUSH from your example that works on enemies), changed the scope to 1 Ally, and called on the new Common Event called PUSH 2.

And then in combat the player can swap the ally in Row 1 with Row 2.

I just thought it was neat I could do this with both a Party and a Troop and if anyone wants to refer to this later I hope maybe this could help them.
But would it be possible for the code to account for multiple positions like this?

For example, if on round one the player chooses to swap the enemies in Rows 1 and 2 (which already works with your code solution), but then on the next round they want to swap the enemies in Row 3 and 4 or Row 2 and 3?

Would that involve something like multiple let statements that assigns each enemy to their row so it can keep track of who was moved around:

let orig1=$gameTroop.rowMembers(1); let orig2=$gameTroop.rowMembers(2); let orig3=$gameTroop.rowMembers(3); let orig4=$gameTroop.rowMembers(4);

and then creating a check to see who is in a new position and then moving the orig(x) enemy to the now vacant spot?
I don't see why you would need to make all those variables if you're only changing two rows at a time.

Why would you care if an enemy started, say, the entire battle in row 1? You only care where they are at the start of resolving this effect.

You can use the three lines of code I wrote above to swap any two rows, just plug in the appropriate numbers.

By the way I got your code as it's currently working to work on allies to.
For actors you may want to use rowAliveMembers(). It could be weird to the player to see corpses sliding around.

But if you're okay with that so long as you preserve the one battler per row part, then that's cool.
I don't see why you would need to make all those variables if you're only changing two rows at a time.

Why would you care if an enemy started, say, the entire battle in row 1? You only care where they are at the start of resolving this effect.

You can use the three lines of code I wrote above to swap any two rows, just plug in the appropriate numbers.

I see what you're saying. I can just create a new skill with the appropriate numbers to switch who I want to switch!

As it is right now your code works really well if (for example) an enemy does an attack that does some X amount of damage as well as moves whoever is in row 2 to row 4 (for example). And this way I'd have control over what the enemy is doing in each case by just plugging in the appropriate numbers to your code like you suggested!

I think the only downside is that it makes it hard for the player to easily recover from being moved to a different row. If a user is moved from their preferred row then that user would have to have access to a skill that could get them back to their preferred row and I feel like it would be cumbersome to give every character access to a list of skills that can move them from any row to any row (I think it's 12 possible combinations for a 4 row setup?)

Would it be possible then to sort of do what Darkest Dungeon did and then give users (and troops) access to a skill which can allow them to swap positions with either the row in front or the row behind them?

For example, in your solution a party (or troop) is moved from (for example) row 1 to row 3. The party (or troop) that now finds itself in row 3 wants to get back to row 1 (and vice versa) so they can use their abilities which are dependent on being in their preferred row. As it is now they'd have to select from a list of skills that offer multiple move options which feels cumbersome for the player.

Would it then be possible to create a skill that allows the party (or troop) to swap places forward (or backward if that was the case) with 1 row? That would mean each character only has access to two skills they have control over, one called something like "Move Forward 1" and another called "Move Backward 1", sort of like how Darkest Dungeon handled this sort of row mechanic where to get back to the preferred row means having to swap places a few times to get back to the preferred row?

And since this could work with parties and troops it then becomes a mechanic where both the player and the AI is trying to use positioning as a key element of combat?

I remember reading Yanfly's wiki about why they didn't port over the Row Formation plugin to MZ. Yanfly said it was because so few projects actually used Row Formation for little more than as a background mechanic. But I'd love to be able to use the Row Formation plugin to really make it a risk / reward system where positioning is integral to the combat, it's just as a total noob I have no idea how to really go about coding it to allow for what my imagination is cooking up.

I do really appreciate your help so far and I apologize if I'm asking for more than is appropriate to ask. I have already learned a ton just from the code you have created and I'm really grateful for your time. I've even bookmarked your code from your thread of code snippets to help me learn more.

Have a great day!
I'm also doing a row formation battle system and have been asking some of the same questions as you.

As for the skills that move you around I have taken the approach of using Yanflys instant skill plugin. Another plugin he says no one uses and won't be porting. :LZYcheeze:That way you can move once(or more) a turn without using your turn. Also some skills move and attack in the same skill like you already are doing. Some skills can move you multiple rows with some other downside. I use a state "already moved" that seals my movement skills to limed uses in a turn. I think this makes the biggest problem with row formations a lot better. Yanfly really is 100% correct in his reasons to not port these plugins over BUT I think we can overcome those reasons. I too have the same dream of making rows not only work but be a integral part of the battle system and above all be something new and FUN.

The plugin commands are pretty powerful. My problem is it got real messy for enemies who are using the same skills as actors so I am making my own plugin now. I think you could do a lot with action seq packs but I am having trouble with even the basics with that.
Here is how I do moment skills.
Two skills:
Move up:
<Row Only: 2, 3, 4>
<Instant Cast>
<Pull Forward User Row: 1>
Add State Moved this Turn 100% which seals movement skill
I also added a momentum state with attack buff for a turn
add maybe a common event to do more work if you want

Move Back:
<Row Only: 1, 2, 3>
<Instant Cast>
<Push Back User Row: 1>
For enemies you can use Yanflys AI plugins or just use state triggers in the enemy editor. If archer has row 1 state, use move back skill. Simple.

You can even use movement skills on the entire party or troop but exclude
who ever you want with target or select conditions. More Yanfly plugins. And really you can use skill cool downs instead of states to limit them.

What type of turn order "battle system" thingy are you using? Default didn't work for me because how can you make a decision when people are still moving rows? I went to Yanflys STB which presents a few other problems but really seems the way to go.

Like you, I too have fears of the movements command being too cumbersome but deiced to make everyone have them anyway. I'm just trying to make it interesting by having more commands! We got a charge skill that knocks back the enemy and moves you up. Also have some that move you 2-3 rows but either take your entire turn or debuff some stats. I also have flaking movements where you move to the rear then "leave" the battle only to return in the front line attacking. Kinda like the classic "ff jump" skill but tailored for rows.
Now lets sayyou have an actor in your first row but then enemy is all sitting in row 3,4. I think its dumb to let them sit back there getting row 3 buffs so I made a skill(that the enemy also uses) to move into their front line making their second line the new front line. Following me? In game terms it means moving all allies back and all enemies forward except the user. Its to simulate running down the enemy who may not want be near you. Also to run from battle you need to get to the rear row and use another movement skill "escape". This means no running unless you are faster or put someone in the front line to die while you run.
"Move up the line" is three skills from one command. First skill:
scope none
<Row Only: 1>
<Instant>
add moved state
call common event to run two other skills

Skill Move Actors:
scope all allies(not needed?)
<Push Back Target Row: 1>
<Target: All Allies But User>

Skill Move Enemies:
scope all enemies
<Pull Forward Target Row:1>

You will also need a check in the common event to make sure the enemy front row is empty. if $gameParty.rowAliveSize(1) > 0 say no to the player then take away moved state to prevent losing turn.

The only problem with this is it takes too long and looks dumb the way they move so I just used the alterRow(x) function from Yanflys row plugin in my own plugin. It at least solve the problem of everyone moving one at a time which was a big problem for me due to having a lot of battlers. I can post the plugin in a new thread if you want but its very specific to my needs and not coded in the best of ways.
I also understand why Yanfly stopped supporting the plugin: if nobody is using it then why continue with it. But I think Yanfly didn't ask hard enough *why* it wasn't being used.

I think I can answer the why - it's because the plugin doesn't take into account movement options. Yes you can push or pull troops / party members, but not individual members of the row. If there are two or more troops or party members in a row that's being pushed or pulled then everyone in the row gets pushed or pulled until the every single character in a troop or party winds up in the same row. It's the plugins biggest failing and when people realize how limiting the options are for the plugin I think people just give up on really exploring all it's other fantastic potential that it does have.

What type of turn order "battle system" thingy are you using?

I'm not trying to do anything too off the beaten path. I'm really new and though I do have quite a lot already figured out, I was saving the battle system for last once I knew what the rest of my game was going to look like.

And so I'm basically sticking pretty close to many of the out of the box features of RPG MV as far as JRPG skills go. It's just I wanted to use rows to allow players to have fun with positioning and having characters in rows that allow them to use skills / items while locking them out in other rows. I'm also sicking to movement does consume a turn since that's in keeping with the broader theme of my game where movement is very important.

And I feel like I'm SOOOOO close to a solution. @ATT_Turan solved a huge issue for me in finding a way to basically keep from having more than 1 troop / party member per row. It's just that now I am hoping to solve how to move a troop / party member just 1 row forward or backwards.

So let's say, for example the fight starts off looking like this:

troops party
4 3 2 1 1 2 3 4

In rows 4 are the healers, in rows 2 are the ranged DPS, in rows 2 are the rogues, and row 1 are the tanks.

On round 1 the troops force my tank back into row 4 where they can no longer use their melee attack on the troops. @ATT_Turan totally solved this issue for me with the script he wrote above.

However, now that the battle looks like this:

4 3 2 1 4 2 3 1

I can either have the player scroll through a list of all possible movement skills (12 total to account for every possible combination that 4 players can be moved) until they find the one that says "Swap rows 4 to 1" or, what I was hoping for, was the have a skill that allows for the player to just swap their party member with the row in front of them. And by limiting the player to just be able to move 1 row at a time then that really changes the dynamic of battle because that means the AI also can only move 1 row at a time which sets up some nice strategy for the player to take advantage of out of position troops.

So if I can find a way to also have a skill (or 2 skills), one that swaps position with the row in front and another with the row in back, then my battle system is pretty much solved as far as the main movement / row mechanic is concerned.

I can post the plugin in a new thread if you want but its very specific to my needs and not coded in the best of ways.

I'd LOVE to take a look at what you've come up with so far. If I can use some of what you've solved maybe I can add on to it and help you as well?
Yea, he kinda made the Row plugin work really well if want exactly how row systems have always worked in RPGs in the past. Meaning they don't really add anything to the game but a one time set and forget thing. Rows in FF7 were pointless and never talked about.
Yes you can push or pull troops / party members, but not individual members of the row.
What do you mean? You can target who ever to push or pull how ever many rows. Yanfly target and select plugins do the job for me. The notetags are very powerful for this.

I am also trying to stick to default as much as possible because working on the battle system is hard enough alone but I don't see how it can work with everyone choosing skills at the same time. I guess the way you are doing it ypu may want to make movement a party command and not for the actors.

So to be clear you in your game there can only be one battler per row right?

Easy dirty way is to make a "move up" skill that moves the target back as well as the user forward. Just make it target the guy next to you automatically so the player never sees that part.
In the skill notetag push user forward and use the target plugin to target the guy in your row +1 then pull back target plugin command. All can be done in same skill for sanity sake.

Same for if you wanted to "swap rows". My row + x = target. You could then notetags to make the non relevant skills not show up in the command list until they are usable.

Be careful though with only moving one per turn. It might slow the game play down. 3 turns to move from rear to front is a lot. Thats why I'm allowing more movent per turn but also adding debuffs to them for balance.

I'll post the plugin in the development section a bit later but will dm you or something when I do.
I think the only downside is that it makes it hard for the player to easily recover from being moved to a different row. If a user is moved from their preferred row then that user would have to have access to a skill that could get them back to their preferred row and I feel like it would be cumbersome to give every character access to a list of skills that can move them from any row to any row (I think it's 12 possible combinations for a 4 row setup?)

Would it be possible then to sort of do what Darkest Dungeon did and then give users (and troops) access to a skill which can allow them to swap positions with either the row in front or the row behind them?
Yes. You know all of the commands I'm referencing are in the plugin documentation, right? In the "Script Calls" section.

So instead of referencing specific row numbers, you just use the commands listed there to retrieve whatever the current information is. For example:
Code:
// Push back
let origOther=$gameParty.rowMembers(user.row()+1);
$gameParty.rowMembers(user.row()).forEach(actor => actor.setRow(actor.row()+1));
origOther.forEach(actor => actor.setRow(actor.row()-1));

You would have to use that in a notetag from the Skill Core or something. If you just use a common event, that has no reference to what the actor who used the skill is.

I also understand why Yanfly stopped supporting the plugin
What do you mean? As far as I understand, none of the Yanfly plugins are supported anymore (I and others have filed numerous bug reports and requests and never gotten a response).

But while the Yanfly Engine was being developed, I don't see anything about the Row Formations plugin being unsupported individually. Only the alternate battle systems were.
What do you mean? As far as I understand, none of the Yanfly plugins are supported anymore (I and others have filed numerous bug reports and requests and never gotten a response).

But while the Yanfly Engine was being developed, I don't see anything about the Row Formations plugin being unsupported individually. Only the alternate battle systems were.
We were talking about how a few plugins are never getting ported to MZ with VisuStella. There is a post on Yanflys site about it and why. Hence the whole reason we are both on MV and will never be able to move to MZ with row formations.
We were talking about how a few plugins are never getting ported to MZ with VisuStella.
I saw that, but I wouldn't call getting ported to a different engine the same thing as "being supported" - many of the VisuStella plugins are very functionally different from their Yanfly corollaries.

But I guess I was overly focused on the terminology - if you both understand each other, it doesn't matter if I do 😉

Hence the whole reason we are both on MV and will never be able to move to MZ with row formations.
I mean, it's on the compatibility list for Project FOSSIL. Have you tried it?
I saw that, but I wouldn't call getting ported to a different engine the same thing as "being supported" - many of the VisuStella plugins are very functionally different from their Yanfly corollaries.

But I guess I was overly focused on the terminology - if you both understand each other, it doesn't matter if I do 😉


I mean, it's on the compatibility list for Project FOSSIL. Have you tried it?
I'm glad you get your terminology correct, it's kinda a big problem with RPG maker or at least was for me. Now I hope he DID mean ported and now supported lol.

I have not tried FOSSIL, didn't think you could or would be worth it to try to use half the Yanfly collection on MZ lol. Or what, get it working with obfuscated Visu plugins?
I have not tried FOSSIL, didn't think you could or would be worth it to try to use half the Yanfly collection on MZ lol. Or what, get it working with obfuscated Visu plugins?
I'm not super educated on it, you can go read through the plugin thread and description and such. But my understanding is it provides internal conversions for plugins referencing variables and functions that changed in MZ.

So if something is compatible with FOSSIL, I believe it should just work. Then it would interact with other plugins exactly the same way plugins always do, if you have things trying to overwrite the same functions they can conflict with each other.

If you use a Yanfly plugin in FOSSIL that has a prerequisite, you should use that prerequisite Yanfly plugin and not include a similar VisuStella plugin at the same time. But it's all there for you to test.
So instead of referencing specific row numbers, you just use the commands listed there to retrieve whatever the current information is. For example:
Code:
// Push back
let origOther=$gameParty.rowMembers(user.row()+1);
$gameParty.rowMembers(user.row()).forEach(actor => actor.setRow(actor.row()+1));
origOther.forEach(actor => actor.setRow(actor.row()-1));

You would have to use that in a notetag from the Skill Core or something. If you just use a common event, that has no reference to what the actor who used the skill is.
Yes, that worked PERFECT!

I placed the code between <Custom Target Row>your code</Custom Target Row> tags in the skill and it ran perfectly. I can't thank you enough for your help, you are so incredibly helpful!

I'm still a total beginner learning coding / Javascript (I'm still pretty much at the "Hello World" stage of coding) - I've never done anything like this before so for me it's like not knowing how to read while also trying to use the Dewey Decimal system at the library. But just seeing examples and then playing with the code has taught me so much, and I'm super grateful for your patience and help.
So to be clear you in your game there can only be one battler per row right?

Easy dirty way is to make a "move up" skill that moves the target back as well as the user forward. Just make it target the guy next to you automatically so the player never sees that part.
In the skill notetag push user forward and use the target plugin to target the guy in your row +1 then pull back target plugin command. All can be done in same skill for sanity sake.

See I didn't realize I could just use math. As someone who has an English degree I never think to use math lol. In hindsight what you're saying makes total perfect sense and seeing how @ATT_Turan solved the issue in his code further enforces the point that I'm really, really bad at math.

Be careful though with only moving one per turn. It might slow the game play down. 3 turns to move from rear to front is a lot. Thats why I'm allowing more movent per turn but also adding debuffs to them for balance.

And yes, I'm trying to keep 1 battler per row. But I also understand what you're saying about not slowing battle down too much. My solution to this was to allow for there to be some overlap between how the rows can be used.

For example if a character is using a melee weapon, like an axe for example, that axe works best in the front 2 rows, not just the front row. That way the player doesn't necessarily have to spend all their turns just moving around, they can get into a "good enough" spot where they can still do damage but maybe that other row also slightly limits their damage output.

And this applies to enemies as well, so the enemy might also get out of position and then the player can take advantage of that and take the enemy out, even if they're not in an optimal row.

But the overall game I've designed plays similar to the combat where forward / backward movement is very important and so the combat system is an extension of what the regular game play is like.

Yea, he kinda made the Row plugin work really well if want exactly how row systems have always worked in RPGs in the past. Meaning they don't really add anything to the game but a one time set and forget thing. Rows in FF7 were pointless and never talked about.

That's a good point. I was thinking of rows as how Darkest Dungeon uses them in which rows are integral to the battle system where every fight is a dance where the player and the AI are trying to get an advantage over each other by getting the other out of position. BUt you're right that the old school way of doing it was really just a "set it and forget it" type of thing where the people in the back took less melee damage and the people in the front dealt more melee damage (or something like that).

So I guess I understand now why Yanfly did it that way like the old school style.

I'll post the plugin in the development section a bit later but will dm you or something when I do.

Sounds good! I look forward to working with you more. Hopefully we can help each other out with our projects.
Ahh ok I checked out that game on steam and it makes more sense why to do it that way. Yea that should be pretty easy to do since its already done now lol
I don't think that will be slow with the movement now since there is always 4 ppl in 4 rows and like you say have other ways to keep it going.

Funny you talk about math because I think game dev has more math in it than other industries. I ask my buddy who works for a bank transaction processing company as a programmer who also does a lot of JS stuff about game dev and he just shrugs and tells me he doesn't use much math in his job so he never learned it and pretty much can't help me with anything like that. It took me weeks to figure out how to just make an equation that would organize any amount of battlers visually into the rows. Yanflys solution simply doesn't work but isn't really noticeable until you have more battlers. For reference here is the solution you can input in the plugin manager:
x = (maxRowX - (4 - rowId) * 112 + rowIndex * 32) - ($gameParty.rowSize(rowId) * 16)
y = centerY + ((rowSize / -2 + 0.5) + rowIndex) * 32

If you ever need THAT, there ya go haha. But you won't need it because your idea is much simpler than mine to implement which is great.

Yes, that worked PERFECT!

I placed the code between <Custom Target Row>your code</Custom Target Row> tags in the skill and it ran perfectly. I can't thank you enough for your help, you are so incredibly helpful!
Yea @ATT_Turan has the best way. I have been messing with plugin commands and notetags for so long I forget just some simple script is a lot easier. I even forgot about <Custom Target Row> which I could have used!
Sounds good! I look forward to working with you more. Hopefully we can help each other out with our projects.
I'm all for it but I think what we are doing is very different. That being said I'm already using ideas from @ATT_Turan ! Gonna have to make this guy a saint in my game and not just for this thread. Just because I said I was making a plugin doesn't mean I can code lol Actually there is nothing there you would need, it just did what Turan just did with 3 lines of code instead of 25 so yea don't wanna post it now! Still got no problem showing you other stuff I have.
Not sure if this is going to be of use or interest to anyone, but I solved kind of a neat problem regarding rows.

I wanted it so that if an enemy in a row was killed it would push all the other rows forward automatically. So I used the code @ATT_Turan already provided for me in their first reply to my query and came up with this little bit of code:

<Custom Row Condition> if ($gameTroop.rowAliveMembers(1) == 0) { $gameTroop.rowMembers(2).forEach(enemy => enemy.setRow(1)); } else { } </Custom Row Condition>

I then made slight changes to the code to reflect which row I was applying this row condition to and sure enough killing an enemy in any row that isn't the back row will push all the rows forward.

The only issue I have is that the game treats whoever enters their new row as if they were a second index(?) in the row and so there's a weird offest where it places the enemy in a slightly different position that what was originally there. I'm not sure how to tell the game to reset the index position of the enemy to make everyone stay in a nice little line, but I'll take my win where I can get one.

Still, 99.99% of the credit goes to @ATT_Turan for giving me most of the code already, but they've given me a good place to start learning from! So thank you, @ATT_Turan

Now if I could only figure how how to limit the number of troops / party members per row (in my case to just 1 per row). I think I've found every single thread on this forum asking for that feature and every single one of them died without a reply from anyone who even attempted to try. So I'm guessing it's not possible?

I've been working on it pretty solid for awhile now, but I'm too noob to solve unsolvable issues lol.

Anyway, hope what I did come up with might help someone in the future!
I wanted it so that if an enemy in a row was killed it would push all the other rows forward automatically.
I've seen (helped with?) a few threads about doing that. I'm not sure it makes sense to put it in a Custom Row Condition, because then you'd have to put it on every damaging skill in your game to make sure it happens consistently.

It might make more sense to put it on your state 1 using the Buffs & States Custom Apply Effect tag (I'm pretty sure that's how I did it before).

Just a few tips about your code:
<Custom Row Condition> if ($gameTroop.rowAliveMembers(1) == 0) { $gameTroop.rowMembers(2).forEach(enemy => enemy.setRow(1)); } else { } </Custom Row Condition>
1 - There's no point in having an empty else. If you're not doing anything if your condition is false, just don't type it.

2 - if statements (and loops) automatically apply to the next single code statement. So if you're only doing one thing, you don't need to create a code block using braces.

3 - 0 is evaluated the same as false in C-based languages (or, in JavaScript, "falsey"), so a common shorthand for checking for it is to use NOT.

None of those things will make your code not work right, but your notetag can much more compactly be:
Code:
if (!$gameTroop.rowAliveMembers(1))
        $gameTroop.rowMembers(2).forEach(enemy => enemy.setRow(1));

Now, some logical notes...
1 - This only checks specifically row 1. Can you have a row 3 without an empty row 2? If not, you probably want to put this twice (or in a little loop).

2 - It only checks enemies. Do you not want actors to do the same thing? If you do, instead of specifically referencing $gameTroop you could use target.friendsUnit()

I'm not sure about why you're getting a weird offset.

Now if I could only figure how how to limit the number of troops / party members per row
You're asking two different things here. Enemies are simple because you define, in the database, which row enemies go in. So you simply arrange it correctly. Then any skills that cause row movement you account for it logically.

For actors, if there's nothing in the plugin parameters for it, you'd have to edit the plugin for the scene where the player sets up rows (is it in the Formation command? Does the Row have its own menu command? In there).

There's pretty much nothing that's "not possible," it's just a matter of how much coding knowledge and effort/work hours it takes to implement.
So this is gonna sound wild, but when I applied your cleaned up code it no longer worked. I then went back to my code and it does work.

Here's how I have everything set up.

BTW, I'm using side view (SV), YEP Core Engine, Message Core, Battle Engine Core, Battle System STB, Turn Order Display, Battle Status Window, Row Formation, Target Core, Selection Control, as well as some other custom plugins (turn based movement which only effects gameplay and not battle, and a static actor plugin that lets me have larger player battlers in battle - but this does not effect the enemy battlers.)

I created 4 states: Row 1, Row 2, Row 3, Row 4. If it's important I have them in state slots 101, 102, 103, and 104 - but don't think what slot the state in should matter.

Battles also (typically) have 4 enemies and 4 players.

In the Row One, state (101) I have this code:
<Custom Row Condition> if ($gameTroop.rowAliveMembers(1) == 0) { $gameTroop.rowMembers(2).forEach(enemy => enemy.setRow(1)); } else { } </Custom Row Condition>
And then in YEP_RowFormation plugin under "Row 1 states 1.5.0" I"m calling out state "101".

---

In the Row Two, state (102) I have this code:
<Custom Row Condition> if ($gameTroop.rowAliveMembers(2) == 0) { $gameTroop.rowMembers(3).forEach(enemy => enemy.setRow(2)); } else { } </Custom Row Condition>
And then in YEP_RowFormation plugin under "Row 2 states 1.5.0" I"m calling out state "102".

---

In the Row Three, state (103) I have this code:
<Custom Row Condition> if ($gameTroop.rowAliveMembers(3) == 0) { $gameTroop.rowMembers(4).forEach(enemy => enemy.setRow(3)); } else { } </Custom Row Condition>
And then in YEP_RowFormation plugin under "Row 3 states 1.5.0" I"m calling out state "103".

---

In the Row Four, state (104) I have this code: Keep in mind it's the SAME code as ROW 3 above - it was the only way I could get it to push Row 4 forward when Row 1, Row 2, and / or Row 3 met the conditions. Not sure why I have to repeat the code, but it works.

<Custom Row Condition> if ($gameTroop.rowAliveMembers(3) == 0) { $gameTroop.rowMembers(4).forEach(enemy => enemy.setRow(3)); } else { } </Custom Row Condition>
And then in YEP_RowFormation plugin under "Row 4 states 1.5.0" I"m calling out state "104".

---

OK. So now it's important for me to explain exactly what effect I'm hoping to achieve which will also answer some of your questions.

Now, some logical notes...
1 - This only checks specifically row 1. Can you have a row 3 without an empty row 2? If not, you probably want to put this twice (or in a little loop).

2 - It only checks enemies. Do you not want actors to do the same thing? If you do, instead of specifically referencing $gameTroop you could use target.friendsUnit()

I always want the rows to move forward when an enemy dies, so if an enemy in row 2 dies it will push rows 3 and 4 forward, or if an enemy in row 1 dies it will push rows 2, 3 and 4 forward, or if an enemy in row 3 dies it pushes row 4 forward. Think of it like the enemies are always trying to get as close to the players as possible but also without there ever being more than 1 enemy in a row.

I also don't want this effect to apply to players and when I don't want an enemy to move I apply the <Row Lock> tag to that enemy (I've tested this and it works). And the reason why I don't want the players to move automatically is because they're the heroes who get to have this advantage in battle over the monsters. Also since a player might need to move to the back row to take advantage of a skill, I don't want the game overriding their decision and forcing them into a row where they can't use a skill / item. That could also potentially lead to a case where if there's only 1 player left and they have to be in row 2 for some skill to kill the enemy, I don't want to create a situation where it's then impossible for the player to win only because the game keeps forcing them to move out of the row they want to be in.

OK, so when I changed the code to use your cleaned up example, the enemies no longer move when they are killed. And all I changed was I went back into the row states that I created (101, 102, 103, and 104) and just replaced my code with your code.

I first tried killing the enemy in row 1 and nothing happened - row 2 did not move into row 1, row 3 did not move to row 2, and row 4 did not move into row 3.

I thought I did something wrong so I went back to my code and everything worked, and then double checked that I had copied your code right, put it back in, but again it didn't work.

So I'm not sure why mine would work and your doesn't.

I'm not sure about why you're getting a weird offset.

If you place more than 1 enemy or player in a row (for example if row 2 has two enemies in it) it offsets them so you can see them both clearly. But for some reason when my code pushes the enemies forward it's acting like there's two enemies in the row (even though there isn't) and is maintaining the offset so that when the new enemy enters the new row, it's offset. The offset isn't anything odd per-se since you normally don't want actors overlapping right on top of each other, it's just odd in my case since even though there isn't another actor in the row the plugin is still maintaining the offset.

You're asking two different things here. Enemies are simple because you define, in the database, which row enemies go in. So you simply arrange it correctly. Then any skills that cause row movement you account for it logically.
I apologize if I don't understand but the plugin lets us put multiple enemies (or players) in a row. For example Row 2 could have the entire player party in it while leaving rows 1, 3 and 4 empty. I understand that when we use the <default row: x> tag it will initially put enemies / players in that row, but when rows are pushed / pulled then the plugin puts multiple enemies / players in that row.

For example if you have an enemy in row 3 and another in row 2 and you use the <Pull Forward Target Row: 3> tag, it will pull row 3 forward, but now row 2 has two enemies in it. I was just trying to prevent that from happening automatically so that if the player chooses to pull row 3 forward it won't let it happen because there's already something in row 2. Basically just trying to limit the amount of things that can be in a row ever, not just initially when the <default row: x> is initialized - sort of like in chess where there can only ever be 1 piece in any 1 square at a time or in GO where there can only ever be 1 black or white stone in a square at one time. And that effect was something I was hoping to apply to both enemies and players.

I hope this helps.
So part of your problems is you're misunderstanding/misusing the Custom Row Condition tag.

The intent of that tag, as described in the documentation, is to determine when a battler is put into a specific row, and to use the described condition variable to turn the state on and off accordingly.

It's not intended for you to run miscellaneous code with different timing in there. That's probably why you're seeing weird offsets and positionings, because your row states are defaulting to true and you're simultaneously changing their row but never turning off the old row state.

I think the reason you're getting mixed results from the code is how you're evaluating the rowAliveMembers() function. I used it in my example for you because you were using it, but that's not quite correct.

Looking at the documentation, that doesn't return a number, it returns an array of the alive battlers in that row. If that array is empty it can evaluate equivalent to 0, but that's not really the correct way to do a comparison. You should be using the rowAliveSize() function, which returns the number of alive battlers. (or looking at the .length property of the array)

So as I mentioned before, this should come out of your row states and go someplace where it's going to be evaluated at the correct point in time for it to be done. That could be on skills, but it would have to be on all of your skills, which is inefficient. I still recommend it go in your state 1, and try thusly:
Code:
<Custom Apply Effect>
if (user.isEnemy())
{
    for (let i=1; i<=3; i++)
    {
        if (!$gameTroop.rowAliveSize(i))
            $gameTroop.rowAliveMembers(i+1).forEach(enemy => enemy.setRow(i));
    }
}
</Custom Apply Effect>

Take all of the Custom Conditions out of your row states and try that. It should cause all of the enemies to fall forward a row when you kill one in the front.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-row-formation-question-about-troops-swapping-positions.153993/