| 赞 | 6 |
| VIP | |
| 好人卡 | |
| 积分 | 3 |
| 经验 | |
| 最后登录 | 2018-9-19 |
| 在线时间 | 204 小时 |
- 梦石
- 0
- 星屑
- 311
- 在线时间
- 204 小时
- 注册时间
- 2007-2-4
- 回帖
- 1772
|
发表于 2016-8-31 11:34:27
|
显示全部楼层
本帖最后由 玄天 于 2016-8-31 11:38 编辑
你这个效果用全局变量类型的插件就行了。
比如这个插件的功能大概就是指定某些变量为全局保存,即不管你游戏进度如何,这个变量都会保持在最后更新的状态。这样你只要在需要分歧的地方加个条件分歧就行了,很简单。
[pre lang="javascript" file="MrTS_GlobalSavesData.js"]//=============================================================================
// MrTS_GlobalSavesData.js
//=============================================================================
/*:
* @plugindesc Allows player to set and change variables that affect all saves.
* @author Mr. Trivel
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial non-commercial projects.
* --------------------------------------------------------------------------------
* Version 1.0
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* GlobalVar Set [NAME] [VALUE] - Sets variable to [VALUE]
* GlobalVar Add [NAME] [VALUE] - Adds [VALUE] to variable
* GlobalVar Sub [NAME] [VALUE] - Subtracts [VALUE] from value
*
* [NAME] - Variable name, case sensitive
* [VALUE] - Value of variable a number or true/false
*
* Examples:
* GlobalVar Set Glasses true
*
* GlobalVar Set GameCompleted 1
* GlobalVar Add GameCompleted 1
* GlobalVar Sub GameCompleted 2
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Script Calls - for use in switches, variables, branches and script calls
* --------------------------------------------------------------------------------
* DataManager.getGlobalVar(NAME) - returns global variable of NAME
*
* Example:
* DataManager.getGlobalVar(Glasses)
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.0 - Release
*/
(function() {
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "globalvar") {
switch (args[0].toUpperCase())
{
case 'SET':
{
DataManager.setGlobalVar(args[1], eval(args[2]))
} break;
case 'ADD':
{
DataManager.addGlobalVar(args[1], Number(args[2]))
} break;
case 'SUB':
{
DataManager.setGlobalVar(args[1], Number(args[2]))
} break;
}
}
};
//--------------------------------------------------------------------------
// StorageManager
//
var _StorageManager_localFilePath = StorageManager.localFilePath;
StorageManager.localFilePath = function(key) {
if (key === 'globalsavedata') return this.localFileDirectoryPath() + 'globalSaveData.rpgsave';
else return _StorageManager_localFilePath.call(this, key);
};
var _StorageManager_webStorageKey = StorageManager.webStorageKey;
StorageManager.webStorageKey = function(key) {
if (key === 'globalsavedata') return 'RPG GlobalSaveData';
else return _StorageManager_webStorageKey.call(this, key);
};
//--------------------------------------------------------------------------
// DataManager
//
var _DataManager_loadGameWithoutRescue = DataManager.loadGameWithoutRescue;
DataManager.loadGameWithoutRescue = function(savefileId) {
var success = _DataManager_loadGameWithoutRescue.call(this, savefileId);
if (success) this._globalSaveData = this.loadGlobalSaveData();
return success;
};
var _DataManager_setupNewgame = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
_DataManager_setupNewgame.call(this);
this._globalSaveData = this.loadGlobalSaveData();
};
DataManager.setGlobalVar = function(name, value) {
this._globalSaveData[name] = value;
};
DataManager.addGlobalVar = function(name, value) {
if (!this._globalSaveData[name]) this._globalSaveData[name] = 0;
this._globalSaveData[name] += value;
};
DataManager.subGlobalVar = function(name, value) {
this.addGlobalVar(name, -value);
};
DataManager.getGlobalVar = function(name) {
if (!this._globalSaveData[name]) this._globalSaveData[name] = 0;
return this._globalSaveData[name];
};
DataManager.loadGlobalSaveData = function() {
var data = StorageManager.load('globalsavedata');
if (data)
{
return JsonEx.parse(data);
}
else return {};
};
var _DataManager_saveGameWithoutRescue = DataManager.saveGameWithoutRescue;
DataManager.saveGameWithoutRescue = function(savefileId) {
var saved = _DataManager_saveGameWithoutRescue.call(this, savefileId);
if (saved) {
this.saveGlobalSaveData(this._globalSaveData);
}
return saved;
};
DataManager.saveGlobalSaveData = function(data) {
StorageManager.save('globalsavedata', JSON.stringify(data));
};
})();
[/pre]
如果觉得这个不够好还可以搜搜其他的,还有不少其他运作方式的全局变量插件。 |
评分
-
查看全部评分
|