//============================================================================= // DynamicVariables.js // ---------------------------------------------------------------------------- // (C)2016 Triacontane // This software is released under the MIT License. // http://opensource.org/licenses/mit-license.php // ---------------------------------------------------------------------------- // Version // 1.4.0 2024/05/16 ゲーム変数、スイッチを参照するローカル変数の定義を追加、誤ったヘルプの記載を削除 // 1.3.0 2020/10/18 MZ版としてリファクタリング。MV版からメモ欄の仕様を変更 // 1.2.0 2020/10/18 リファクタリングとヘルプの整理 // 1.1.1 2018/09/27 テストプレー時はパラメータ「例外処理」の値に関係なくスクリプトエラーで異常終了しないよう修正 // 1.1.0 2018/08/19 イベントページの出現条件および敵キャラの行動パターンで各オブジェクトおよびデータを参照できる機能を追加 // 1.0.5 2018/01/27 1.0.4の更新でもともと入っていた値の取得方法をvalueに変更 // 1.0.4 2018/01/15 実行時に対象スイッチIDおよび代入されているもとの値を参照できる機能を追加 // 1.0.3 2017/08/12 パラメータの型指定機能に対応 // 1.0.2 2016/11/04 指定範囲外のスイッチの値を正しく返していなかった問題を修正 // 1.0.1 2016/11/01 結果が空文字の場合に0が設定されないよう修正 // 1.0.0 2016/10/27 初版 // ---------------------------------------------------------------------------- // [Blog] : https://triacontane.blogspot.jp/ // [Twitter]: https://twitter.com/triacontane/ // [GitHub] : https://github.com/triacontane/ //============================================================================= /*: @target MZ @url https://github.com/triacontane/RPGMakerMV/tree/mz_master/DynamicVariables.js @plugindesc Dynamic Variables Plugin @author Triacontane @license MIT License @help English Help Translator: munokura This is an unofficial English translation of the plugin help, created to support global RPG Maker users. Feedback is welcome to improve translation quality (see: https://github.com/munokura/triacontane-MZ-plugins ). Original plugin by Triacontane. Please check the latest official version at: https://triacontane.blogspot.com ----- When referencing a variable or switch within the specified range Returns the result of evaluating the "variable name" and "switch name" as a script. In addition to control characters, the following local variables can be used in scripts. id # Target switch, variable ID value # Target switch, variable ID's original value When referencing a switch in the appearance conditions of an event page, the following variables can be used. e # Reference to the event object d # Reference to the event data When referencing a switch in an enemy character's behavior pattern, the following variables can be used. e # Reference to the enemy character object d # Reference to the enemy character data The following variables can be used regardless of the situation. v # Reference to the game variable object s # Reference to the game switch object Dynamic variables are valid in all places where variables and switches are referenced (see below). Examples of referencing variables and switches 1. Event page determination process 2. Enemy character action determination process 3. Conditional branching 4. Event command operands 5. References by other plugins You can also reference dynamic variables and switches within a script. However, attempting to reference a variable (switch) with the same number will result in a circular reference and an error. Originally, the event page determination process would only be executed when any switch or variable is changed. This plugin changes the page determination process to run every frame if you set even one dynamic switch or dynamic variable as a page appearance condition. This process slightly degrades performance, so if you don't want it to run every frame even when using a dynamic switch, please specify the following in the notes field: This plugin does not have any plugin commands. Terms of Use: You may modify and redistribute this plugin without permission, and there are no restrictions on its use (commercial, R18, etc.). This plugin is now yours. @param DynamicSwitchStart @text Dynamic switch start position @desc The starting position number of the dynamic switch. @type switch @default 0 @param DynamicSwitchEnd @text Dynamic switch end position @desc End position number of the dynamic switch. @type switch @default 0 @param DynamicVariableStart @text Dynamic variable start position @desc The starting position number of the dynamic variable. @type variable @default 0 @param DynamicVariableEnd @text Dynamic variable end position @desc The ending position number of the dynamic variable. @type variable @default 0 @param ValidException @text Exception Handling @desc Exception handling will be performed when the script is executed. Invalid scripts will no longer be forcibly terminated, but the execution speed will be slightly reduced. @type boolean @default false */ /*:ja @plugindesc 動的変数プラグイン @target MZ @url https://github.com/triacontane/RPGMakerMV/tree/mz_master/DynamicVariables.js @base PluginCommonBase @author トリアコンタン @param DynamicSwitchStart @text 動的スイッチ開始位置 @desc 動的スイッチの開始位置番号です。 @default 0 @type switch @param DynamicSwitchEnd @text 動的スイッチ終了位置 @desc 動的スイッチの終了位置番号です。 @default 0 @type switch @param DynamicVariableStart @text 動的変数開始位置 @desc 動的変数の開始位置番号です。 @default 0 @type variable @param DynamicVariableEnd @text 動的変数終了位置 @desc 動的変数の終了位置番号です。 @default 0 @type variable @param ValidException @text 例外処理 @desc スクリプト実行時に例外処理を行います。不正なスクリプトで強制終了しなくなる代わりに実行速度が僅かに低下します。 @default false @type boolean @help 指定範囲内の変数、スイッチを参照したとき 「変数名称」及び「スイッチ名称」をスクリプトとして評価した結果を返します。 スクリプト中では制御文字のほか以下のローカル変数が利用できます。 id # 処理対象のスイッチ、変数ID value # 処理対象のスイッチ、変数IDにもともと入っていた値 イベントページの出現条件でスイッチを参照する場合、以下の変数が使えます。 e # イベントオブジェクトへの参照 d # イベントデータへの参照 敵キャラの行動パターンでスイッチを参照する場合、以下の変数が使えます。 e # 敵キャラオブジェクトへの参照 d # 敵キャラデータへの参照 使用する局面を問わず、以下の変数が使えます。 v # ゲーム変数オブジェクトへの参照 s # ゲームスイッチオブジェクトへの参照 動的変数は、変数およびスイッチを参照するすべての箇所(※)で有効です。 ※ 変数・スイッチを参照する例 1. イベントページの決定処理 2. 敵キャラの行動決定処理 3. 条件分岐 4. イベントコマンドの各種オペランド 5. その他プラグインによる参照 スクリプト中でさらに動的変数およびスイッチを参照することもできますが 同じ番号の変数(スイッチ)を参照しようとすると循環参照となりエラーが発生します。 本来、イベントのページを決定する処理は、いずれかのスイッチもしくは変数が 変更されたときにのみ実行されます。 本プラグインではページの出現条件に動的スイッチ、動的変数をひとつでも 設定するとページ決定処理を毎フレーム実行するよう変更します。 この処理は僅かながらパフォーマンスを低下させるため、動的スイッチを指定した 場合も毎フレーム実行したくない場合は、以下のメモ欄を指定してください。 このプラグインにはプラグインコマンドはありません。 利用規約: 作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等) についても制限はありません。 このプラグインはもうあなたのものです。 */ (function() { 'use strict'; const script = document.currentScript; const param = PluginManagerEx.createParameter(script); // eval参照用 let e = null; let d = null; //============================================================================= // Game_Variables // 動的変数の取得処理を追加定義します。 //============================================================================= const _Game_Variables_value = Game_Variables.prototype.value; Game_Variables.prototype.value = function(variableId) { const value = _Game_Variables_value.apply(this, arguments); if (this.isDynamic(variableId)) { return this.getDynamicValue($dataSystem.variables[variableId], variableId, value); } else { return value; } }; Game_Variables.prototype.isDynamic = function(variableId) { return variableId >= param.DynamicVariableStart && variableId <= param.DynamicVariableEnd; }; Game_Variables.prototype.getOriginalValue = function(variableId) { return _Game_Variables_value.apply(this, arguments); }; Game_Variables.prototype.getDynamicValue = function(dynamicScript, id, value) { if (!dynamicScript) { return value; } const v = $gameVariables.value.bind($gameVariables); const s = $gameSwitches.value.bind($gameSwitches); if (param.ValidException || $gameTemp.isPlaytest()) { try { return eval(dynamicScript); } catch (e) { console.error(e.message); return 0; } } else { return eval(dynamicScript); } }; //============================================================================= // Game_Switches // 動的スイッチの取得処理を追加定義します。 //============================================================================= const _Game_Switches_value = Game_Switches.prototype.value; Game_Switches.prototype.value = function(switchId) { const value = _Game_Switches_value.apply(this, arguments); if (this.isDynamic(switchId)) { return !!this.getDynamicValue($dataSystem.switches[switchId], switchId, value); } else { return value; } }; Game_Switches.prototype.isDynamic = function(switchId) { return switchId >= param.DynamicSwitchStart && switchId <= param.DynamicSwitchEnd; }; Game_Switches.prototype.getOriginalValue = function(switchId) { return _Game_Switches_value.apply(this, arguments); }; Game_Switches.prototype.getDynamicValue = Game_Variables.prototype.getDynamicValue; //============================================================================= // Game_Event // 必要な場合、イベントページを毎フレームリフレッシュします。 //============================================================================= const _Game_Event_initialize = Game_Event.prototype.initialize; Game_Event.prototype.initialize = function(mapId, eventId) { _Game_Event_initialize.apply(this, arguments); this._needsAlwaysRefresh = this.isNeedAlwaysRefresh(); }; Game_Event.prototype.isNeedAlwaysRefresh = function() { if (PluginManagerEx.findMetaValue(this.event(), 'NoRefresh')) { return false; } const pages = this.event().pages; if (!pages) { return false; } return pages.some(page => this.isDynamicConditionPage(page)); }; Game_Event.prototype.isDynamicConditionPage = function(page) { const c = page.conditions; if (c.switch1Valid && $gameSwitches.isDynamic(c.switch1Id)) { return true; } else if (c.switch2Valid && $gameSwitches.isDynamic(c.switch2Id)) { return true; } else if (c.variableValid && $gameVariables.isDynamic(c.variableId)) { return true; } return false; }; const _Game_Event_update = Game_Event.prototype.update; Game_Event.prototype.update = function() { if (this._needsAlwaysRefresh) { this.refresh(); } _Game_Event_update.apply(this, arguments); }; const _Game_Event_meetsConditions = Game_Event.prototype.meetsConditions; Game_Event.prototype.meetsConditions = function(page) { e = this; d = this.event(); const result = _Game_Event_meetsConditions.apply(this, arguments); e = null; d = null; return result; }; /** * Game_Enemy * 敵キャラ情報をスクリプト実行用に記憶します。 */ const _Game_Enemy_meetsSwitchCondition = Game_Enemy.prototype.meetsSwitchCondition; Game_Enemy.prototype.meetsSwitchCondition = function(param) { e = this; d = this.enemy(); const result = _Game_Enemy_meetsSwitchCondition.apply(this, arguments); e = null; d = null; return result; }; })();