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

Project1

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

[原创发布] 复制事件脚本

[复制链接]

Lv5.捕梦者

梦石
16
星屑
11247
在线时间
1325 小时
注册时间
2020-3-21
帖子
357

极短23获奖

跳转到指定楼层
1
发表于 2021-3-14 19:04:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
突然想把这个自己写,自己用的脚本发出来。
单纯复制事件,相比其他同类型脚本的优点是简介方便。
缺点是因为每次复制都加载一次数据,所以可能运行速度慢,但是慢那么几毫秒应该不成问题。
若是仔细看脚本的话会发现一些多余的指令,原因是:这个脚本我自用时有一些别的功能,发布的时候删去了,但并未完全删去,方便以后拓展。

* 一共三个指令。
* 写在脚本指令里而非插件指令里!!!
* 1.
* HG.Spawn.spawnEvent(mapid,eventId,x,y);
* 将id为mapid的地图上id为eventId的事件复制到当前地图的(x,y)位置。
* 2.
* HG.Spawn.clearEvent(id);
* 删除本地图指定id的事件。
* 若是删除本事件,那么就写成HG.Spawn.clearEvent(this._eventId)
* 若在非“复制事件”的事件中执行,那么无效。
* 3.
* HG.Spawn.clearMap(id);
* 删除本地图的所有复制事件。




JAVASCRIPT 代码复制下载
  1. //-----------------------------------------------------
  2. //
  3. //-----------------------------------------------------
  4. /*:
  5.  * @plugindesc 学习galv大佬写的复制事件脚本。
  6.  * @author 仇九
  7.  *
  8.  * @help
  9.  * 一共三个指令。
  10.  * 写在脚本指令里而非插件指令里!!!
  11.  * 1.
  12.  * HG.Spawn.spawnEvent(mapid,eventId,x,y);
  13.  * 将id为mapid的地图上id为eventId的事件复制到当前地图的(x,y)位置。
  14.  * 2.
  15.  * HG.Spawn.clearEvent(id);
  16.  * 删除本地图指定id的事件。
  17.  * 若是删除本事件,那么就写成HG.Spawn.clearEvent(this._eventId)
  18.  * 若在非“复制事件”的事件中执行,那么无效。
  19.  * 3.
  20.  * HG.Spawn.clearMap(id);
  21.  * 删除本地图的所有复制事件。
  22.  *
  23.  */
  24. //-----------------------------------------------------
  25. //
  26. //-----------------------------------------------------
  27. var HG = HG || {};
  28. HG.Spawn = HG.Spawn || {};
  29. var $dataSpawnMap=null;
  30. HG.Spawn.spawnEvent = function(mapid,eventId,x,y) {//默认为本地图的xy
  31.         DataManager.loadSpawnMapData(0,mapid,eventId,x,y);
  32. };
  33. HG.Spawn.clearEvent = function(id) {
  34.         $gameMap.clearEvent(id);
  35. };
  36. HG.Spawn.clearMap = function() {
  37.         $gameMap.clearMap();
  38. };
  39. HG.Spawn.clearSwitches = function(mapId,eventId) {
  40.         var switches = ['A','B','C','D'];
  41.         for (var s = 0; s < switches.length; s++) {
  42.                 var key = mapId + "," + eventId + "," + switches[s];
  43.                 $gameSelfSwitches.setValue(key,false);
  44.         };
  45. };
  46. DataManager.loadSpawnMapData = function(bid,mapid,eventId,x,y) {
  47.     if (Number(mapid) > 0) {
  48.         var src = 'Map%1.json'.format(mapid.padZero(3));
  49.         var name='$dataSpawnMap';
  50.         var xhr = new XMLHttpRequest();
  51.         var url = 'data/' + src;
  52.         xhr.open('GET', url);
  53.         xhr.overrideMimeType('application/json');
  54.         xhr.onload = function() {
  55.             if (xhr.status < 400) {
  56.                 window[name] = JSON.parse(xhr.responseText);
  57.                 var object=window[name];
  58.                 var array;
  59.                     if (object === $dataSpawnMap) {
  60.                     DataManager.extractMetadata(object);
  61.                     array = object.events;
  62.                             if (Array.isArray(array)) {
  63.                                     for (var i = 0; i < array.length; i++) {
  64.                                             var data = array[i];
  65.                                             if (data && data.note !== undefined) {
  66.                                                     DataManager.extractMetadata(data);
  67.                                 }
  68.                                     }
  69.                             }
  70.                     }
  71.                     $gameMap.spawnEvent(bid,mapid,eventId,x,y);
  72.             }
  73.         };
  74.         xhr.send();
  75.     }
  76. };
  77. //-----------------------------------------------------
  78. //
  79. //-----------------------------------------------------
  80. Game_Map.prototype.spawnEvent = function(bid,sourcemapid,sourceid,x,y) {
  81.     var maxid = this._events.length;
  82.     this._events[maxid] = new Game_SpawnEvent(bid,sourcemapid,sourceid,maxid,this._mapId,x,y);
  83.     SceneManager._scene._spriteset.createSpawnEvent(maxid);
  84. };
  85. Game_Map.prototype.clearEvent = function(id) {
  86.         this._events[id] = null;
  87.         SceneManager._scene._spriteset.clearEvent(id);
  88.         HG.Spawn.clearSwitches(this._mapId,id);
  89.         this.clearId();
  90. };
  91. Game_Map.prototype.clearMap = function() {
  92.         for (var i=1;i<this._events.length;i++) {
  93.                 if (this._events[i]._sourceid!=null) {
  94.                         $gameMap.clearEvent(i);
  95.                         i-=1;
  96.                 }
  97.         }
  98. };
  99. Game_Map.prototype.clearId = function() {
  100.         for (var i = this._events.length - 1; i > 0; i--) {
  101.                 if (this._events[i] === null) this._events.splice(i, 1);
  102.         else return;
  103.         };
  104. };
  105. //-----------------------------------------------------
  106. //
  107. //-----------------------------------------------------
  108. Spriteset_Map.prototype.clearEvent = function(id) {
  109.         for (var i = 0; i < this._characterSprites.length; i++) {
  110.                 var event = this._characterSprites[i]._character;
  111.                 if (event._sourceid!=null && id == event._eventId) {
  112.                         for (var s = 0; s < this._characterSprites[i]._animationSprites.length; s++) {
  113.                                 this._tilemap.removeChild(this._characterSprites[i]._animationSprites[s]);
  114.                         };
  115.                         this._tilemap.removeChild(this._characterSprites[i]);
  116.                 };
  117.         };
  118. };
  119. Spriteset_Map.prototype.createSpawnEvent = function(id) {
  120.         var event = $gameMap._events[id];
  121.         var sId = this._characterSprites.length;
  122.         this._characterSprites[sId] = new Sprite_Character(event);
  123.         this._characterSprites[sId].update();
  124.         this._tilemap.addChild(this._characterSprites[sId])
  125. };
  126. //-----------------------------------------------------
  127. //
  128. //-----------------------------------------------------
  129. function Game_SpawnEvent() {
  130.     this.initialize.apply(this, arguments);
  131. }
  132. Game_SpawnEvent.prototype = Object.create(Game_Event.prototype);
  133. Game_SpawnEvent.prototype.constructor = Game_SpawnEvent;
  134.  
  135. Game_SpawnEvent.prototype.initialize = function(bid,sourcemapid,sourceid,maxid,mapid,x,y) {
  136.         this._bid = bid;
  137.         this._sourcemapid = sourcemapid;
  138.         this._sourceid = sourceid;
  139.         this._eventId = maxid;
  140.         this._mapId = mapid;
  141.         this._sx = x;
  142.         this._sy = y;
  143.         this._event = $dataSpawnMap.events[this._sourceid];
  144.         this._event.x = x;
  145.         this._event.y = y;
  146.         Game_Event.prototype.initialize.call(this,mapid,maxid);
  147.         DataManager.extractMetadata(this.event());
  148.         this.refresh();
  149. };
  150. Game_SpawnEvent.prototype.event = function() {
  151.     return this._event;
  152. };
  153. Game_SpawnEvent.prototype.locate = function(x,y) {
  154.     Game_Event.prototype.locate.call(this, x, y);
  155. };
  156. Game_SpawnEvent.prototype.bid = function() {
  157.         return this._bid;
  158. };

评分

参与人数 1+1 收起 理由
Abyssstew + 1 塞糖

查看全部评分

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

本版积分规则

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

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

GMT+8, 2024-5-16 21:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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