Follower Distance

● ARCHIVED · READ-ONLY
Started by MechPen 36 posts Page 1 of 2 View original ↗
  1. Follower Space ver 1.2

    by me, MechPen


    Here's a quick and easy plugin to change how many tiles the party members follow behind the leader. You might need this if your character sprites are wider or longer than 1 tile. Make that pony RPG!

    Feature

    - Change the distance that party members follow behind the leader.


    Screenshots
    A Follow Distance setting of 2
    followerSpace.png


    How to Use

    Place the plugin in the 'plugins' folder as usual. Add it to the project using the Plugin Manager. Adjust the Follower Distance parameter to the number of tiles you'd like the followers to be behind the leader.

    As of 1.2, this also works in MZ.



    Script
    MechPen_FollowerSpace.js
    JavaScript:
    //=============================================================================
    // MechPen Plugins - Followers Follow Less Close.
    // MechPen_FollowerSpace.js
    //=============================================================================
    
    //It's important that this goes before anything otehr plug-in that modifies:
    // Game_Follower.updateMove();
    
    var Imported = Imported || {};
    Imported.MechPen_FollowerSpace = true;
    
    var MechPen = MechPen || {};
    MechPen.FollowerSpace = MechPen.FollowerSpace || {};
    MechPen.FollowerSpace.version = 1.2;
    
    //=============================================================================
    /*:
    * @target MV MZ
    * @plugindesc v1.2 Lets party followers lag a set number of tiles behind.
    * Useful if your character sprites are large (or fat :P ).
    * @author MechPen
    *
    * @param Follower Distance
    * @desc How many tiles are between each character.
    * Default: 1
    * @default 1
    *
    * @help
    * Be sure to put this plug-in above any other plug-in that
    * modifies Game_Follower.updateMove(); or else that plug-in might not work.
    *
    * Also: You can't set Follower Distance less than 1. It would make no sense to stack
    * the followers like that!
    * version 1.2
    * - Not it works in MZ.
    * version 1.1
    * - Fixed bug with Gathering, if the player hadn't walked enough to fill out his last positions.
    * version 1.0
    * - Finished plugin!
    */
    //=============================================================================
    
    MechPen.Parameters = PluginManager.parameters('MechPen_FollowerSpace');
    MechPen.Param = MechPen.Param || {};
    MechPen.Param.FollowerSpaceDistance = Math.max((Number(MechPen.Parameters['Follower Distance']) || 1), 1);
    
    //=============================================================================
    // Game_Player
    //=============================================================================
    MechPen.FollowerSpace.Game_Player_initialize = Game_Player.prototype.initialize;
    Game_Player.prototype.initialize = function() {
        MechPen.FollowerSpace.Game_Player_initialize.call(this);
        this._lastPositions = new Array();
    };
    
    MechPen.FollowerSpace.Game_Player_clearTransferInfo = Game_Player.prototype.clearTransferInfo;
    Game_Player.prototype.clearTransferInfo = function() {
        MechPen.FollowerSpace.Game_Player_clearTransferInfo.call(this);
        this.clearLastPositions();
    };
    
    Game_Player.prototype.getLastPositions = function() {
        return this._lastPositions;
    };
    
    Game_Player.prototype.popLastPositions = function() {
        this._lastPositions.pop();
    };
    
    Game_Player.prototype.clearLastPositions = function() {
        this._lastPositions.length = 0;
    };
    
    Game_Player.prototype.repeatLastPositions = function() {
        var currentPosition = [this.x, this.y];
        this._lastPositions.unshift(currentPosition)
    };
    
    MechPen.FollowerSpace.Game_Player_moveStraight = Game_Player.prototype.moveStraight;
    Game_Player.prototype.moveStraight = function(d) {
        MechPen.FollowerSpace.Game_Player_moveStraight.call(this, d);
        if (this.isMovementSucceeded()) {
            var currentPosition = [this.x, this.y];
            this._lastPositions.unshift(currentPosition);
        }
    };
    
    MechPen.FollowerSpace.Game_Player_moveDiagonally = Game_Player.prototype.moveDiagonally;
    Game_Player.prototype.moveDiagonally = function(horz, vert) {
        MechPen.FollowerSpace.Game_Player_moveDiagonally.call(this, horz, vert);
        if (this.isMovementSucceeded()) {
            var currentPosition = [this.x, this.y];
            this._lastPositions.unshift(currentPosition);
        }
    };
    
    //=============================================================================
    // Game_Follower
    //=============================================================================
    Game_Follower.prototype.chasePlayerAtDistance = function(character, distance) {
        var spacesAway = distance;
        var spaces = $gamePlayer.getLastPositions();
        if (spaces.length < spacesAway) { return; }
     
        var sx = this.deltaXFrom(spaces[spacesAway - 1][0]);
        var sy = this.deltaYFrom(spaces[spacesAway - 1][1]);
        //TODO: reoptimize.
        if (Math.abs(sx) > 0 && Math.abs(sy) > 0) {
            this.moveDiagonally(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2);
        } else if (Math.abs(sx) > 0) {
            this.moveStraight(sx > 0 ? 4 : 6);
        } else if (Math.abs(sy) > 0) {
            this.moveStraight(sy > 0 ? 8 : 2);
        }
        this.setMoveSpeed($gamePlayer.realMoveSpeed());
    };
    
    
    //=============================================================================
    // Game_Followers
    //=============================================================================
    Game_Followers.prototype.updateMove = function() {
        var spacing = 0;
        for (var i = 0; i < this._data.length; i++) {
            var precedingCharacter = (i > 0 ? this._data[i - 1] : $gamePlayer);
            spacing += MechPen.Param.FollowerSpaceDistance;
            this._data[i].chasePlayerAtDistance(precedingCharacter, spacing);
        }
     
        if ($gamePlayer.getLastPositions().length - 1 > spacing * (this._data[this._data.length - 1]._memberIndex + 1))
        {
            $gamePlayer.popLastPositions();
        }
     
        if (this.areGathering())
        {
            $gamePlayer.repeatLastPositions();
        }
    };
    
    MechPen.FollowerSpace.Game_Followers_jumpAll = Game_Followers.prototype.jumpAll;
    Game_Followers.prototype.jumpAll = function() {
        MechPen.FollowerSpace.Game_Followers_jumpAll.call(this);
        $gamePlayer.clearLastPositions();
    };
    
    if (Utils.RPGMAKER_NAME == "MZ")
    {
    
    Game_Followers.prototype.synchronize = function(x, y, d) {
        for (const follower of this._data) {
            follower.locate(x, y);
            follower.setDirection(d);
        }
    };
    
    } else if (Utils.RPGMAKER_NAME == "MV")
    {
        
    Game_Followers.prototype.synchronize = function(x, y, d) {
        this.forEach(function(follower) {
            follower.locate(x, y);
            follower.setDirection(d);
        }, this);
    };
    
    }


    Terms of Use
    This work is licensed under the MIT license.
  2. This is an awesome, much-needed plugin. Thanks!

    It's a shot in the dark, but I have to ask: Any chance you might update this plugin to support a pixel movement mod like Analog Move? Analog Move is my favorite pixel movement plugin but lacks any parameters to control follower distance.

    ETA: Nevermind, I figured out how to change follower distance in the Analog Move plugin myself. (It's shockingly easy.) FWIW, I posted it in the Analog Move thread here: https://forums.rpgmakerweb.com/index.php?threads/analog-move.49828/post-1066448

    Anyway, great plugin!
  3. Good plugin! I'm using tall sprites (with 8 frames for each direction), they look better now with a distance of 2.
    There is a visual bug though...when the player starts walking away, the followers start walking in place until the target distance is reached and then they start moving.
    It would look better, if they would stand still first and start walking and moving when distance is met.
  4. Thanks a lot!!
    I really expected this plugin a long time ago,
    thanks a lot again <3
  5. Ascare said:
    Good plugin! I'm using tall sprites (with 8 frames for each direction), they look better now with a distance of 2.
    There is a visual bug though...when the player starts walking away, the followers start walking in place until the target distance is reached and then they start moving.
    It would look better, if they would stand still first and start walking and moving when distance is met.
    Has this been fixed?
  6. Uranium said:
    Has this been fixed?
    Works for me! Starting a brand new project, only including Follower_Distance and setting Follower Distance to 2. The followers wait until they need to step before animating. Maybe someone else's plug in is animating Followers for you?
  7. Is there a way to adjust the distance of the sprites with a script call? I have some maps where it makes sense to be closer and others where it doesn't.
  8. you could set MechPen.Param.FollowerSpaceDistance in a script call and it would work, but it wouldn't get saved to the save file...
  9. Thankyou so much for your work with this plugin. Unfortunately it doesn't work for me and I'm baffled as to why....:unsure:
  10. Make sure its near the end of the plug in list and turned on. And you have to change the plug in parameter Follower Distance to 2 (or more, if you like).

    And make sure you press Save Project. MV doesn't update the plugins until you save.
  11. Works great, thanks. This is the answer when using larger sprites.
  12. Thank you for this plugin! It works well for me in MZ. Would it be possible to set the follower distance to a decimal value? In my case, my sprites need a distance between 1.2 and 1.5, as a distance of 2 is too spacious for it.
  13. @laaghisce

    Not as written. this plug-in only changes the tile distance. you'd need some kind of pixel movement or half move plug in and a new follower distance would need to be written on top of it.
  14. I just tried this plugin it doesn't seem to work. I am using this for MZ project, the only other movement-related plugin I am using is Visustella's Event and Move plugin. When I place the plugin at the top of the plugin list, my followers do not follow the player. Even when I turned off all my plugins. I tried this both in MV and MZ and got the same result.
  15. KazukiT said:
    I just tried this plugin it doesn't seem to work. I am using this for MZ project, the only other movement-related plugin I am using is Visustella's Event and Move plugin. When I place the plugin at the top of the plugin list, my followers do not follow the player. Even when I turned off all my plugins. I tried this both in MV and MZ and got the same result.
    I think you must be doing something incorrectly. I just put this into new MV and MZ projects and it works perfectly.

    Are you saving your project and starting a new game after installing the plugin?
  16. I found out which plugin caused followers to stop moving. It was "Cae_Slope Move" plugin, which allows the player to go and down diagonally (going down stairs sideways.) I also tried installing the plug-in again, saving then starting a new game with the followers distance not changing. I also turned the Cae_Slope plugin off and got the same result.
  17. Try changing the order of the plugins. When 2 plugins clash when one is above the other, then putting it under the other might work.

    Cant promise this is the case here but it is worth the try.
  18. @JohnDoeNews despite changing the order where (Cae_Slope Move) was on the bottom and it still didn't work. I think I will put skip this plugin for now.
  19. Might be best. Sometimes you have to make a choice. Not all plugins can work together.

    Too bad changing the order did not do anything.
  20. Cae_SlopeMove overrides Game_Player.prototype.moveStraight. but I alias it so it should work if you load Cae_SlopeMove first and then MechPen_FollowerSpace.

    Does it not?