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.