/*:
* @plugindesc Allows saving and loading custom data in RPG Maker MV's save files
* @version 1.0.0
*
* @author
*
* @help
*
* This plugin allows you to save and load custom data in RPG Maker MV's save
* files. You can use it to save and load additional data such as custom items,
* weapons and armors.
*
* To use this plugin, you will need to modify the DataManager.saveGame and
* DataManager.loadGame functions to include your custom data. You can do this
* in your own plugins, or modify this plugin directly.
*
* For more information, refer to the plugin's help file.
*/
(function() {
// Stores custom data in a save file
var _DataManager_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
var contents = _DataManager_makeSaveContents.call(this);
contents.customData = this.customDataToSave();
return contents;
};
// Retrieves custom data from a save file
var _DataManager_extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
_DataManager_extractSaveContents.call(this, contents);
this.customDataFromSave(contents.customData);
};
// Saves custom data to a save file
DataManager.customDataToSave = function() {
var customData = {};
// Modify this code to include your own custom data
customData.customItems = $gameParty.customItems;
customData.customWeapons = $gameParty.customWeapons;
customData.customArmors = $gameParty.customArmors;
return JSON.stringify(customData);
};
// Loads custom data from a save file
DataManager.customDataFromSave = function(data) {
if (data) {
data = JSON.parse(data);
// Modify this code to load your own custom data
$gameParty.customItems = data.customItems;
$gameParty.customWeapons = data.customWeapons;
$gameParty.customArmors = data.customArmors;
}
};
以下是个实例,我用脚本写了个随机打造装备的事件,原来打造好的装备只要重启游戏就被覆盖了,现在不会了,会被保存进存档里。
// Saves custom data to a save file
DataManager.customDataToSave = function() {
var customData = {};
var weaponsData = [];
// Loop through each weapon data and add it to the array
for (var i = 1; i < $dataWeapons.length; i++) {
var weaponData = {};
weaponData.name = $dataWeapons[i].name;
weaponData.description = $dataWeapons[i].description;
weaponData.note = $dataWeapons[i].note;
weaponData.param2 = $dataWeapons[i].params[2];
weaponData.param4 = $dataWeapons[i].params[4];
weaponData.param6 = $dataWeapons[i].params[6];
weaponData.param7 = $dataWeapons[i].params[7];
weaponData.param0 = $dataWeapons[i].params[0];
weaponData.trait0 = $dataWeapons[i].traits[0].value;
weaponData.trait1 = $dataWeapons[i].traits[1].value;
weaponData.trait2 = $dataWeapons[i].traits[2].value;
weaponData.trait3 = $dataWeapons[i].traits[3].value;
weaponData.trait4 = $dataWeapons[i].traits[4].value;
weaponData.price = $dataWeapons[i].price;
weaponData.animationId = $dataWeapons[i].animationId;
weaponData.trait8 = $dataWeapons[i].traits[8].value;
weaponData.wtypeId = $dataWeapons[i].wtypeId;
weaponsData.push(weaponData);
}
// Add the weapons data array to the custom data object
customData.weapons = weaponsData;
return JSON.stringify(customData);
};
// Loads custom data from a save file
DataManager.customDataFromSave = function(data) {
if (data) {
data = JSON.parse(data);
var weaponsData = data.weapons;
// Loop through the weapons data and update $dataWeapons array
for (var i = 0; i < weaponsData.length; i++) {
var weaponData = weaponsData[i];
var weapon = $dataWeapons[i + 1];
weapon.name = weaponData.name;
weapon.description = weaponData.description;
weapon.note = weaponData.note;
weapon.params[2] = weaponData.param2;
weapon.params[4] = weaponData.param4;
weapon.params[6] = weaponData.param6;
weapon.params[7] = weaponData.param7;
weapon.params[0] = weaponData.param0;
weapon.traits[0].value = weaponData.trait0;
weapon.traits[1].value = weaponData.trait1;
weapon.traits[2].value = weaponData.trait2;
weapon.traits[3].value = weaponData.trait3;
weapon.traits[4].value = weaponData.trait4;
weapon.price = weaponData.price;
weapon.wtypeId = weaponData.wtypeId;
weapon.animationId = weaponData.animationId;
weapon.traits[8].value = weaponData.trait8;
}
}
};