じ☆ve冰风 发表于 4 天前

Unstacking followers from on top of the player

I spent over two hours searching for how to do this and mostly found non-answers like "it's too hard so you need to do a plugin request" but those non-answers never seemed to come from people who actually write plugins. And one of the actual plugin authors at one point (I think it was Yanfly) mentioned that most of the functionality of their plugins could be accomplished within the event system. And it is, indeed, rather flexible if you take the time to learn it. HOWEVER there are some things that aren't exposed in the event system and Follower settings are a big one not there.

So first this is actually a trivial task. In order to "unstack" the followers when you first transfer into a map you only need to know the direction the player is facing and the X and Y coordinates they are at. Then all you need to do is assign each follower to an appropriate position. This does assume that you setup the player entry position far enough from walls and such that the followers won't be in a strange position.

Since the follower info can't be manipulated directly in the event system we need some javascript to do that. And it's rather trivial as it only requires a SINGLE line of code for each follower. So assuming the standard party size of 4 that's THREE lines of code. When facing down you want each the first follower to have the same X position as the player but -1 to the Y and the second is -2 to the Y and so on.

Your first step is to create an event and it's better to do it someplace where the player and NPCs won't wander on top of it and set it to priority "Below characters" and the Trigger to "Autorun" and then the fun begins.
We can use the event system and game variables to get the player facing and X and Y coordinates like this:




Once you get the variables named you need to fill them in like this:



in the Control Variables we need to choose the variable like this:



And fill it like this:



Choose Game Data then select it and grab this:



Choose Character, Player and Direction.
Then do the same for the Map X and Map Y to go into the Player X and Player Y variables respectively.
You should end up with this:




We need to check the Player direction. I dug into the main javascript files and found this:

Game_Map.prototype.doScroll = function(direction, distance) {
    switch (direction) {
      case 2:
            this.scrollDown(distance);
            break;
      case 4:
            this.scrollLeft(distance);
            break;
      case 6:
            this.scrollRight(distance);
            break;
      case 8:
            this.scrollUp(distance);
            break;
    }
};

That tells us that Down is 2, Left is 4 and so on. Interesting thing is this implies that we can do diagonals and those would be the odd numbers but we don't need that now

So we next need to check for those directions like this:







We'll want to choose Variable and use our Player Facing variable and select 2 for the down position.
We don't truly need an else which will make this look a little cleaner so leave that checkbox off.
Now the fun part:



Right there between the IF and the End we want to add the Script which is on Tab 3



more game variables that took some digging to find go in here like this:
$gamePlayer.followers()._data.locate($gamePlayer.x, $gamePlayer.y-1);
$gamePlayer.followers()._data.locate($gamePlayer.x, $gamePlayer.y-2);
$gamePlayer.followers()._data.locate($gamePlayer.x, $gamePlayer.y-3);

That's our 3 lines of code needed and you can copy those from here and paste them into that window like this:



and the end result looks like this:




So now even if you didn't know javascript before you've advanced from noob to powernoob

Once we complete the other directions your event should look like this:




I took an extra step and did an Erase Event at the tail end but it's probably unnecessary.
You will see an immediate result when you start the game since that event is autorun and you'll see the followers in their line behind the player like this:




And as long as you set your maps up properly and have a copy of that event on each map then when your player transfers to a map everyone will be in their proper spot!

For MZ since it allows more code into the Script window I condensed it much further to one simple script command for the event you can see here:
MZ version simplified


本贴来自国际rpgmaker官方论坛作者:zzmmorgan处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/unstacking-followers-from-on-top-of-the-player.140388/
页: [1]
查看完整版本: Unstacking followers from on top of the player