Guest User

QMFollowers

a guest
May 28th, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | Source Code | 0 0
  1. //=============================================================================
  2. // QMFollowers
  3. //=============================================================================
  4.  
  5. var Imported = Imported || {};
  6.  
  7. if (!Imported.QMovement || !QPlus.versionCheck(Imported.QMovement, '1.2.2')) {
  8. alert('Error: QM+Followers requires QMovement 1.2.2 or newer to work.');
  9. throw new Error('Error: QM+Followers requires QMovement 1.2.2 or newer to work.');
  10. }
  11.  
  12. Imported.QMFollowers = '1.0.2';
  13.  
  14. //=============================================================================
  15. /*:
  16. * @plugindesc <QMFollowers>
  17. * QMovement Addon: Adds follower support
  18. * @version 1.0.2
  19. * @author Quxios | Version 1.0.2 //iVillain edit
  20. * @site https://quxios.github.io/
  21. * @updateurl https://quxios.github.io/data/pluginsMin.json
  22. *
  23. * @requires QMovement
  24. *
  25. * @help
  26. * ============================================================================
  27. * ## About
  28. * ============================================================================
  29. * This adds support for followers when using QMovement.
  30. *
  31. * *Note:* I won't be continuing working on this plugin. I personally dislike
  32. * followers and rather not do anything with them. So if you have issues with this
  33. * plugin you will need to try to fix it your self or find another plugin dev
  34. * to fix it for you. Sorry!
  35. * ============================================================================
  36. * ## Links
  37. * ============================================================================
  38. * Formated Help:
  39. *
  40. * https://quxios.github.io/#/plugins/QM+Followers
  41. *
  42. * RPGMakerWebs:
  43. *
  44. * http://forums.rpgmakerweb.com/index.php?threads/qplugins.73023/
  45. *
  46. * Terms of use:
  47. *
  48. * https://github.com/quxios/QMV-Master-Demo/blob/master/readme.md
  49. *
  50. * Like my plugins? Support me on Patreon!
  51. *
  52. * https://www.patreon.com/quxios
  53. *
  54. * @tags QM-Addon, followers
  55. */
  56. //=============================================================================
  57.  
  58.  
  59. //=============================================================================
  60. // QMFollowers
  61.  
  62. (function() {
  63.  
  64. //-----------------------------------------------------------------------------
  65. // Game_Player
  66.  
  67. var Alias_Game_Player_onPositionChange = Game_Player.prototype.onPositionChange;
  68. Game_Player.prototype.onPositionChange = function() {
  69. Alias_Game_Player_onPositionChange.call(this);
  70. var dir = this.radianToDirection(this._radian, QMovement.diagonal);
  71. this._followers.addMove(this._px, this._py, this.realMoveSpeed(), dir);
  72. };
  73.  
  74. //-----------------------------------------------------------------------------
  75. // Game_Follower
  76.  
  77. var Alias_Game_Follower_initialize = Game_Follower.prototype.initialize;
  78. Game_Follower.prototype.initialize = function(memberIndex) {
  79. Alias_Game_Follower_initialize.call(this, memberIndex);
  80. this._moveList = [];
  81. };
  82.  
  83. Game_Follower.prototype.addMove = function(x, y, speed, dir) {
  84. this._moveList.push([x, y, speed, dir]);
  85. };
  86.  
  87. Game_Follower.prototype.clearList = function() {
  88. this._moveList = [];
  89. };
  90.  
  91. Game_Follower.prototype.update = function() {
  92. Game_Character.prototype.update.call(this);
  93. this.setOpacity($gamePlayer.opacity());
  94. this.setBlendMode($gamePlayer.blendMode());
  95. this.setWalkAnime($gamePlayer.hasWalkAnime());
  96. this.setStepAnime($gamePlayer.hasStepAnime());
  97. this._isDashing = $gamePlayer.isDashing();
  98. this.setDirectionFix($gamePlayer.isDirectionFixed());
  99. this.setTransparent($gamePlayer.isTransparent());
  100. };
  101.  
  102. Game_Follower.prototype.updateMoveList = function(preceding, gathering) {
  103. if (this._moveList.length === 0 || this.startedMoving()) return;
  104. if (this._moveList.length <= this._memberIndex) return;
  105.  
  106. while(this._moveList.length > (12 * this._memberIndex)) {
  107.  
  108. var move = this._moveList.shift();
  109. if (!gathering) {
  110. var collided = this.collideWithPreceding(preceding, move[0], move[1], move[3]);
  111. if (collided) {
  112. this._moveList.unshift(move);
  113. return;
  114. }
  115. }
  116. this.setMoveSpeed(move[2]);
  117. this.setDirection(move[3]);
  118. this._realPX = this._px;
  119. this._realPY = this._py;
  120. this._px = move[0];
  121. this._py = move[1];
  122.  
  123. }
  124. };
  125.  
  126. Game_Follower.prototype.collideWithPreceding = function(preceding, x, y, dir) {
  127. if (!this.isVisible()) return false;
  128. this.collider('collision').moveTo(x, y);
  129. if (this.collider('collision').intersects(preceding.collider('collision'))) {
  130. if (this._direction === preceding._direction) {
  131. this.collider('collision').moveTo(this._px, this._py);
  132. return true;
  133. }
  134. }
  135. this.collider('collision').moveTo(this._px, this._py);
  136. return false;
  137. };
  138.  
  139. Game_Follower.prototype.defaultColliderConfig = function() {
  140. return QMovement.playerCollider;
  141. };
  142.  
  143. //-----------------------------------------------------------------------------
  144. // Game_Follower
  145.  
  146. Game_Followers.prototype.update = function() {
  147. for (var i = 0; i < this._data.length; i++) {
  148. var precedingCharacter = (i > 0 ? this._data[i - 1] : $gamePlayer);
  149. this._data[i].update();
  150. this._data[i].updateMoveList(precedingCharacter, this._gathering);
  151. }
  152. };
  153.  
  154. Game_Followers.prototype.addMove = function(x, y, speed, dir) {
  155. for (var i = 0; i < this._data.length; i++) {
  156. this._data[i].addMove(x, y, speed, dir);
  157. }
  158. };
  159.  
  160. Game_Followers.prototype.synchronize = function (x, y, d) {
  161. var chara = $gamePlayer;
  162. for (const follower of this._data) {
  163. follower.copyPosition(chara);
  164. follower.straighten();
  165. follower.setDirection(chara.direction());
  166. follower.clearList();
  167. }
  168. };
  169.  
  170. Game_Followers.prototype.areGathering = function() {
  171. if (this.areGathered() && this._gathering) {
  172. this._gathering = false;
  173. return true;
  174. }
  175. return false;
  176. };
  177.  
  178. Game_Followers.prototype.areGathered = function() {
  179. return this.visibleFollowers().every(function(follower) {
  180. return follower.cx() === $gamePlayer.cx() && follower.cy() === $gamePlayer.cy();
  181. }, this);
  182. };
  183. })()
  184.  
Tags: RPG Maker MZ
Advertisement
Add Comment
Please, Sign In to add comment