Skip to content

Instantly share code, notes, and snippets.

@Jomy10
Last active May 2, 2022 17:20
Show Gist options
  • Save Jomy10/4c284bbfda71003d2ad34b49a92a27e5 to your computer and use it in GitHub Desktop.
Save Jomy10/4c284bbfda71003d2ad34b49a92a27e5 to your computer and use it in GitHub Desktop.
Move any event to a player in RPG Maker

Player follower

This plugin for RPG Maker MV (should work for MZ as well) moves any event marked with to the player.

Installation

Copy playerFollower.js to project folder > js > plugins and then select the plugin in the plugin menu.

Usage

Create a new event on the map and add <player-follower> to the event's Note section. Make sure to set Priority to either Above characters or Below characters`.

1 - example

Showcase

/*:
* @author Jonas Everaert
* @plugindesc Move any event to the player
* <be.jonaseveraert.mv.playerFollower>
*
* @help
* Move any event marked with <player-follower> in the event's note section to
* the player.
*/
(function() {
let pluginParams = $plugins.filter(function(p) {
return p.description.contains('<be.jonaseveraert.mv.playerFollower>') && p.status;
})[0];
/// gets the events indicated with "<player-follower>" in the notes
function getPlayerLightEvents() {
let events = [];
if ($dataMap != null) {
for (eventId in $dataMap.events) {
let eventFromId = $gameMap.event(eventId)
if (eventFromId != null && eventFromId instanceof Game_Event && eventFromId.event().note.contains("<player-follower>")) {
events.push(eventId);
}
}
}
return events;
}
/// Event ids containing "<player-follower>"
let events = getPlayerLightEvents();
// Get new events for new map player is transferred to
let oldGamePlayer_performTransfer = Game_Player.prototype.performTransfer;
Game_Player.prototype.performTransfer = function() {
oldGamePlayer_performTransfer.call(this);
events = getPlayerLightEvents();
};
// Called every frame
// Move event to player
let update = Window_Base.prototype.update;
Window_Base.prototype.update = function() {
update.call(this);
for (i = 0; i < events.length; i++) {
let event = $gameMap._events[events[i]];
//event.moveStraight(event.findDirectionTo($gamePlayer._realX, $gamePlayer._realY));
event.setMoveSpeed($gamePlayer.realMoveSpeed());
event.moveTowardPlayer();
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment