查看: 3948|回复: 2

[已经解决] 求救!!请大神告知MV时间移动脚本【已解决】

[复制链接]
梦石
0
星屑
875
在线时间
290 小时
注册时间
2010-9-9
回帖
53
发表于 2016-3-18 02:52:50 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 czsRwind 于 2016-3-18 11:18 编辑

在VA的事件指令→设置移动路线→脚本。可以用moveto(x,y)设置自动移动。但是MV用moveto的时候,提示代码错误,请教下大神完整的脚本代码是什么。

点评

setPosition(x,y)  发表于 2016-3-18 08:03
梦石
0
星屑
1309
在线时间
904 小时
注册时间
2014-12-4
回帖
349
发表于 2016-3-18 08:09:49 | 显示全部楼层
本帖最后由 翻滚牛宝宝 于 2016-3-18 11:13 编辑

$gameMap.event(this._eventId).setPosition(x,y)
[pre lang="javascript"]//=============================================================================
// Smart Pathfinding
// by Shaz
// Last Updated: 2015.10.26
//=============================================================================

/*:
* @plugindesc Allows events or players to do smart Pathfinding
* @author Shaz
*
* @help
*
* This is merely a fork of Shaz's SMARTPATH plugin. I've added some extra
* functionality to be able to auto-cancel the pathfinding as well as to
* have the event interpreter WAIT while the pathing takes place.
*
* Plugin Command:
*  SmartPath eventId1 eventId2      # Makes event 1 find path to event 2
*  SmartPath eventId x y            # Makes event find a path to location x, y
*  SmartPath eventId cancel         # Cancel Pathfinding for event
*
*  event = number for specific event
*  event = 0 for "this" event
*  event = -1 for player
*  event = $gameVariables.value(x) to get the event id from variable x
*
*  x, y = coordinates or $gameVariables.value(#) to use a variable coordinate
*
* Update by DragoonKain:
*   Use Game_Interpreter.findEvent to allow specifying events by name.
*   Added Wait, Auto_Cancel and Auto_Cancel_Near.
*/

(function() {
  var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);

    if (command.toUpperCase() === 'SMARTPATH') {
      subject = this.findEvent
        ? this.findEvent(args[0])
        : this.character(eval(args[0]));

      if (args[1].toUpperCase() === 'CANCEL') {
        subject.clearTarget();
      } else if (args[1].toUpperCase() === 'WAIT') {
        if (subject._target && !subject.isOnTarget(subject._targetX, subject._targetY)) {
          this.wait(20);
          this.jumpTo(this._index-1);
        }
      } else if (args[1].toUpperCase() == 'AUTO_CANCEL') {
        subject.setTargetAutoCancel('on');
      } else if (args[1].toUpperCase() == 'AUTO_CANCEL_NEAR') {
        subject.setTargetAutoCancel('near');
      } else if (args.length > 2) {
        subject.setTarget(null, eval(args[1]), eval(args[2]));
      } else {
        var target = this.findEvent
          ? this.findEvent(args[1])
          : this.character(eval(args[1]));
        subject.setTarget(target);
      }
    }
  };

  var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  Game_CharacterBase.prototype.initMembers = function() {
    _Game_CharacterBase_initMembers.call(this);
    this._target = null;
    this._targetX = null;
    this._targetY = null;
    this._targetAutoCancel = false; // 'on', 'near', false
    this._break = false;
  };

  Game_CharacterBase.prototype.setTarget = function(target, targetX, targetY) {
    this._target = target;
    if (this._target) {
      this._targetX = this._target.x;
      this._targetY = this._target.y;
    } else {
      this._targetX = targetX;
      this._targetY = targetY;
    }
    this._targetAutoCancel = false;
  };

  Game_CharacterBase.prototype.setTargetAutoCancel = function(targetAutoCancel) {
    this._targetAutoCancel = targetAutoCancel;
  }

  Game_CharacterBase.prototype.clearTarget = function() {
    this._target = null;
    this._targetX = null;
    this._targetY = null;
  };

  Game_CharacterBase.prototype.isNearTarget = function(x, y) {
    var isNear =    Math.abs(this.x - x) <= 1 &&
                    Math.abs(this.y - y) <= 1;
    return isNear;
  }

  Game_CharacterBase.prototype.isOnTarget = function(x, y) {
    return this.x == x &&
           this.y == y;
  }

  var _Game_CharacterBase_updateStop = Game_CharacterBase.prototype.updateStop;
  Game_CharacterBase.prototype.updateStop = function() {
    _Game_CharacterBase_updateStop.call(this);

    if (this._target) {
      this._targetX = this._target.x;
      this._targetY = this._target.y;
    }

    if (this._targetX != null) {
      direction = this.findDirectionTo(this._targetX, this._targetY);
      if (direction > 0)
      {
        this.moveStraight(direction);
      }
    }

    if (this._target && this._targetAutoCancel) {
      if (this._targetAutoCancel.toUpperCase() === 'ON') {
        if (this.isOnTarget(this._targetX, this._targetY)) {
          this.clearTarget();
        }
      } else if (this._targetAutoCancel.toUpperCase() === 'NEAR') {
        if (this.isNearTarget(this._targetX, this._targetY)) {
          this.clearTarget();
        }
      }
    }
  };
})();[/pre]

点评

用插件命令 SmartPath eventId x y  发表于 2016-3-18 11:13
VA的moveto不是这样吗?需要走过去的话找插件  发表于 2016-3-18 11:10
谢谢告知,不过这个的效果是直接设置事件位置的,事件直接跳往指定位置,没有移动动画哦  发表于 2016-3-18 10:46
回复

使用道具 举报

梦石
0
星屑
875
在线时间
290 小时
注册时间
2010-9-9
回帖
53
 楼主| 发表于 2016-3-18 11:17:34 | 显示全部楼层
翻滚牛宝宝 发表于 2016-3-18 08:09
$gameMap.event(this._eventId).setPosition(x,y)
//=================================================== ...

好的,谢谢大神
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部