制作二周目技巧(保留队伍物品、人物属性等)
本篇分享制作思路,以RMMZ为例。通关之后,存储一个特殊的存档,里面包含着你要继承的类别。开新游戏后,通过脚本来读取这个特殊存档的内容,并覆盖掉当前游戏中的相应类别。具体代码如下,或者下载附件,使用插件管理加载。
DataManager.saveGame_2 = function(savefileId) {
$gameSystem.onBeforeSave();
const contents = this.makeSaveContents_2();/** 制作/设置存档内容*/
const saveName = this.makeSavename(savefileId);//制作/设置存档名称(不含后缀)
return StorageManager.saveObject(saveName, contents).then(() => {
this._globalInfo = this.makeSavefileInfo();
this.saveGlobalInfo(); /** 保存全局(存档里的)信息*/
return 0; //返回0代表 无报错
});
};
DataManager.loadGame_2 = function(savefileId) {
const saveName = this.makeSavename(savefileId);//制作/设置存档名称(不含后缀)
return StorageManager.loadObject(saveName).then(contents => {
this.createGameObjects_2();/** 创建游戏对象组(所有$game类)*/
this.extractSaveContents_2(contents);
this.correctDataErrors();
return 0;
});
};
DataManager.createGameObjects_2 = function() {
//$gameTemp = new Game_Temp();
//$gameSystem = new Game_System();
//$gameScreen = new Game_Screen();
//$gameTimer = new Game_Timer();
//$gameMessage = new Game_Message();
//$gameSwitches = new Game_Switches();
//$gameVariables = new Game_Variables();
//$gameSelfSwitches = new Game_SelfSwitches();
//$gameActors = new Game_Actors();
$gameParty = new Game_Party();
//$gameTroop = new Game_Troop();
//$gameMap = new Game_Map();
//$gamePlayer = new Game_Player();
};
/** 制作/设置存档内容*/
DataManager.makeSaveContents_2 = function() {
const contents = {};
//contents.system = $gameSystem;
//contents.screen = $gameScreen;
//contents.timer = $gameTimer;
//contents.switches = $gameSwitches;
//contents.variables = $gameVariables;
//contents.selfSwitches = $gameSelfSwitches;
//contents.actors = $gameActors;
contents.party = $gameParty;
//contents.map = $gameMap;
//contents.player = $gamePlayer;
return contents;
};
/** 提取保存内容* @param {object} contents 内容*/
DataManager.extractSaveContents_2 = function(contents) {
//$gameSystem = contents.system;
//$gameScreen = contents.screen;
//$gameTimer = contents.timer;
//$gameSwitches = contents.switches;
//$gameVariables = contents.variables;
//$gameSelfSwitches = contents.selfSwitches;
//$gameActors = contents.actors;
$gameParty = contents.party;
//$gameMap = contents.map;
//$gamePlayer = contents.player;
};
可以看出,我把save和load通过下标_2的形式做了一个复制。这里保留的是$gameParty = contents.party部分,里面有队伍所持的物品等。操作层面执行如下:
第1步:
使用DataManager.loadGame_2(X)存储一个序号为X的存档。
这个X建议大于你游戏中的存档上限。比如你游戏存档上限为20,那X就设定成21,这样玩家就无法通过读取存档页面来看到这个特殊存档。
第2步:
在你需要执行继承命令的地方,使用DataManager.loadGame_2(X)
需要注意的是,save、load、Objects三个函数内的contents部分需要一致,否则会报错。
页:
[1]