设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3477|回复: 1
打印 上一主题 下一主题

[已经解决] 关于YEP_SmartJump

[复制链接]

Lv4.逐梦者

梦石
0
星屑
6422
在线时间
1557 小时
注册时间
2011-6-14
帖子
520
跳转到指定楼层
1
发表于 2016-3-16 17:06:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
智能跳跃脚本在插件管理设置跳跃步数进入游戏实测相差太大
我设置为1 在游戏里面却是跳了4.5步 求设置方法


JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // Yanfly Engine Plugins - Smart Jump
  3. // YEP_SmartJump.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.YEP_SmartJump = true;
  8.  
  9. var Yanfly = Yanfly || {};
  10. Yanfly.Jump = Yanfly.Jump || {};
  11.  
  12. //=============================================================================
  13. /*:
  14.  * @plugindesc v1.00 Adds a plugin command that enables smart jumping
  15.  * where the player cannot jump into illegal areas.
  16.  * @author Yanfly Engine Plugins
  17.  *
  18.  * @param Illegal Regions
  19.  * @desc These are the region ID's the player cannot jump on
  20.  * or past. Separate each region with a space.
  21.  * @default 0
  22.  *
  23.  * @help
  24.  * ============================================================================
  25.  * Introduction
  26.  * ============================================================================
  27.  *
  28.  * For those that may have made their own Jump system before with events, you
  29.  * may have come across the problem of being able to jump off the map, into
  30.  * places you're not supposed to go, or even on top of events that shouldn't be
  31.  * allowed to go on top of. This plugin helps faciliate eventing a Jump system
  32.  * for your RPG Maker game by introducing Smart Jumps.
  33.  *
  34.  * Smart Jumps will allow you to jump over areas, but will limit you from
  35.  * jumping on top of places you can't go, on top of normal priority events, and
  36.  * set up boundaries (such as walls) that you normally cannot jump past.
  37.  *
  38.  * ============================================================================
  39.  * Instructions - Setting Up Smart Jumps
  40.  * ============================================================================
  41.  *
  42.  * Use the Plugin Command 'SmartJump' to make the player character perform a
  43.  * Smart Jump.
  44.  *
  45.  * Inside the plugin parameters, mark the Illegal Regions your player cannot
  46.  * jump past or on and then draw them on the map. Alternatively, you can mark
  47.  * certain tile types within the Database > Tileset tab and use Terrain Tags to
  48.  * restrict where the player cannot jump.
  49.  *
  50.  * ============================================================================
  51.  * Notetags
  52.  * ============================================================================
  53.  *
  54.  * You can use these notetags to set up what Terrain Tags that the player can't
  55.  * jump on or past.
  56.  *
  57.  * Tileset Notetags:
  58.  *
  59.  *   <Illegal Jump: x>
  60.  *   <Illegal Jump: x, x, x>
  61.  *   <Illegal Jump: x to y>
  62.  *   Replace x with the terrain tags you want to forbid the player from going
  63.  *   past or landing on while doing Smart Jumps.
  64.  *
  65.  * Event Notetag:
  66.  *
  67.  *   <Illegal Jump>
  68.  *   This will prevent the player from being able to jump on or over this
  69.  *   event while doing Smart Jumps. If the event is set to Through mode, then
  70.  *   the player can jump through or onto the event.
  71.  */
  72. //=============================================================================
  73.  
  74. //=============================================================================
  75. // Parameter Variables
  76. //=============================================================================
  77.  
  78. Yanfly.Parameters = PluginManager.parameters('YEP_SmartJump');
  79. Yanfly.Param = Yanfly.Param || {};
  80.  
  81. Yanfly.Param.JumpIllegalRegion = String(Yanfly.Parameters['Illegal Regions']);
  82. Yanfly.Param.JumpIllegalRegion = Yanfly.Param.JumpIllegalRegion.split(' ');
  83. if (Yanfly.Param.JumpIllegalRegion === '') Yanfly.Param.JumpIllegalRegion = [];
  84. Yanfly.max = Yanfly.Param.JumpIllegalRegion.length;
  85. for (Yanfly.i = 0; Yanfly.i < Yanfly.max; ++Yanfly.i) {
  86.   Yanfly.Param.JumpIllegalRegion[Yanfly.i] =
  87.     parseInt(Yanfly.Param.JumpIllegalRegion[Yanfly.i]);
  88. };
  89.  
  90. //=============================================================================
  91. // DataManager
  92. //=============================================================================
  93.  
  94. Yanfly.Jump.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  95. DataManager.isDatabaseLoaded = function() {
  96.     if (!Yanfly.Jump.DataManager_isDatabaseLoaded.call(this)) return false;
  97.     this.processJumpNotetags1($dataTilesets);
  98.     return true;
  99. };
  100.  
  101. DataManager.processJumpNotetags1 = function(group) {
  102.   var note1a = /<(?:ILLEGAL JUMP):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
  103.   var note1b = /<(?:ILLEGAL JUMP):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  104.   for (var n = 1; n < group.length; n++) {
  105.     var obj = group[n];
  106.     var notedata = obj.note.split(/[\r\n]+/);
  107.  
  108.     obj.illegalJumpTag = [];
  109.  
  110.     for (var i = 0; i < notedata.length; i++) {
  111.       var line = notedata[i];
  112.       if (line.match(note1a)) {
  113.         var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  114.         obj.illegalJumpTag = obj.illegalJumpTag.concat(array);
  115.       } else if (line.match(note1b)) {
  116.         var range = Yanfly.Util.getRange(parseInt(RegExp.$1),
  117.           parseInt(RegExp.$2));
  118.         obj.illegalJumpTag = obj.illegalJumpTag.concat(range);
  119.       }
  120.     }
  121.   }
  122. };
  123.  
  124. DataManager.processJumpNotetags2 = function(obj) {
  125.   var notedata = obj.note.split(/[\r\n]+/);
  126.   obj.illegalJump = false;
  127.   for (var i = 0; i < notedata.length; i++) {
  128.     var line = notedata[i];
  129.     if (line.match(/<(?:ILLEGAL JUMP)>/i)) {
  130.       obj.illegalJump = true;
  131.     }
  132.   }
  133. };
  134.  
  135. //=============================================================================
  136. // Game_CharacterBase
  137. //=============================================================================
  138.  
  139. Game_CharacterBase.prototype.smartJump = function(distance) {
  140.     if (distance === 0) return this.jump(0, 0);
  141.     this.setupSmartJump(this.getSmartJumpDistance(distance));
  142. };
  143.  
  144. Game_CharacterBase.prototype.setupSmartJump = function(distance) {
  145.     if (this._direction === 2) {
  146.       this.jump(0, distance);
  147.     } else if (this._direction === 4) {
  148.       this.jump(-distance, 0);
  149.     } else if (this._direction === 6) {
  150.       this.jump(distance, 0);
  151.     } else if (this._direction === 8) {
  152.       this.jump(0, -distance);
  153.     }
  154. };
  155.  
  156. Game_CharacterBase.prototype.getSmartJumpDistance = function(distance) {
  157.     if (this._direction === 2) {
  158.       for (var i = 0; i < distance; ++i) {
  159.         if (this.isSmartJumpIllegalRegion(this.x, this.y + i + 1)) {
  160.           distance = i;
  161.           break;
  162.         }
  163.       }
  164.     } else if (this._direction === 4) {
  165.       for (var i = 0; i < distance; ++i) {
  166.         if (this.isSmartJumpIllegalRegion(this.x - i - 1, this.y)) {
  167.           distance = i;
  168.           break;
  169.         }
  170.       }
  171.     } else if (this._direction === 6) {
  172.       for (var i = 0; i < distance; ++i) {
  173.         if (this.isSmartJumpIllegalRegion(this.x + i + 1, this.y)) {
  174.           distance = i;
  175.           break;
  176.         }
  177.       }
  178.     } else if (this._direction === 8) {
  179.       for (var i = 0; i < distance; ++i) {
  180.         if (this.isSmartJumpIllegalRegion(this.x, this.y - i - 1)) {
  181.           distance = i;
  182.           break;
  183.         }
  184.       }
  185.     }
  186.     return this.calcSmartJumpDistance(distance);
  187. };
  188.  
  189. Game_CharacterBase.prototype.isSmartJumpIllegalRegion = function(x, y) {
  190.     if (x < 0 || y < 0) return true;
  191.     if (x > $gameMap.width() - 1 || y > $gameMap.height() - 1) return true;
  192.     if (this.isThrough()) return false;
  193.     var regionId = $gameMap.regionId(x, y);
  194.     if (regionId > 0 && Yanfly.Param.JumpIllegalRegion.contains(regionId)) {
  195.       return true;
  196.     }
  197.     var tileset = $gameMap.tileset();
  198.     if (tileset && tileset.illegalJumpTag.contains($gameMap.terrainTag(x, y))) {
  199.       return true;
  200.     }
  201.     var events = $gameMap.eventsXy(x, y);
  202.     var length = events.length;
  203.     for (var i = 0; i < length; ++i) {
  204.       var ev = events[i];
  205.       if (!ev) continue;
  206.       if (ev.isThrough()) continue;
  207.       if (ev.isSmartJumpBlocked()) return true;
  208.     }
  209.     return false;
  210. };
  211.  
  212. Game_CharacterBase.prototype.calcSmartJumpDistance = function(distance) {
  213.     var max = distance;
  214.     var value = 0;
  215.     if (this._direction === 2) {
  216.       for (var i = 0; i < max; ++i) {
  217.         if (this.isSmartJumpValid(this.x, this.y + max - i)) {
  218.           value = max - i;
  219.           break;
  220.         }
  221.       }
  222.     } else if (this._direction === 4) {
  223.       for (var i = 0; i < max; ++i) {
  224.         if (this.isSmartJumpValid(this.x - max + i, this.y)) {
  225.           value = max - i;
  226.           break;
  227.         }
  228.       }
  229.     } else if (this._direction === 6) {
  230.       for (var i = 0; i < max; ++i) {
  231.         if (this.isSmartJumpValid(this.x + max - i, this.y)) {
  232.           value = max - i;
  233.           break;
  234.         }
  235.       }
  236.     } else if (this._direction === 8) {
  237.       for (var i = 0; i < max; ++i) {
  238.         if (this.isSmartJumpValid(this.x, this.y - max + i)) {
  239.           value = max - i;
  240.           break;
  241.         }
  242.       }
  243.     }
  244.     return value;
  245. };
  246.  
  247. Game_CharacterBase.prototype.isSmartJumpValid = function(x, y) {
  248.     if (this.isThrough()) return true;
  249.     var events = $gameMap.eventsXyNt(x, y);
  250.     var length = events.length;
  251.     for (var i = 0; i < length; ++i) {
  252.       var ev = events[i];
  253.       if (!ev) continue;
  254.       if (ev.isThrough()) continue;
  255.       if (ev.isNormalPriority()) return false;
  256.       if (ev.isSmartJumpBlocked()) return false;
  257.     }
  258.     return $gameMap.isPassable(x, y, this._direction);
  259. };
  260.  
  261. //=============================================================================
  262. // Game_Event
  263. //=============================================================================
  264.  
  265. Yanfly.Jump.Game_Event_setupPageSettings =
  266.     Game_Event.prototype.setupPageSettings;
  267. Game_Event.prototype.setupPageSettings = function() {
  268.     Yanfly.Jump.Game_Event_setupPageSettings.call(this);
  269.     DataManager.processJumpNotetags2(this.event());
  270. };
  271.  
  272. Game_Event.prototype.isSmartJumpBlocked = function() {
  273.     if (this.event().illegalJump === undefined) {
  274.       DataManager.processJumpNotetags2(this.event());
  275.     }
  276.     return this.event().illegalJump;
  277. };
  278.  
  279. //=============================================================================
  280. // Game_Interpreter
  281. //=============================================================================
  282.  
  283. Yanfly.Jump.Game_Interpreter_pluginCommand =
  284.     Game_Interpreter.prototype.pluginCommand;
  285. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  286.   Yanfly.Jump.Game_Interpreter_pluginCommand.call(this, command, args);
  287.   if (command === 'SmartJump') {
  288.     $gamePlayer.smartJump(parseInt(args[0]));
  289.   }
  290. };
  291.  
  292. //=============================================================================
  293. // Utilities
  294. //=============================================================================
  295.  
  296. Yanfly.Util = Yanfly.Util || {};
  297.  
  298. Yanfly.Util.getRange = function(n, m) {
  299.     var result = [];
  300.     for (var i = n; i <= m; ++i) result.push(i);
  301.     return result;
  302. };
  303.  
  304. //=============================================================================
  305. // End of File
  306. //=============================================================================

Lv1.梦旅人

Mr.Gandum

梦石
0
星屑
226
在线时间
2070 小时
注册时间
2007-1-31
帖子
3039

贵宾

2
发表于 2016-3-16 17:13:36 | 只看该作者
本帖最后由 feizhaodan 于 2016-3-16 17:16 编辑

插件管理里面设置的数值是不可以跳上或者跳过的区域ID。。。
在呼出跳跃指令(SmartJump)的参数里面指定了跳跃距离了么?
然后看了一下脚本内容,貌似是自动寻找设置的距离之内可以着地的最远的位置进行跳跃

点评

设置了 我设置的1 但是他却是跳4.5步,我是新建的一张地图然后填充草地测试的  发表于 2016-3-16 18:12
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-12-23 19:19

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表