赞 | 3 |
VIP | 0 |
好人卡 | 0 |
积分 | 6 |
经验 | 9433 |
最后登录 | 2024-9-29 |
在线时间 | 283 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 597
- 在线时间
- 283 小时
- 注册时间
- 2011-8-31
- 帖子
- 101
|
3楼
楼主 |
发表于 2023-4-7 20:04:48
|
只看该作者
这个问题解决了,最终是chatGpt帮我写了个插件,允许我可以自定义保存游戏内的任何数据,重启游戏时读取……
用户
你可以帮我写个插件,重写 DataManager.saveGame 和 DataManager.loadGame 这两个函数,使它们能够将自定义的道具、武器和装备数据写入或读取存档文件吗?
word count: 50, token estimate: 115
助手
当然,我可以为你编写这个插件。以下是一个示例插件,可以用于保存自定义的道具、武器和装备数据。
复制
//=============================================================================
// CustomDataSave.js
//=============================================================================
/*:
* @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;
}
};
})();
该插件使用 JSON 格式将自定义数据保存到存档文件中。你需要在游戏中编写你自己的代码,修改 customDataToSave 和 customDataFromSave 这两个函数以保存和读取你自己的自定义数据。
以下是个实例,我用脚本写了个随机打造装备的事件,原来打造好的装备只要重启游戏就被覆盖了,现在不会了,会被保存进存档里。
// 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;
}
}
};
chatGTP实在是太厉害了!!! |
|