查看: 4090|回复: 0

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

[复制链接]
梦石
18
星屑
13373
在线时间
1525 小时
注册时间
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);
* 删除本地图的所有复制事件。




[pre lang="javascript" line="1" file="HG-Spawnevent"]//-----------------------------------------------------
//
//-----------------------------------------------------
/*:
* @plugindesc 学习galv大佬写的复制事件脚本。
* @author 仇九
*
* @help
* 一共三个指令。
* 写在脚本指令里而非插件指令里!!!
* 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);
* 删除本地图的所有复制事件。
*
*/
//-----------------------------------------------------
//
//-----------------------------------------------------
var HG = HG || {};
HG.Spawn = HG.Spawn || {};
var $dataSpawnMap=null;
HG.Spawn.spawnEvent = function(mapid,eventId,x,y) {//默认为本地图的xy
        DataManager.loadSpawnMapData(0,mapid,eventId,x,y);
};
HG.Spawn.clearEvent = function(id) {
        $gameMap.clearEvent(id);
};
HG.Spawn.clearMap = function() {
        $gameMap.clearMap();
};
HG.Spawn.clearSwitches = function(mapId,eventId) {
        var switches = ['A','B','C','D'];
        for (var s = 0; s < switches.length; s++) {
                var key = mapId + "," + eventId + "," + switches;
                $gameSelfSwitches.setValue(key,false);
        };
};
DataManager.loadSpawnMapData = function(bid,mapid,eventId,x,y) {
    if (Number(mapid) > 0) {
        var src = 'Map%1.json'.format(mapid.padZero(3));
        var name='$dataSpawnMap';
        var xhr = new XMLHttpRequest();
        var url = 'data/' + src;
        xhr.open('GET', url);
        xhr.overrideMimeType('application/json');
        xhr.onload = function() {
            if (xhr.status < 400) {
                window[name] = JSON.parse(xhr.responseText);
                var object=window[name];
                var array;
                    if (object === $dataSpawnMap) {
                    DataManager.extractMetadata(object);
                    array = object.events;
                            if (Array.isArray(array)) {
                                    for (var i = 0; i < array.length; i++) {
                                            var data = array;
                                            if (data && data.note !== undefined) {
                                                    DataManager.extractMetadata(data);
                                }
                                    }
                            }
                    }
                    $gameMap.spawnEvent(bid,mapid,eventId,x,y);
            }
        };
        xhr.send();
    }
};
//-----------------------------------------------------
//
//-----------------------------------------------------
Game_Map.prototype.spawnEvent = function(bid,sourcemapid,sourceid,x,y) {
    var maxid = this._events.length;
    this._events[maxid] = new Game_SpawnEvent(bid,sourcemapid,sourceid,maxid,this._mapId,x,y);
    SceneManager._scene._spriteset.createSpawnEvent(maxid);
};
Game_Map.prototype.clearEvent = function(id) {
        this._events[id] = null;
        SceneManager._scene._spriteset.clearEvent(id);
        HG.Spawn.clearSwitches(this._mapId,id);
        this.clearId();
};
Game_Map.prototype.clearMap = function() {
        for (var i=1;i<this._events.length;i++) {
                if (this._events._sourceid!=null) {
                        $gameMap.clearEvent(i);
                        i-=1;
                }
        }
};
Game_Map.prototype.clearId = function() {
        for (var i = this._events.length - 1; i > 0; i--) {
                if (this._events === null) this._events.splice(i, 1);
        else return;
        };
};
//-----------------------------------------------------
//
//-----------------------------------------------------
Spriteset_Map.prototype.clearEvent = function(id) {
        for (var i = 0; i < this._characterSprites.length; i++) {
                var event = this._characterSprites._character;
                if (event._sourceid!=null && id == event._eventId) {
                        for (var s = 0; s < this._characterSprites._animationSprites.length; s++) {
                                this._tilemap.removeChild(this._characterSprites._animationSprites);
                        };
                        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();
        this._tilemap.addChild(this._characterSprites[sId])
};
//-----------------------------------------------------
//
//-----------------------------------------------------
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(bid,sourcemapid,sourceid,maxid,mapid,x,y) {
        this._bid = bid;
        this._sourcemapid = sourcemapid;
        this._sourceid = sourceid;
        this._eventId = maxid;
        this._mapId = mapid;
        this._sx = x;
        this._sy = y;
        this._event = $dataSpawnMap.events[this._sourceid];
        this._event.x = x;
        this._event.y = y;
        Game_Event.prototype.initialize.call(this,mapid,maxid);
        DataManager.extractMetadata(this.event());
        this.refresh();
};
Game_SpawnEvent.prototype.event = function() {
    return this._event;
};
Game_SpawnEvent.prototype.locate = function(x,y) {
    Game_Event.prototype.locate.call(this, x, y);
};
Game_SpawnEvent.prototype.bid = function() {
        return this._bid;
};[/pre]

评分

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

查看全部评分

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

本版积分规则

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

在本版发帖返回顶部