查看: 6922|回复: 11

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

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

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

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

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

请过路的高手、大神们指点一二。
梦石
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
星屑
4623
在线时间
1207 小时
注册时间
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
星屑
45699
在线时间
7948 小时
注册时间
2009-7-6
回帖
13337

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/
[pre lang="javascript" line="1" file="GALV_EventSpawner.js"]//-----------------------------------------------------------------------------
//  Galv's Event Spawner
//-----------------------------------------------------------------------------
//  For: RPGMAKER MV
//  GALV_EventSpawner.js
//-----------------------------------------------------------------------------
//  2017-01-21 - Version 1.5 - bug fix clearing saved events on different map
//  2016-11-08 - Version 1.4 - corrected false info in help file
//  2016-07-25 - Version 1.3 - create event note meta when events spawn now
//  2016-05-21 - Version 1.2 - added compatibility with tower defense plugin
//  2016-05-15 - Version 1.1 - fixed a bug where events wouldn't spawn at y2
//  2016-05-15 - Version 1.0 - release
//-----------------------------------------------------------------------------
// Terms can be found at:
// galvs-scripts.com
//-----------------------------------------------------------------------------

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

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

//-----------------------------------------------------------------------------
/*:
* @plugindesc (v.1.5) Spawn events from a specified spawn map to a desired location.
*
* @author Galv - galvs-scripts.com
*
* @param Spawn Map Id
* @desc The map ID of the map you are using to store spawnable events
* @default 0
*
* @help
*   Galv's Event Spawner
* ----------------------------------------------------------------------------
* This plugin allows you to copy events from a specified 'spawn' map and
* duplicate them onto the current map. This spawn map is designated with the
* "Spawn Map Id" plugin setting.
* You can spawn to an x,y location or a random region ID.
*
* When spawning an event, it's important to know that if the location is
* blocked by impassible terrain, the player or any other event - it will not
* spawn unless you have previously changed Galv.SPAWN.overlap script call to
* one of the settings that allows it to overlap things.
*
* If you set the s variable to true in the script calls (below), that event
* will be 'saved' and exist until it is cleared. The event is saved where it
* is spawned and will not save it's x,y position if it moves and the player
* leaves the map (like normal events).
*
* Self switches work for all spawned events while they exist.
*
* ----------------------------------------------------------------------------
*  SCRIPT commands
* ----------------------------------------------------------------------------
*
*    Galv.SPAWN.event(id,x,y,s);       // Spawn event to x,y coords
*                                      // s = true to save event
*                                      // leave s out completely to not save
*
*    Galv.SPAWN.event(id,r,s);         // Spawn event to random region tile
*                                      // s = true to save event
*                                      // leave s out completely to not save
*
*    Galv.SPAWN.event(id,[r,r,r],s);   // Spawn event to a random region tile
*                                      // from the array list.
*                                       // s = true to save event
*                                      // leave s out completely to not save
*
*    Galv.SPAWN.overlap = type;        // can be one of the following:
*                                      // 'all' spawns over characters/terrain
*                                      // 'terrain' any terrain, no characters
*                                      // 'chars' any characters, no terrain
*                                      // 'none' spawns on empty tiles only
*                                      // events spawned after changing this
*                                      // will use the new overlap type
*
*
*    Galv.SPAWN.clear(mapId);         // Remove normal spawned events from map
*    Galv.SPAWN.clear(mapId,true);    // Remove ALL spawned events inc. saved
*                                     // Make MapID = 0 to clear current map
*
*    Galv.SPAWN.unspawn(this);        // Unspawns event code is executed in.
*
* ----------------------------------------------------------------------------
* EXAMPLES
* Galv.SPAWN.event(4,6,6);        // spawn event 4 at x6, y6, not saved
* Galv.SPAWN.event(1,12,true);    // spawn event 1 on random region 12, saved
* Galv.SPAWN.event(7,[2,3]);      // spawn event 7 on region 2 or 3, not saved
* Galv.SPAWN.overlap = 'chars';   // all events will spawn on top of other
*                                 // characters from now on.
* ----------------------------------------------------------------------------
*/

//-----------------------------------------------------------------------------
//  CODE STUFFS
//-----------------------------------------------------------------------------

(function() {


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

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

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

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

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

Galv.SPAWN.randomRegion = function(regions) {
        if (regions.constructor != Array) {
                var regions = [regions];
        };
        var possible = [];
        var width = $gameMap.width();
        var height = $gameMap.height();
        for (var x = 0; x < width; x++) {
                for (var y = 0; y < height; y++) {
                        if (Galv.SPAWN.canSpawnOn(x,y,regions)) possible.push([x,y]);
                };
        };
        // Randomize between possible spawning coordinates
        return possible[Math.floor(Math.random() * possible.length)];
};

Galv.SPAWN.canSpawnOn = function(x,y,regions) {
        var region = $gameMap.regionId(x,y);
        if (regions && !regions.contains(region)) return false;                              // Incorrect region
        if (Galv.SPAWN.overlap != 'all') {
                if (Galv.SPAWN.overlap != 'chars') {
                        if ($gameMap.eventsXy(x, y).length > 0) return false;                        // No spawning on other events
                        if ($gamePlayer.x == x && $gamePlayer.y == y) return false;                  // No spawning on player
                        if (Game_CharacterBase.prototype.isCollidedWithVehicles(x,y)) return false;  // No colliding with vehicles
                };
                if (Galv.SPAWN.overlap != 'terrain') {
                        if (!$gameMap.isPassable(x,y)) return false;
                };
        };
        return true;
};

Galv.SPAWN.clear = function(mapId,clearSaved) {
        var mapId = mapId || $gameMap._mapId; // 0 is to target current map
        if (mapId == $gameMap._mapId) {
                // same map clear
                if (Galv.SPAWN.onScene()) SceneManager._scene._spriteset.clearSpawnedEvents(clearSaved);
                $gameMap.clearSpawnedEvents(mapId,clearSaved);
        } else if (clearSaved) {
                // clear save on another map
                var sEvents = $gameMap._savedSpawnedEvents[mapId]
                for (var eId in sEvents) {
                        Galv.SPAWN.clearSSwitches(mapId,eId);
                }
                $gameMap._savedSpawnedEvents[mapId] = {};
        }
};

Galv.SPAWN.clearSSwitches = function(mapId,eventId) {
        for (var s = 0; s < Galv.SPAWN.sSwitches.length; s++) {
                var key = mapId + "," + eventId + "," + Galv.SPAWN.sSwitches;
                $gameSelfSwitches.setValue(key,false);
        };
};

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

//-----------------------------------------------------------------------------
// DATA MANAGER
//-----------------------------------------------------------------------------

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

DataManager.loadSpawnMapData();


//-----------------------------------------------------------------------------
// GAME MAP / SPRITESET MAP / SCENE MAP
//-----------------------------------------------------------------------------

Galv.SPAWN.Game_Map_initialize = Game_Map.prototype.initialize;
Game_Map.prototype.initialize = function() {
        this._savedSpawnedEvents = {};
        Galv.SPAWN.Game_Map_initialize.call(this);
};

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

Galv.SPAWN.Game_Map_setupEvents = Game_Map.prototype.setupEvents;
Game_Map.prototype.setupEvents = function() {
        Galv.SPAWN.Game_Map_setupEvents.call(this);
        $gameMap.setupSpawnEvents();
};

Game_Map.prototype.setupSpawnEvents = function() {
        // Adds saved spawn events to event list
        for (var eId in this._savedSpawnedEvents[this._mapId]) {
                var event = this._savedSpawnedEvents[this._mapId][eId];
                var x = event.x;
                var y = event.y;
                var id = event.id;
                this._events[eId] = new Game_SpawnEvent(this._mapId,eId,x,y,id,true);
        };
};

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


Game_Map.prototype.spawnedEvents = function(includeSaved) {
        var array = [];
        for (var i = 0; i < this._events.length; i++) {
                if (this._events && this._events.isSpawnEvent) {
                        if (!this._events.isSavedEvent || (this._events.isSavedEvent && includeSaved)) {
                                array.push(i);
                        };
                };
        };
        return array;
};

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

Game_Map.prototype.clearSpawnedEvents = function(mapId,clearSaved) {
        // clear normal
        var sList = this.spawnedEvents(clearSaved);
        for (var i = 0; i < sList.length; i++) {
                var eId = this._events[sList]._eventId;
                // clear self switches
                Galv.SPAWN.clearSSwitches(mapId,eId);
                // remove event
                this._events[sList] = null;
                // remove from saved list
                delete(this._savedSpawnedEvents[this._mapId][eId]);
        };
        // remove all null events from end of event to prevent array bloat
        this.removeNullEvents();
};

Game_Map.prototype.removeNullEvents = function() {
        for (var i = this._events.length - 1; i > 0; i--) {
                if (this._events === null) {
                        this._events.splice(i, 1);
                } else {
                        break;
                };
        };
};


// SPRITESET

Spriteset_Map.prototype.unspawnEvent = function(eId) {
        for (var i = 0; i < this._characterSprites.length; i++) {
                var event = this._characterSprites._character;
                if (event.isSpawnEvent && eId == event._eventId) {
                        this._tilemap.removeChild(this._characterSprites);
                };
        };
};

Spriteset_Map.prototype.clearSpawnedEvents = function(clearSaved) {
        for (var i = 0; i < this._characterSprites.length; i++) {
                var event = this._characterSprites._character;
                if (event.isSpawnEvent) {
                        if (!event.isSavedEvent || (event.isSavedEvent && clearSaved)) {
                                this._tilemap.removeChild(this._characterSprites);
                        };
                };
        };
};

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

})();

//-----------------------------------------------------------------------------
// SPAWN EVENT OBJECT
//-----------------------------------------------------------------------------

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

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

Game_SpawnEvent.prototype.initialize = function(mapId,eventId,x,y,spawnEventId,saveEvent) {
        this._spawnX = x;
        this._spawnY = y;
        this._spawnEventId = spawnEventId;
        this.isSpawnEvent = true;
        this.isSavedEvent = saveEvent;
        Game_Event.prototype.initialize.call(this,mapId,eventId);
        DataManager.extractMetadata(this.event());
};

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

Game_SpawnEvent.prototype.locate = function() {
        var x = this._spawnX;
        var y = this._spawnY;
    Game_Event.prototype.locate.call(this, x, y);
};
[/pre]
回复

使用道具 举报

梦石
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.

在本版发帖返回顶部