Project1

标题: 请问这个脚本应该怎么改呢 [打印本页]

作者: 夏小堕    时间: 2023-4-4 17:35
标题: 请问这个脚本应该怎么改呢
这是GALV的互动提示插件代码,在人物面前的事件会弹出动态图标提示。怎么实现人物不朝向事件方向也能弹出提示呢?另外能不能扩大提示的范围,相距两格的时候就进行提示?
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. //  Galv's Action Indicators
  3. //-----------------------------------------------------------------------------
  4. //  For: RPGMAKER MV
  5. //  GALV_ActionIndicators.js
  6. //-----------------------------------------------------------------------------
  7. //  2017-05-26 - Version 1.4 - fixed a bug when looking at same icon indicator
  8. //                           - wouldn't do popup effect
  9. //  2015-03-06 - Version 1.3 - now works with events 'under' the player as well
  10. //                           - as counters
  11. //  2015-12-08 - Version 1.2 - added opacity, z and hiding options.
  12. //  2015-12-07 - Version 1.1 - fixed a crash when you deleted events.
  13. //  2015-12-04 - Version 1.0 - release
  14. //-----------------------------------------------------------------------------
  15. // Terms can be found at:
  16. // galvs-scripts.com
  17. //-----------------------------------------------------------------------------
  18.  
  19. var Imported = Imported || {};
  20. Imported.Galv_ActionIndicators = true;
  21.  
  22. var Galv = Galv || {};        // Galv's main object
  23. Galv.pCmd = Galv.pCmd || {};  // Plugin Command manager
  24. Galv.AI = Galv.AI || {};      // Galv's plugin stuff
  25.  
  26. //-----------------------------------------------------------------------------
  27. /*:
  28.  * @plugindesc 当玩家能够与事件交互时显示图标。
  29.  *
  30.  * @author Galv - galvs-scripts.com
  31.  *
  32.  * @param Y Offset
  33.  * @desc 图标Y位置的像素偏移
  34.  * @default 0
  35.  *
  36.  * @param Z Position
  37.  * @desc Z位置(controls if it appears over/under map objects)
  38.  * @default 5
  39.  *
  40.  * @param Auto Hide
  41.  * @desc true or false. If true, 事件运行时图标将消失
  42.  * @default true
  43.  *
  44.  * @param Icon Opacity
  45.  * @desc 0-255. 图标的不透明度
  46.  * @default 255
  47.  *
  48.  * @help
  49.  *   Galv's Action Indicators
  50.  * ----------------------------------------------------------------------------
  51.  * This plugin will enable you to display an icon when the player is facing an
  52.  * event that has the below code in a 'comment' command anywhere in the active
  53.  * event page.
  54.  *
  55.  *   <actionIcon: id>       // The code to use in a COMMENT within and event.
  56.  *                          // id = the icon ID to use for the indicator.
  57.  *
  58.  * ----------------------------------------------------------------------------
  59.  *  插件命令
  60.  * ----------------------------------------------------------------------------
  61.  *
  62.  *   AIVISIBLE FALSE        // 禁用动作指示器
  63.  *   AIVISIBLE TRUE         // 启用动作指示器
  64.  *   
  65.  */
  66.  
  67. //-----------------------------------------------------------------------------
  68. //  CODE STUFFS
  69. //-----------------------------------------------------------------------------
  70.  
  71. (function() {
  72.  
  73. Galv.AI.y = Number(PluginManager.parameters('Galv_ActionIndicators')["Y Offset"]);
  74. Galv.AI.z = Number(PluginManager.parameters('Galv_ActionIndicators')["Z
  75.  
  76. Position"]);
  77. Galv.AI.opacity = Number(PluginManager.parameters('Galv_ActionIndicators')["Icon
  78.  
  79. Opacity"]);
  80.  
  81. Galv.AI.autoHide = eval(PluginManager.parameters('Galv_ActionIndicators')["Auto
  82.  
  83. Hide"]);
  84. Galv.AI.needRefresh = false;
  85.  
  86. // GALV'S PLUGIN MANAGEMENT. INCLUDED IN ALL GALV PLUGINS THAT HAVE PLUGIN COMMAND
  87.  
  88. CALLS, BUT ONLY RUN ONCE.
  89. if (!Galv.aliased) {
  90.         var Galv_Game_Interpreter_pluginCommand =
  91.  
  92. Game_Interpreter.prototype.pluginCommand;
  93.         Game_Interpreter.prototype.pluginCommand = function(command, args) {
  94.                 if (Galv.pCmd[command]) {
  95.                         Galv.pCmd[command](args);
  96.                         return;
  97.                 };
  98.                 Galv_Game_Interpreter_pluginCommand.call(this, command, args);
  99.         };
  100.         Galv.aliased = true; // Don't keep aliasing for other Galv scripts.
  101. };
  102.  
  103. // Direct to Plugin Object
  104. Galv.pCmd.AIVISIBLE = function(arguments) {
  105.         var status = eval(arguments[0].toLowerCase())
  106.         $gameSystem.actionIndicatorVisible = status;
  107. };
  108. // END GALV'S PLUGIN MANAGEMENT
  109.  
  110.  
  111.  
  112.  
  113. //-----------------------------------------------------------------------------
  114. // Game_System
  115.  
  116. var Galv_Game_System_initialize = Game_System.prototype.initialize;
  117. Game_System.prototype.initialize = function() {
  118.         Galv_Game_System_initialize.call(this);
  119.         this.actionIndicatorVisible = true;
  120. };
  121.  
  122. //-----------------------------------------------------------------------------
  123. // Game_Map
  124.  
  125. var Galv_Game_Map_requestRefresh = Game_Map.prototype.requestRefresh;
  126. Game_Map.prototype.requestRefresh = function(mapId) {
  127.         Galv_Game_Map_requestRefresh.call(this,mapId);
  128.         Galv.AI.needRefresh = true;
  129. };
  130.  
  131.  
  132. //-----------------------------------------------------------------------------
  133. // Game_Player
  134.  
  135. var Galv_Game_CharacterBase_moveStraight =
  136.  
  137. Game_CharacterBase.prototype.moveStraight;
  138. Game_CharacterBase.prototype.moveStraight = function(d) {
  139.         Galv_Game_CharacterBase_moveStraight.call(this,d);
  140.         Galv.AI.needRefresh = true;
  141. };
  142.  
  143. Galv.AI.checkActionIcon = function() {
  144.         var x2 = $gameMap.roundXWithDirection($gamePlayer._x,
  145.  
  146. $gamePlayer._direction);
  147.     var y2 = $gameMap.roundYWithDirection($gamePlayer._y, $gamePlayer._direction);
  148.         var action = null;
  149.  
  150.  
  151.         // CHECK EVENT STANDING ON
  152.         $gameMap.eventsXy($gamePlayer._x, $gamePlayer._y).forEach(function(event)
  153.  
  154. {
  155.                 action = Galv.AI.checkEventForIcon(event);
  156.         });
  157.  
  158.         // CHECK EVENT IN FRONT
  159.         if (!action) {
  160.                 $gameMap.eventsXy(x2, y2).forEach(function(event) {
  161.                         if (event.isNormalPriority()) {
  162.                                 action = Galv.AI.checkEventForIcon(event);
  163.                         };
  164.                 });
  165.         };
  166.  
  167.         // CHECK COUNTER
  168.         if (!action && $gameMap.isCounter(x2, y2)) {
  169.                 var direction = $gamePlayer.direction();
  170.                 var x3 = $gameMap.roundXWithDirection(x2, direction);
  171.                 var y3 = $gameMap.roundYWithDirection(y2, direction);
  172.                  $gameMap.eventsXy(x3, y3).forEach(function(event) {
  173.                         if (event.isNormalPriority()) {
  174.                                 action = Galv.AI.checkEventForIcon(event);
  175.                         };
  176.                 });
  177.         };
  178.         action = action || {'eventId': 0, 'iconId': 0};
  179.         $gamePlayer.actionIconTarget = action;
  180. };
  181.  
  182.  
  183.  
  184. Galv.AI.checkEventForIcon = function(event) {
  185.         var icon = 0;
  186.  
  187.         if (event.page()) {
  188.                 var listCount = event.page().list.length;
  189.  
  190.                 for (var i = 0; i < listCount; i++) {
  191.                         if (event.page().list[i].code === 108) {
  192.                                 var iconCheck = event.page().list[i].parameters
  193.  
  194. [0].match(/<actionIcon: (.*)>/i);
  195.                                 if (iconCheck) {
  196.                                         // create target object
  197.                                         return {'eventId':
  198.  
  199. event._eventId,'iconId': Number(iconCheck[1])};
  200.                                         break;
  201.                                 };
  202.                         };
  203.                 };
  204.         };
  205.         return null;
  206. };
  207.  
  208.  
  209. //-----------------------------------------------------------------------------
  210. // Spriteset_Map
  211.  
  212. var Galv_Spriteset_Map_createLowerLayer =
  213.  
  214. Spriteset_Map.prototype.createLowerLayer;
  215. Spriteset_Map.prototype.createLowerLayer = function() {
  216.         Galv_Spriteset_Map_createLowerLayer.call(this);
  217.         this.createActionIconSprite();
  218. };
  219.  
  220. Spriteset_Map.prototype.createActionIconSprite = function() {
  221.         this._actionIconSprite = new Sprite_ActionIcon();
  222.         this._tilemap.addChild(this._actionIconSprite);
  223. };
  224.  
  225.  
  226. //-----------------------------------------------------------------------------
  227. // Sprite_ActionIcon
  228.  
  229. function Sprite_ActionIcon() {
  230.     this.initialize.apply(this, arguments);
  231. }
  232.  
  233. Sprite_ActionIcon.prototype = Object.create(Sprite.prototype);
  234. Sprite_ActionIcon.prototype.constructor = Sprite_ActionIcon;
  235.  
  236. Sprite_ActionIcon.prototype.initialize = function() {
  237.     Sprite.prototype.initialize.call(this);
  238.         $gamePlayer.actionIconTarget = $gamePlayer.actionIconTarget || {'eventId':
  239.  
  240. 0, 'iconId': 0};
  241.         this._iconIndex = 0;
  242.         this.z = Galv.AI.z;
  243.         this.changeBitmap();
  244.         this._tileWidth = $gameMap.tileWidth();
  245.         this._tileHeight = $gameMap.tileHeight();
  246.         this._offsetX = -(Window_Base._iconWidth / 2);
  247.         this._offsetY = -38 + Galv.AI.y;
  248.         this.anchor.y = 1;
  249.         this._float = 0.1;
  250.         this.mod = 0.2;
  251.         Galv.AI.needRefresh = true;
  252. };
  253.  
  254. Sprite_ActionIcon.prototype.changeBitmap = function() {
  255.         if ($gamePlayer.actionIconTarget.eventId <= 0) {
  256.                 this._iconIndex = 0;
  257.         } else {
  258.                 this._iconIndex = $gamePlayer.actionIconTarget.iconId;
  259.         };
  260.  
  261.         var pw = Window_Base._iconWidth;
  262.     var ph = Window_Base._iconHeight;
  263.         var sx = this._iconIndex % 16 * pw;
  264.     var sy = Math.floor(this._iconIndex / 16) * ph;
  265.  
  266.         this.bitmap = new Bitmap(pw,ph);
  267.         if (this._iconIndex <= 0) return;
  268.     var bitmap = ImageManager.loadSystem('IconSet');
  269.     this.bitmap.blt(bitmap, sx, sy, pw, ph, 0, 0);
  270.  
  271.         Galv.AI.needRefresh = false;
  272. };
  273.  
  274. Sprite_ActionIcon.prototype.initPopVars = function() {
  275.         this.scale.y = 0.1;
  276.         this.opacity = 0;
  277.         this.mod = 0.2;
  278.         this._float = 0.1;
  279. };
  280.  
  281. if (Galv.AI.autoHide) {
  282.         Sprite_ActionIcon.prototype.updateOpacity = function() {
  283.                 if ($gameMap.isEventRunning()) {
  284.                         this.opacity -= 40;
  285.                 } else {
  286.                         this.opacity = $gameSystem.actionIndicatorVisible ?
  287.  
  288. Galv.AI.opacity : 0;
  289.                 };
  290.         };
  291. } else {
  292.         Sprite_ActionIcon.prototype.updateOpacity = function() {
  293.                 this.opacity = $gameSystem.actionIndicatorVisible ?
  294.  
  295. Galv.AI.opacity : 0;
  296.         };
  297. };
  298.  
  299. Sprite_ActionIcon.prototype.update = function() {
  300.     Sprite.prototype.update.call(this);
  301.  
  302.         if (Galv.AI.needRefresh) Galv.AI.checkActionIcon();
  303.  
  304.         if ($gamePlayer.actionIconTarget.eventId != this._eventId) {
  305.                 this.initPopVars();
  306.                 this._eventId = $gamePlayer.actionIconTarget.eventId;
  307.         }
  308.  
  309.         if (this._iconIndex !== $gamePlayer.actionIconTarget.iconId)
  310.  
  311. this.changeBitmap();
  312.         if (this._iconIndex <= 0) return;
  313.  
  314.  
  315.         this.x = $gameMap.event($gamePlayer.actionIconTarget.eventId).screenX() +
  316.  
  317. this._offsetX;
  318.         this.y = $gameMap.event($gamePlayer.actionIconTarget.eventId).screenY() +
  319.  
  320. this._offsetY + this._float;
  321.  
  322.         this.scale.y = Math.min(this.scale.y + 0.1,1);
  323.  
  324.         this.updateOpacity();
  325.  
  326.         this._float += this.mod;
  327.         if (this._float < -0.1) {
  328.                 this.mod = Math.min(this.mod + 0.01,0.2);
  329.         } else if (this._float >= 0.1) {
  330.                 this.mod = Math.max(this.mod + -0.01,-0.2);
  331.         };
  332.  
  333. };
  334.  
  335. })();


作者: 夏小堕    时间: 2023-4-6 17:07
求助
作者: RyanYe    时间: 2023-4-6 19:20
根据楼主的需求来看,根本不适合使用这个插件
我建议楼主去使用MOG_EventIndicators
作者: 夏小堕    时间: 2023-4-6 21:05
RyanYe 发表于 2023-4-6 19:20
根据楼主的需求来看,根本不适合使用这个插件
我建议楼主去使用MOG_EventIndicators ...

好的,感谢




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1