查看: 7141|回复: 11

[已经解决] 如何用脚本或指令新增事件?

[复制链接]
梦石
0
星屑
55
在线时间
69 小时
注册时间
2008-3-2
回帖
21
发表于 2017-5-2 16:54:33 | 显示全部楼层 |阅读模式

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

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

×
请教高手,如何通过脚本或指令来新增事件?我想通过这样的方式,来实现在地图上增加小动物。虽然了解了一些js的基础,但完全不知道该如何实现。下面是我在事件脚本里胡乱写的,没有任何效果。
  1. var x_Event = new Game_Event(1,1);
  2. x_Event.setImage("Nature",2);
  3. x_Event.setDirection(1);
  4. x_Event.setPattern(1);
  5. x_Event.locate(3,2);
  6. x_Event.update();
复制代码


请过路的高手、大神们指点一二。
梦石
0
星屑
112
在线时间
376 小时
注册时间
2015-1-26
回帖
194
发表于 2017-5-2 17:10:37 | 显示全部楼层
你还不如在编辑器里先设置好这些事件,需要的时候用开关或者变量显示出来
回复

使用道具 举报

梦石
0
星屑
55
在线时间
69 小时
注册时间
2008-3-2
回帖
21
 楼主| 发表于 2017-5-2 18:19:37 | 显示全部楼层
raketenfaust02 发表于 2017-5-2 17:10
你还不如在编辑器里先设置好这些事件,需要的时候用开关或者变量显示出来 ...

这样不行,我需要能随意增加小动物数量。
回复

使用道具 举报

梦石
0
星屑
4628
在线时间
1208 小时
注册时间
2016-4-7
回帖
944

开拓者

发表于 2017-5-3 17:52:46 | 显示全部楼层
rm的事件系统极其复杂,一个办法是在一个特定地图里设置好预定的事件。
然后在需要的时候,读取那张地图然后把需要的事件复制过来。
要记得是得把事件放到地图事件数组里。像主楼里那样只是赋值给一个局部变量,并不会起作用。
附庸的附庸不是我的附庸,女儿的女儿还是我的女儿。CK2沉迷ing
回复

使用道具 举报

梦石
0
星屑
55
在线时间
69 小时
注册时间
2008-3-2
回帖
21
 楼主| 发表于 2017-5-3 22:43:31 | 显示全部楼层
shitake 发表于 2017-5-3 17:52
rm的事件系统极其复杂,一个办法是在一个特定地图里设置好预定的事件。
然后在需要的时候,读取那张地图然 ...

非常感谢你的回复,如果能更详细解释一下就好了,或者有没有什么教程可以推荐给我学习的?
事件复制,我在某个群里得到了一位高手写的脚本,已经实现。不过,现在是自己弄明白如何编写脚本。JS的基础部分已经学完了,但是在RM里,完全看不懂,一头雾水。也不知道这些默认的构造函数,该如何具体的应用。{:2_253:}
回复

使用道具 举报

老黄鸡

梦石
4
星屑
46133
在线时间
7978 小时
注册时间
2009-7-6
回帖
13342

MZ评测员RM创作大赛01组委会开拓者贵宾

发表于 2017-5-3 23:38:04 | 显示全部楼层
你还需要把这个新建的事件加入到地图事件列表
  1. var last_id = $dataMap.events.length;
  2. var map_id = $gameMap.mapId;
  3. var spriteset = SceneManager._scene._spriteset;
  4. var eventData = {"id":1,"name":"EV020","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Nature","direction":2,"pattern":0,"characterIndex":0},"list":[{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":10,"y":10};
  5. eventData.id = last_id;eventData.x=3;eventData.y=2;
  6. $dataMap.events.push(eventData);
  7. var x_Event = new Game_Event(map_id,last_id);
  8. x_Event.update();
  9. $gameMap._events[last_id] = x_Event;
  10. var spr = new Sprite_Character(x_Event);
  11. spriteset._characterSprites.push(spr);
  12. spriteset._tilemap.addChild(spr);
复制代码

注意,这种访问方法非常不规范(而且在事件里塞这么大一坨也确实很丑),还是往各个类里添加相应功能的函数比较靠谱。
楼主的做法只是生成了一个临时事件,并没有加入地图
所以正确的做法应该是创造事件(并且创造原始数据)并添加,然后创造事件相应的精灵并添加。
RGDirect - DirectX驱动的RGSS,点我了解.
(排满,暂停)RM全系列成套系统定制请联系QQ1213237796
不接受对其他插件维护的委托
回复

使用道具 举报

梦石
0
星屑
55
在线时间
407 小时
注册时间
2011-4-10
回帖
352
发表于 2017-5-4 00:29:17 | 显示全部楼层
这个插件应该是你需要的。
https://galvs-scripts.com/2016/05/14/mv-event-spawner/
  1. //-----------------------------------------------------------------------------
  2. //  Galv's Event Spawner
  3. //-----------------------------------------------------------------------------
  4. //  For: RPGMAKER MV
  5. //  GALV_EventSpawner.js
  6. //-----------------------------------------------------------------------------
  7. //  2017-01-21 - Version 1.5 - bug fix clearing saved events on different map
  8. //  2016-11-08 - Version 1.4 - corrected false info in help file
  9. //  2016-07-25 - Version 1.3 - create event note meta when events spawn now
  10. //  2016-05-21 - Version 1.2 - added compatibility with tower defense plugin
  11. //  2016-05-15 - Version 1.1 - fixed a bug where events wouldn't spawn at y2
  12. //  2016-05-15 - Version 1.0 - release
  13. //-----------------------------------------------------------------------------
  14. // Terms can be found at:
  15. // galvs-scripts.com
  16. //-----------------------------------------------------------------------------

  17. var Imported = Imported || {};
  18. Imported.Galv_EventSpawner = true;

  19. var Galv = Galv || {};              // Galv's main object
  20. Galv.SPAWN = Galv.SPAWN || {};      // Galv's stuff

  21. //-----------------------------------------------------------------------------
  22. /*:
  23. * @plugindesc (v.1.5) Spawn events from a specified spawn map to a desired location.
  24. *
  25. * @author Galv - galvs-scripts.com
  26. *
  27. * @param Spawn Map Id
  28. * @desc The map ID of the map you are using to store spawnable events
  29. * @default 0
  30. *
  31. * @help
  32. *   Galv's Event Spawner
  33. * ----------------------------------------------------------------------------
  34. * This plugin allows you to copy events from a specified 'spawn' map and
  35. * duplicate them onto the current map. This spawn map is designated with the
  36. * "Spawn Map Id" plugin setting.
  37. * You can spawn to an x,y location or a random region ID.
  38. *
  39. * When spawning an event, it's important to know that if the location is
  40. * blocked by impassible terrain, the player or any other event - it will not
  41. * spawn unless you have previously changed Galv.SPAWN.overlap script call to
  42. * one of the settings that allows it to overlap things.
  43. *
  44. * If you set the s variable to true in the script calls (below), that event
  45. * will be 'saved' and exist until it is cleared. The event is saved where it
  46. * is spawned and will not save it's x,y position if it moves and the player
  47. * leaves the map (like normal events).
  48. *
  49. * Self switches work for all spawned events while they exist.
  50. *
  51. * ----------------------------------------------------------------------------
  52. *  SCRIPT commands
  53. * ----------------------------------------------------------------------------
  54. *
  55. *    Galv.SPAWN.event(id,x,y,s);       // Spawn event to x,y coords
  56. *                                      // s = true to save event
  57. *                                      // leave s out completely to not save
  58. *
  59. *    Galv.SPAWN.event(id,r,s);         // Spawn event to random region tile
  60. *                                      // s = true to save event
  61. *                                      // leave s out completely to not save
  62. *
  63. *    Galv.SPAWN.event(id,[r,r,r],s);   // Spawn event to a random region tile
  64. *                                      // from the array list.
  65. *                                       // s = true to save event
  66. *                                      // leave s out completely to not save
  67. *
  68. *    Galv.SPAWN.overlap = type;        // can be one of the following:
  69. *                                      // 'all' spawns over characters/terrain
  70. *                                      // 'terrain' any terrain, no characters
  71. *                                      // 'chars' any characters, no terrain
  72. *                                      // 'none' spawns on empty tiles only
  73. *                                      // events spawned after changing this
  74. *                                      // will use the new overlap type
  75. *
  76. *
  77. *    Galv.SPAWN.clear(mapId);         // Remove normal spawned events from map
  78. *    Galv.SPAWN.clear(mapId,true);    // Remove ALL spawned events inc. saved
  79. *                                     // Make MapID = 0 to clear current map
  80. *
  81. *    Galv.SPAWN.unspawn(this);        // Unspawns event code is executed in.
  82. *
  83. * ----------------------------------------------------------------------------
  84. * EXAMPLES
  85. * Galv.SPAWN.event(4,6,6);        // spawn event 4 at x6, y6, not saved
  86. * Galv.SPAWN.event(1,12,true);    // spawn event 1 on random region 12, saved
  87. * Galv.SPAWN.event(7,[2,3]);      // spawn event 7 on region 2 or 3, not saved
  88. * Galv.SPAWN.overlap = 'chars';   // all events will spawn on top of other
  89. *                                 // characters from now on.
  90. * ----------------------------------------------------------------------------
  91. */

  92. //-----------------------------------------------------------------------------
  93. //  CODE STUFFS
  94. //-----------------------------------------------------------------------------

  95. (function() {


  96. Galv.SPAWN.spawnMapId = Number(PluginManager.parameters('GALV_EventSpawner')["Spawn Map Id"]);
  97. Galv.SPAWN.overlap = 'none';
  98. Galv.SPAWN.sSwitches = ["A","B","C","D"];

  99. Galv.SPAWN.scenes = ['Scene_Map'];

  100. Galv.SPAWN.onScene = function() {
  101.         if (Galv.SPAWN.scenes.indexOf(SceneManager._scene.constructor.name) > -1) return true;
  102.         return false;
  103. };

  104. Galv.SPAWN.event = function(eventId,x,y,save) {
  105.         if (!Galv.SPAWN.onScene()) return;

  106.         if (y == undefined || y === true) {
  107.                 var save = y;
  108.                 // Spawn random region where x = array of region Id's
  109.                 var coords = Galv.SPAWN.randomRegion(x,y);
  110.                 if (coords) $gameMap.spawnEvent(eventId,coords[0],coords[1],save);
  111.         } else {
  112.                 // Spawn X,Y position
  113.                 if (Galv.SPAWN.canSpawnOn(x,y)) $gameMap.spawnEvent(eventId,x,y,save);
  114.         };
  115. };

  116. Galv.SPAWN.randomRegion = function(regions) {
  117.         if (regions.constructor != Array) {
  118.                 var regions = [regions];
  119.         };
  120.         var possible = [];
  121.         var width = $gameMap.width();
  122.         var height = $gameMap.height();
  123.         for (var x = 0; x < width; x++) {
  124.                 for (var y = 0; y < height; y++) {
  125.                         if (Galv.SPAWN.canSpawnOn(x,y,regions)) possible.push([x,y]);
  126.                 };
  127.         };
  128.         // Randomize between possible spawning coordinates
  129.         return possible[Math.floor(Math.random() * possible.length)];
  130. };

  131. Galv.SPAWN.canSpawnOn = function(x,y,regions) {
  132.         var region = $gameMap.regionId(x,y);
  133.         if (regions && !regions.contains(region)) return false;                              // Incorrect region
  134.         if (Galv.SPAWN.overlap != 'all') {
  135.                 if (Galv.SPAWN.overlap != 'chars') {
  136.                         if ($gameMap.eventsXy(x, y).length > 0) return false;                        // No spawning on other events
  137.                         if ($gamePlayer.x == x && $gamePlayer.y == y) return false;                  // No spawning on player
  138.                         if (Game_CharacterBase.prototype.isCollidedWithVehicles(x,y)) return false;  // No colliding with vehicles
  139.                 };
  140.                 if (Galv.SPAWN.overlap != 'terrain') {
  141.                         if (!$gameMap.isPassable(x,y)) return false;
  142.                 };
  143.         };
  144.         return true;
  145. };

  146. Galv.SPAWN.clear = function(mapId,clearSaved) {
  147.         var mapId = mapId || $gameMap._mapId; // 0 is to target current map
  148.         if (mapId == $gameMap._mapId) {
  149.                 // same map clear
  150.                 if (Galv.SPAWN.onScene()) SceneManager._scene._spriteset.clearSpawnedEvents(clearSaved);
  151.                 $gameMap.clearSpawnedEvents(mapId,clearSaved);
  152.         } else if (clearSaved) {
  153.                 // clear save on another map
  154.                 var sEvents = $gameMap._savedSpawnedEvents[mapId]
  155.                 for (var eId in sEvents) {
  156.                         Galv.SPAWN.clearSSwitches(mapId,eId);
  157.                 }
  158.                 $gameMap._savedSpawnedEvents[mapId] = {};
  159.         }
  160. };

  161. Galv.SPAWN.clearSSwitches = function(mapId,eventId) {
  162.         for (var s = 0; s < Galv.SPAWN.sSwitches.length; s++) {
  163.                 var key = mapId + "," + eventId + "," + Galv.SPAWN.sSwitches[s];
  164.                 $gameSelfSwitches.setValue(key,false);
  165.         };
  166. };

  167. Galv.SPAWN.unspawn = function(obj) {
  168.         var eId = Number(obj.eventId());
  169.         if ($gameMap._events[eId].isSpawnEvent) {
  170.                 $gameMap.unspawnEvent(eId);
  171.                 if (Galv.SPAWN.onScene()) SceneManager._scene._spriteset.unspawnEvent(eId); // eId undefined?
  172.         };
  173. };

  174. //-----------------------------------------------------------------------------
  175. // DATA MANAGER
  176. //-----------------------------------------------------------------------------

  177. DataManager.loadSpawnMapData = function() {
  178.         var mapId = Galv.SPAWN.spawnMapId;
  179.     if (mapId > 0) {
  180.         var filename = 'Map%1.json'.format(mapId.padZero(3));
  181.         this.loadDataFile('$dataSpawnMap', filename);
  182.     } else {
  183.         window.alert("ERROR: You didn't set a spawn map ID. Choose a map from your map list to use for the spawn map.")
  184.     }
  185. };

  186. DataManager.loadSpawnMapData();


  187. //-----------------------------------------------------------------------------
  188. // GAME MAP / SPRITESET MAP / SCENE MAP
  189. //-----------------------------------------------------------------------------

  190. Galv.SPAWN.Game_Map_initialize = Game_Map.prototype.initialize;
  191. Game_Map.prototype.initialize = function() {
  192.         this._savedSpawnedEvents = {};
  193.         Galv.SPAWN.Game_Map_initialize.call(this);
  194. };

  195. Galv.SPAWN.Game_Map_setup = Game_Map.prototype.setup;
  196. Game_Map.prototype.setup = function(mapId) {
  197.         this._savedSpawnedEvents[mapId] = this._savedSpawnedEvents[mapId] || {};
  198.         Galv.SPAWN.Game_Map_setup.call(this,mapId);
  199. };

  200. Galv.SPAWN.Game_Map_setupEvents = Game_Map.prototype.setupEvents;
  201. Game_Map.prototype.setupEvents = function() {
  202.         Galv.SPAWN.Game_Map_setupEvents.call(this);
  203.         $gameMap.setupSpawnEvents();
  204. };

  205. Game_Map.prototype.setupSpawnEvents = function() {
  206.         // Adds saved spawn events to event list
  207.         for (var eId in this._savedSpawnedEvents[this._mapId]) {
  208.                 var event = this._savedSpawnedEvents[this._mapId][eId];
  209.                 var x = event.x;
  210.                 var y = event.y;
  211.                 var id = event.id;
  212.                 this._events[eId] = new Game_SpawnEvent(this._mapId,eId,x,y,id,true);
  213.         };
  214. };

  215. Game_Map.prototype.spawnEvent = function(id,x,y,save) {
  216.         // Get highest event id available
  217.     var eId = this._events.length;
  218.         // Add event to event list
  219.     this._events[eId] = new Game_SpawnEvent(this._mapId,eId,x,y,id,save);
  220.        
  221.         // Add save data if save
  222.         if (save) this._savedSpawnedEvents[this._mapId][eId] = {id: id, x:x, y:y, eId: Number(eId)};
  223.         if (Galv.SPAWN.onScene()) SceneManager._scene._spriteset.createSpawnEvent(eId);
  224. };


  225. Game_Map.prototype.spawnedEvents = function(includeSaved) {
  226.         var array = [];
  227.         for (var i = 0; i < this._events.length; i++) {
  228.                 if (this._events[i] && this._events[i].isSpawnEvent) {
  229.                         if (!this._events[i].isSavedEvent || (this._events[i].isSavedEvent && includeSaved)) {
  230.                                 array.push(i);
  231.                         };
  232.                 };
  233.         };
  234.         return array;
  235. };

  236. Game_Map.prototype.unspawnEvent = function(eId) {
  237.         this._events[eId] = null;
  238.         Galv.SPAWN.clearSSwitches(this._mapId,eId);
  239.         delete(this._savedSpawnedEvents[this._mapId][eId]);
  240. };

  241. Game_Map.prototype.clearSpawnedEvents = function(mapId,clearSaved) {
  242.         // clear normal
  243.         var sList = this.spawnedEvents(clearSaved);
  244.         for (var i = 0; i < sList.length; i++) {
  245.                 var eId = this._events[sList[i]]._eventId;
  246.                 // clear self switches
  247.                 Galv.SPAWN.clearSSwitches(mapId,eId);
  248.                 // remove event
  249.                 this._events[sList[i]] = null;
  250.                 // remove from saved list
  251.                 delete(this._savedSpawnedEvents[this._mapId][eId]);
  252.         };
  253.         // remove all null events from end of event to prevent array bloat
  254.         this.removeNullEvents();
  255. };

  256. Game_Map.prototype.removeNullEvents = function() {
  257.         for (var i = this._events.length - 1; i > 0; i--) {
  258.                 if (this._events[i] === null) {
  259.                         this._events.splice(i, 1);
  260.                 } else {
  261.                         break;
  262.                 };
  263.         };
  264. };


  265. // SPRITESET

  266. Spriteset_Map.prototype.unspawnEvent = function(eId) {
  267.         for (var i = 0; i < this._characterSprites.length; i++) {
  268.                 var event = this._characterSprites[i]._character;
  269.                 if (event.isSpawnEvent && eId == event._eventId) {
  270.                         this._tilemap.removeChild(this._characterSprites[i]);
  271.                 };
  272.         };
  273. };

  274. Spriteset_Map.prototype.clearSpawnedEvents = function(clearSaved) {
  275.         for (var i = 0; i < this._characterSprites.length; i++) {
  276.                 var event = this._characterSprites[i]._character;
  277.                 if (event.isSpawnEvent) {
  278.                         if (!event.isSavedEvent || (event.isSavedEvent && clearSaved)) {
  279.                                 this._tilemap.removeChild(this._characterSprites[i]);
  280.                         };
  281.                 };
  282.         };
  283. };

  284. Spriteset_Map.prototype.createSpawnEvent = function(id) {
  285.         var event = $gameMap._events[id];
  286.         var sId = this._characterSprites.length;
  287.         this._characterSprites[sId] = new Sprite_Character(event);
  288.         this._characterSprites[sId].update(); // To remove occsaional full-spriteset visible issue
  289.         this._tilemap.addChild(this._characterSprites[sId]);
  290.        
  291. };

  292. })();

  293. //-----------------------------------------------------------------------------
  294. // SPAWN EVENT OBJECT
  295. //-----------------------------------------------------------------------------

  296. function Game_SpawnEvent() {
  297.     this.initialize.apply(this, arguments);
  298. }

  299. Game_SpawnEvent.prototype = Object.create(Game_Event.prototype);
  300. Game_SpawnEvent.prototype.constructor = Game_SpawnEvent;

  301. Game_SpawnEvent.prototype.initialize = function(mapId,eventId,x,y,spawnEventId,saveEvent) {
  302.         this._spawnX = x;
  303.         this._spawnY = y;
  304.         this._spawnEventId = spawnEventId;
  305.         this.isSpawnEvent = true;
  306.         this.isSavedEvent = saveEvent;
  307.         Game_Event.prototype.initialize.call(this,mapId,eventId);
  308.         DataManager.extractMetadata(this.event());
  309. };

  310. Game_SpawnEvent.prototype.event = function() {
  311.     return $dataSpawnMap.events[this._spawnEventId];
  312. };

  313. Game_SpawnEvent.prototype.locate = function() {
  314.         var x = this._spawnX;
  315.         var y = this._spawnY;
  316.     Game_Event.prototype.locate.call(this, x, y);
  317. };
复制代码
回复

使用道具 举报

梦石
0
星屑
225
在线时间
162 小时
注册时间
2015-11-23
回帖
90
发表于 2017-5-4 09:50:40 | 显示全部楼层
建议你通过 复制 现有的事件来增加
自天地未辟混沌未开时就已经开始装逼的神奇人物
MV的魔塔模板::托管在github上的游戏,可以直接运行
基于RPGMakerMV的JavaScript基础
回复

使用道具 举报

梦石
0
星屑
55
在线时间
69 小时
注册时间
2008-3-2
回帖
21
 楼主| 发表于 2017-5-4 09:51:14 | 显示全部楼层
sutao80216 发表于 2017-5-4 00:29
这个插件应该是你需要的。
https://galvs-scripts.com/2016/05/14/mv-event-spawner/
//------------------ ...

这个也是复制事件的,不过比我找到的那个功能要全一些,谢谢。
回复

使用道具 举报

梦石
0
星屑
95
在线时间
256 小时
注册时间
2011-3-14
回帖
78
发表于 2017-5-4 11:44:21 | 显示全部楼层
我是通过调用模版事件做的
用下面第一个插件把需要生成的事件放在模版地图里面
然后在新地图中用第二个插件的脚本命令动态调用

插件:
建立模版事件https://github.com/triacontane/R ... er/TemplateEvent.js
事件动态生成https://github.com/triacontane/R ... ter/EventReSpawn.js
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部