查看: 4161|回复: 0

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

[复制链接]
梦石
18
星屑
13427
在线时间
1526 小时
注册时间
2020-3-21
回帖
334

MZ评测员极短23获奖

发表于 2021-3-14 19:04:24 | 显示全部楼层 |阅读模式

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

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

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

* 一共三个指令。
* 写在脚本指令里而非插件指令里!!!
* 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);
* 删除本地图的所有复制事件。




  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. Game_SpawnEvent.prototype.initialize = function(bid,sourcemapid,sourceid,maxid,mapid,x,y) {
  135.         this._bid = bid;
  136.         this._sourcemapid = sourcemapid;
  137.         this._sourceid = sourceid;
  138.         this._eventId = maxid;
  139.         this._mapId = mapid;
  140.         this._sx = x;
  141.         this._sy = y;
  142.         this._event = $dataSpawnMap.events[this._sourceid];
  143.         this._event.x = x;
  144.         this._event.y = y;
  145.         Game_Event.prototype.initialize.call(this,mapid,maxid);
  146.         DataManager.extractMetadata(this.event());
  147.         this.refresh();
  148. };
  149. Game_SpawnEvent.prototype.event = function() {
  150.     return this._event;
  151. };
  152. Game_SpawnEvent.prototype.locate = function(x,y) {
  153.     Game_Event.prototype.locate.call(this, x, y);
  154. };
  155. Game_SpawnEvent.prototype.bid = function() {
  156.         return this._bid;
  157. };
复制代码

评分

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

查看全部评分

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

本版积分规则

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

在本版发帖返回顶部