查看: 5154|回复: 5

[原创发布] 复制事件,离开地图保存事件位置和方向

[复制链接]
梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2015-12-2 14:11:25 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 汪汪 于 2015-12-3 21:45 编辑

单纯保存位置方向


  1. //=============================================================================
  2. // baocun_event_xyd.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc 保存事件位置朝向
  6. * @author wangwang
  7. *
  8. * @param baocunbl
  9. * @desc 默认保存地图事件的变量号
  10. * @default 1
  11. *
  12. * @help
  13. * 大概没用........
  14. * 保存事件的位置 和 朝向,
  15. *
  16. *
  17. */




  18. (function() {
  19. //====================修改默认部分=================
  20. //对 默认的 $gameMap.prototype.setupEvents 安装事件进行修改
  21. Game_Map.prototype.setupEvents = function() {
  22.     this._events = [];
  23.     for (var i = 0; i < $dataMap.events.length; i++) {
  24.         if ($dataMap.events[i]) {
  25.             this._events[i] = new Game_Event(this._mapId, i);
  26.         }
  27.     }
  28.     this.ww_loadEvents()//添加部分,读取事件记录

  29.     this._commonEvents = this.parallelCommonEvents().map(function(commonEvent) {
  30.         return new Game_CommonEvent(commonEvent.id);
  31.     });
  32.     this.refreshTileEvents();
  33. };


  34. //转换场景时的处理(添加保存事件)
  35. Scene_Map.prototype.stop = function() {   
  36.         this.ww_saveEventsXyd()//添加部分,保存事件
  37.        
  38.     Scene_Base.prototype.stop.call(this);
  39.     $gamePlayer.straighten();
  40.     this._mapNameWindow.close();
  41.     if (this.needsSlowFadeOut()) {
  42.         this.startFadeOut(this.slowFadeSpeed(), false);
  43.     } else if (SceneManager.isNextScene(Scene_Map)) {
  44.         this.fadeOutForTransfer();
  45.     } else if (SceneManager.isNextScene(Scene_Battle)) {
  46.         this.launchBattle();
  47.     }
  48. };



  49. //===================================================================


  50. //====================添加部分====================


  51. //读取事件记录
  52. Game_Map.prototype.ww_loadEvents = function() {
  53.         //读取变量
  54.     var blid = parseInt(PluginManager.parameters("baocun_event_xyd")["baocunbl"], 10);
  55.     var value = $gameVariables._data[blid]
  56.     //如果存在
  57.     if (!!value){
  58.             //如果这个地图有保存
  59.             if (!!value[this._mapId]){
  60.                     //循环所有地图内的事件记录
  61.                     for (var i=0; i <  value[this._mapId].length ;i++){
  62.                             //读取一条事件记录的内容
  63.                             var  nr = value[this._mapId][i]
  64.                             //如果存在内容
  65.                                 if (!!nr){
  66.                                     //如果  事件x和y 是数字
  67.                                         if (isFinite( nr.x ) && isFinite(nr.y) ){
  68.                                                 //设置事件的新位置
  69.                                                 this._events[i].setPosition(nr.x,nr.y)
  70.                                         }
  71.                                         //如果 事件方向是数字
  72.                                         if (isFinite( nr.d )){
  73.                                                 //设置事件方向
  74.                                                 this._events[i].setDirection(nr.d)
  75.                                         }
  76.                                 }
  77.                     }
  78.             }
  79.     }
  80. };

  81. //保存事件记录
  82. Scene_Map.prototype.ww_saveEventsXyd= function () {
  83.         //读取变量号
  84.         var blid = parseInt(PluginManager.parameters("baocun_event_xyd")["baocunbl"], 10);
  85.         //如果变量内容不存在,新建一个数组
  86.         if (!$gameVariables._data[blid]){$gameVariables._data[blid] = []}
  87.         var value = $gameVariables._data[blid]
  88.         var mapid = $gameMap._mapId
  89.     //变量中本地图的记录内容情况
  90.         value[mapid] = []
  91.         //循环在地图中的事件
  92.     for (var i = 0; i < $gameMap._events.length; i++) {
  93.             event = $gameMap._events[i]
  94.             if (!!event){
  95.                     //设置保存内容
  96.                     nr ={
  97.                                 x:event.x,
  98.                                    y:event.y,
  99.                                    d:event._direction
  100.                            }
  101.                     value[mapid][i] = nr
  102.             }
  103.     }
  104. }




  105. })();










复制代码











复制事件,离开地图保存事件位置和方向
修改独立开关使之支持
好像没什么用
然后谁能告诉我为什么操作开关改变事件页后的行走图设置问题.....为什么不能转变成我要的那个方向?
最后求大神教教简单快捷高效的读取某地图数据的方法,
好想制作出跨地图的事件复制啊....


  1. //=============================================================================
  2. // baocun_event_xyd.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc 复制事件,保存事件位置朝向
  6. * @author wangwang
  7. *
  8. * @param baocunbl
  9. * @desc 默认保存地图事件的变量号
  10. * @default 1
  11. *
  12. * @help
  13. * 大概没什么用........
  14. * 保存事件的位置 和 朝向,
  15. * 添加一个基于本地图上事件的 事件(复制)
  16. * addEvent (eventId,x,y,d)
  17. *    eventId  复制的事件id
  18. *    事件的x,y
  19. *    d 事件朝向,请在(2468)之中
  20. *
  21. */



  22. (function() {
  23. //====================修改默认部分=================
  24. //对 默认的 $gameMap.prototype.setupEvents 安装事件进行修改
  25. Game_Map.prototype.setupEvents = function() {
  26.     this._events = [];
  27.     for (var i = 0; i < $dataMap.events.length; i++) {
  28.         if ($dataMap.events[i]) {
  29.             this._events[i] = new Game_Event(this._mapId, i);
  30.         }
  31.     }
  32.     this.ww_loadEvents()//添加部分,读取事件记录

  33.     this._commonEvents = this.parallelCommonEvents().map(function(commonEvent) {
  34.         return new Game_CommonEvent(commonEvent.id);
  35.     });
  36.     this.refreshTileEvents();
  37. };


  38. //修改事件的初始化
  39. Game_Event.prototype.initialize = function(mapId, eventId , id) {
  40.     Game_Character.prototype.initialize.call(this);
  41.     this._mapId = mapId;
  42.     this._eventId = eventId;
  43.     this._id = id || eventId  //添加部分
  44.     this.locate(this.event().x, this.event().y);
  45.     this.refresh();
  46. };


  47. //转换场景时的处理(添加保存事件)
  48. Scene_Map.prototype.stop = function() {   
  49.         this.ww_saveEventsXyd()//添加部分,保存事件
  50.     Scene_Base.prototype.stop.call(this);
  51.     $gamePlayer.straighten();
  52.     this._mapNameWindow.close();
  53.     if (this.needsSlowFadeOut()) {
  54.         this.startFadeOut(this.slowFadeSpeed(), false);
  55.     } else if (SceneManager.isNextScene(Scene_Map)) {
  56.         this.fadeOutForTransfer();
  57.     } else if (SceneManager.isNextScene(Scene_Battle)) {
  58.         this.launchBattle();
  59.     }
  60. };



  61. Game_Interpreter.prototype.setup = function(list, eventId,id) {
  62.     this.clear();
  63.     this._mapId = $gameMap.mapId();
  64.     this._eventId = eventId || 0;
  65.     this._list = list;
  66.     this._id = id || this._eventId
  67. };




  68. Game_Event.prototype.updateParallel = function() {
  69.     if (this._interpreter) {
  70.         if (!this._interpreter.isRunning()) {
  71.             this._interpreter.setup(this.list(), this._eventId,this._id);
  72.         }
  73.         this._interpreter.update();
  74.     }
  75. };

  76. //安装开始地图事件
  77. Game_Map.prototype.setupStartingMapEvent = function() {
  78.     var events = this.events();
  79.     for (var i = 0; i < events.length; i++) {
  80.         var event = events[i];
  81.         if (event.isStarting()) {
  82.             event.clearStartingFlag();
  83.             this._interpreter.setup(event.list(), event.eventId(),event._id);
  84.             return true;
  85.         }
  86.     }
  87.     return false;
  88. };










  89. //满足条件
  90. Game_Event.prototype.meetsConditions = function(page) {
  91.     var c = page.conditions;
  92.     if (c.switch1Valid) {
  93.         if (!$gameSwitches.value(c.switch1Id)) {
  94.             return false;
  95.         }
  96.     }
  97.     if (c.switch2Valid) {
  98.         if (!$gameSwitches.value(c.switch2Id)) {
  99.             return false;
  100.         }
  101.     }
  102.     if (c.variableValid) {
  103.         if ($gameVariables.value(c.variableId) < c.variableValue) {
  104.             return false;
  105.         }
  106.     }
  107.     //修改独立开关的判断条件  
  108.     if (c.selfSwitchValid) {
  109.             // _eventId  ->   _id
  110.         var key = [this._mapId,this._id, c.selfSwitchCh];
  111.         if ($gameSelfSwitches.value(key) !== true) {
  112.             return false;
  113.         }
  114.     }
  115.     if (c.itemValid) {
  116.         var item = $dataItems[c.itemId];
  117.         if (!$gameParty.hasItem(item)) {
  118.             return false;
  119.         }
  120.     }
  121.     if (c.actorValid) {
  122.         var actor = $gameActors.actor(c.actorId);
  123.         if (!$gameParty.members().contains(actor)) {
  124.             return false;
  125.         }
  126.     }
  127.     return true;
  128. };

  129. // Common Event 公共事件
  130. Game_Interpreter.prototype.command117 = function() {
  131.     var commonEvent = $dataCommonEvents[this._params[0]];
  132.     if (commonEvent) {
  133.         var eventId = this.isOnCurrentMap() ? this._eventId : 0;
  134.         var id = this.isOnCurrentMap() ? this._id : 0;
  135.         this.setupChild(commonEvent.list, eventId,id);
  136.     }
  137.     return true;
  138. };
  139. //安装子项
  140. Game_Interpreter.prototype.setupChild = function(list, eventId,id) {
  141.     this._childInterpreter = new Game_Interpreter(this._depth + 1);
  142.     this._childInterpreter.setup(list, eventId,id);
  143. };



  144. //独立开关操作(修改)
  145. Game_Interpreter.prototype.command123 = function() {
  146.     if (this._eventId > 0) {
  147.              // _eventId  ->  事件 _id
  148.         var key = [this._mapId, this._id , this._params[0]];
  149.         $gameSelfSwitches.setValue(key, this._params[1] === 0);
  150.     }
  151.     return true;
  152. };


  153. Game_Interpreter.prototype.command111 = function() {
  154.     var result = false;
  155.     switch (this._params[0]) {
  156.     case 0:  // Switch 开关
  157.         result = ($gameSwitches.value(this._params[1]) === (this._params[2] === 0));
  158.         break;
  159.     case 1:  // Variable 变量
  160.         var value1 = $gameVariables.value(this._params[1]);
  161.         var value2;
  162.         if (this._params[2] === 0) {
  163.             value2 = this._params[3];
  164.         } else {
  165.             value2 = $gameVariables.value(this._params[3]);
  166.         }
  167.         switch (this._params[4]) {
  168.         case 0:  // Equal to 等于
  169.             result = (value1 === value2);
  170.             break;
  171.         case 1:  // Greater than or Equal to  大于等于
  172.             result = (value1 >= value2);
  173.             break;
  174.         case 2:  // Less than or Equal to  小于等于
  175.             result = (value1 <= value2);
  176.             break;
  177.         case 3:  // Greater than  大于
  178.             result = (value1 > value2);
  179.             break;
  180.         case 4:  // Less than  小于
  181.             result = (value1 < value2);
  182.             break;
  183.         case 5:  // Not Equal to  不等于
  184.             result = (value1 !== value2);
  185.             break;
  186.         }
  187.         break;
  188.     case 2:  // Self Switch 独立开关
  189.         if (this._eventId > 0) {
  190.                 //修改
  191.                 
  192.             var key = [this._mapId, this._id, this._params[1]];
  193.             result = ($gameSelfSwitches.value(key) === (this._params[2] === 0));
  194.         }
  195.         break;
  196.     case 3:  // Timer  计时器
  197.         if ($gameTimer.isWorking()) {
  198.             if (this._params[2] === 0) {
  199.                 result = ($gameTimer.seconds() >= this._params[1]);
  200.             } else {
  201.                 result = ($gameTimer.seconds() <= this._params[1]);
  202.             }
  203.         }
  204.         break;
  205.     case 4:  // Actor 角色
  206.         var actor = $gameActors.actor(this._params[1]);
  207.         if (actor) {
  208.             var n = this._params[3];
  209.             switch (this._params[2]) {
  210.             case 0:  // In the Party  在队伍
  211.                 result = $gameParty.members().contains(actor);
  212.                 break;
  213.             case 1:  // Name 名称
  214.                 result = (actor.name() === n);
  215.                 break;
  216.             case 2:  // Class 职业
  217.                 result = actor.isClass($dataClasses[n]);
  218.                 break;
  219.             case 3:  // Skill 技能
  220.                 result = actor.isLearnedSkill(n);
  221.                 break;
  222.             case 4:  // Weapon 武器
  223.                 result = actor.hasWeapon($dataWeapons[n]);
  224.                 break;
  225.             case 5:  // Armor 防具
  226.                 result = actor.hasArmor($dataArmors[n]);
  227.                 break;
  228.             case 6:  // State 状态
  229.                 result = actor.isStateAffected(n);
  230.                 break;
  231.             }
  232.         }
  233.         break;
  234.     case 5:  // Enemy 敌人
  235.         var enemy = $gameTroop.members()[this._params[1]];
  236.         if (enemy) {
  237.             switch (this._params[2]) {
  238.             case 0:  // Appeared 出现
  239.                 result = enemy.isAlive();
  240.                 break;
  241.             case 1:  // State 状态
  242.                 result = enemy.isStateAffected(this._params[3]);
  243.                 break;
  244.             }
  245.         }
  246.         break;
  247.     case 6:  // Character 人物
  248.         var character = this.character(this._params[1]);
  249.         if (character) {
  250.             result = (character.direction() === this._params[2]);
  251.         }
  252.         break;
  253.     case 7:  // Gold 金钱
  254.         switch (this._params[2]) {
  255.         case 0:  // Greater than or equal to 大于等于
  256.             result = ($gameParty.gold() >= this._params[1]);
  257.             break;
  258.         case 1:  // Less than or equal to 小于等于
  259.             result = ($gameParty.gold() <= this._params[1]);
  260.             break;
  261.         case 2:  // Less than 小于
  262.             result = ($gameParty.gold() < this._params[1]);
  263.             break;
  264.         }
  265.         break;
  266.     case 8:  // Item 物品
  267.         result = $gameParty.hasItem($dataItems[this._params[1]]);
  268.         break;
  269.     case 9:  // Weapon 武器
  270.         result = $gameParty.hasItem($dataWeapons[this._params[1]], this._params[2]);
  271.         break;
  272.     case 10:  // Armor 防具
  273.         result = $gameParty.hasItem($dataArmors[this._params[1]], this._params[2]);
  274.         break;
  275.     case 11:  // Button 按键
  276.         result = Input.isPressed(this._params[1]);
  277.         break;
  278.     case 12:  // Script 脚本
  279.         result = !!eval(this._params[1]);
  280.         break;
  281.     case 13:  // Vehicle 交通工具
  282.         result = ($gamePlayer.vehicle() === $gameMap.vehicle(this._params[1]));
  283.         break;
  284.     }
  285.     this._branch[this._indent] = result;
  286.     if (this._branch[this._indent] === false) {
  287.         this.skipBranch();
  288.     }
  289.     return true;
  290. };







  291. //===================================================================


  292. //====================添加部分====================
  293. //添加事件
  294. addEvent = function (eventId,x,y,d) {
  295.         //如果这个事件id在地图数据中有基础
  296.         if ($dataMap.events[eventId]) {
  297.                 //获取添加的id
  298.             var tjid= $gameMap._events.length
  299.             //地图事件添加一个新的基于 地图数据中id事件内容 的事件
  300.                 $gameMap._events[tjid]=new Game_Event($gameMap._mapId,eventId,tjid)
  301.                 //如果x,y是数字 设置事件位置
  302.                 if (isFinite(x) && isFinite(y) ){$gameMap._events[tjid].setPosition(x,y)}
  303.                 //如果d是数字 设置事件方向(请输入:2,4,6,8)
  304.                 if (isFinite(d)) { $gameMap._events[tjid].setDirection(d)}
  305.                 //如果当前场景是 地图
  306.             if  (SceneManager._scene.constructor == Scene_Map){
  307.                     //地图场景的 精灵组 的 人物精灵 添加 一个新 人物精灵(添加的事件)
  308.                     SceneManager._scene._spriteset._characterSprites.push(new Sprite_Character($gameMap._events[tjid]))
  309.                     //获取  新添加的精灵的id
  310.                     var tjid2 = SceneManager._scene._spriteset._characterSprites.length - 1
  311.                     //把   新添加的精灵 添加到 场景 精灵组 地图 的子项
  312.                     var tjc=SceneManager._scene._spriteset._characterSprites[tjid2]
  313.                     SceneManager._scene._spriteset._tilemap.addChild(tjc);
  314.             }
  315.             $gameMap.requestRefresh()
  316.     }
  317. }



  318. //读取事件记录
  319. Game_Map.prototype.ww_loadEvents = function() {
  320.         //读取变量
  321.     var blid = parseInt(PluginManager.parameters("baocun_event_xyd")["baocunbl"], 10);
  322.     var value = $gameVariables._data[blid]
  323.     //如果存在
  324.     if (!!value){
  325.             //如果这个地图有保存
  326.             if (!!value[this._mapId]){
  327.                     //循环所有地图内的事件记录
  328.                     for (var i=0; i <  value[this._mapId].length ;i++){
  329.                             //读取一条事件记录的内容
  330.                             var  nr = value[this._mapId][i]
  331.                             //如果存在内容
  332.                                 if (!!nr){                            
  333.                                         //如果是超出原本地图内事件数量的
  334.                                         if(i >= $dataMap.events.length ){
  335.                                                 //基于原地图数据复制出一个新的事件
  336.                                                 this._events[i]=new Game_Event(this._mapId,nr[0],i)
  337.                                     }
  338.                                     //如果  事件x和y 是数字
  339.                                         if (isFinite( nr[1] ) && isFinite(nr[2]) ){
  340.                                                 //设置事件的新位置
  341.                                                 this._events[i].setPosition(nr[1],nr[2])
  342.                                         }
  343.                                         //如果 事件方向是数字
  344.                                         if (isFinite( nr[3] )){
  345.                                                 //设置事件方向
  346.                                                 this._events[i].setDirection(nr[3])
  347.                                         }
  348.                                 }
  349.                     }
  350.             }
  351.     }
  352. };

  353. //保存事件记录
  354. Scene_Map.prototype.ww_saveEventsXyd= function () {
  355.         //读取变量号
  356.         var blid = parseInt(PluginManager.parameters("baocun_event_xyd")["baocunbl"], 10);
  357.         //如果变量内容不存在,新建一个数组
  358.         if (!$gameVariables._data[blid]){$gameVariables._data[blid] = []}
  359.         var value = $gameVariables._data[blid]
  360.         var mapid = $gameMap._mapId
  361.     //变量中本地图的记录内容情况
  362.         value[mapid] = []
  363.         //循环在地图中的事件
  364.     for (var i = 0; i < $gameMap._events.length; i++) {
  365.             event = $gameMap._events[i]
  366.             if (!!event){
  367.                     //设置保存内容
  368.                     nr =[event._eventId ,event.x,event.y,event._direction]
  369.                     value[mapid][i] = nr
  370.             }
  371.     }
  372. }




  373. })();

复制代码



















BaiduShurufa_2015-12-2_14-16-0.png
jietu201512214323837.png
jietu201512214335878.png
jietu201512214346225.png
jietu201512214432719.png
jietu201512214454690.png

评分

参与人数 1梦石 +1 收起 理由
余烬之中 + 1 原创发布

查看全部评分

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2015-12-2 14:28:55 | 显示全部楼层
不要用独立开关
用一般开关/変数做判定

点评

好吧...对这种不太懂  发表于 2015-12-2 15:30
因為独立开关只在事件中使用  发表于 2015-12-2 14:39
为什么?  发表于 2015-12-2 14:33
回复

使用道具 举报

梦石
0
星屑
90
在线时间
387 小时
注册时间
2007-7-27
回帖
4075

开拓者

发表于 2015-12-3 22:28:22 | 显示全部楼层
后面这个功能yep有……

点评

前面没有就好....学习脚本过程中,所以随便写的啦....(顺便问一下如何高效得获取其他地图里事件?)  发表于 2015-12-3 23:57
吸吸
回复

使用道具 举报

梦石
0
星屑
50
在线时间
50 小时
注册时间
2008-5-4
回帖
18
发表于 2015-12-6 20:35:42 | 显示全部楼层
如果想不保存某单个事件的位置该怎么办?

点评

最后的 if (!!event) 这里加一个判断就好。比如 if (!!event && event.id==3) 这样的  发表于 2015-12-6 20:48
回复

使用道具 举报

梦石
0
星屑
50
在线时间
50 小时
注册时间
2008-5-4
回帖
18
发表于 2015-12-6 21:00:16 | 显示全部楼层
你的意思是在脚本里写上事件ID号?脚本是全局的啊……

点评

只是举例啦……你也可以添加事件的其他信息。比如注释,名称位置等等。  发表于 2015-12-6 22:54
回复

使用道具 举报

梦石
0
星屑
50
在线时间
50 小时
注册时间
2008-5-4
回帖
18
发表于 2015-12-6 23:37:49 | 显示全部楼层
本帖最后由 龙骑兵 于 2015-12-6 23:50 编辑

明白了,和VXA的记忆位置事件差不多,只要在事件内有“不保存位置”的注释,也可以不记录

能说明下具体怎么改吗?谢谢……

点评

暂时没法用电脑,不方便……如果只是要保存事件位置功能,可以去找yep的插件。  发表于 2015-12-7 08:15
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部