=begin ◆概要 数値入力に最大値/最小値を設けることができます。 ◆機能 ・設定項目でスイッチ/最大値変数/最小値変数を設定してください。 ・スイッチ関係なく、$game_system.variable_max_min = [最大値, 最小値]で制限を かけられます。また、$game_system.reset_variable_max_minで普通に戻ります。 ◆仕様 ・スイッチがOFFの時、$game_system.variable_max_minの制限がかかり、スイッチがONの 時、どちらかの最大値が小さいほう、最小値が大きいほうの制限がかかります。 例:$game_variable_max_min = [10000, 20] 最大値変数/最小値変数 = 9000, 0 スイッチOFF→最大値10000, 最小値20 スイッチON→最大値9000, 最小値20 ・0以下に設定することはできません。やってみたけど面倒すぎ。 ◆使用上の注意 ・●……再定義 ★……エイリアス ○……新規定義 ・再定義があるスクリプトです。扱いにご注意ください。 =end # 設定項目:制限をかけるスイッチID。ONの時制限。0で常時制限。 VMM_SWITCH = 0 # 設定項目:最大値(上)、最小値(下)を参照する変数ID。0でデフォルトを使用。 VMM_MAX_VARIABLE = 1 VMM_MIN_VARIABLE = 2 # 設定項目:デフォルトの最大値/最小値 VMM_INI_MAX = 99999999 VMM_INI_MIN = 0 #============================================================================== # ■ Game_System #============================================================================== class Game_System #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :variable_max_min # 最大値/最小値の配列 #-------------------------------------------------------------------------- # ★ オブジェクト初期化 #-------------------------------------------------------------------------- alias vmm_initialize initialize def initialize vmm_initialize reset_variable_max_min end #-------------------------------------------------------------------------- # ○ 最大値/最小値のリセット #-------------------------------------------------------------------------- def reset_variable_max_min @variable_max_min = [VMM_INI_MAX, VMM_INI_MIN] end #-------------------------------------------------------------------------- # ○ 内部処理 #-------------------------------------------------------------------------- def limit_variable VMM_SWITCH.zero? || $game_switches[VMM_SWITCH] end def variable_max return @variable_max_min[0] if !limit_variable [@variable_max_min[0], $game_variables[VMM_MAX_VARIABLE]].min end def variable_min return [@variable_max_min[1], 0].max if !limit_variable [@variable_max_min[1], $game_variables[VMM_MIN_VARIABLE], 0].max end end #============================================================================== # ■ Window_NumberInput #============================================================================== class Window_NumberInput < Window_Base #-------------------------------------------------------------------------- # ● 入力処理の開始 #-------------------------------------------------------------------------- def start @digits_max = $game_message.num_input_digits_max @number = $game_variables[$game_message.num_input_variable_id] @number = [[@number, num_min].max, num_max].min # ☆ @index = 0 update_placement create_contents refresh open activate end #-------------------------------------------------------------------------- # ○ メソッドの短縮 #-------------------------------------------------------------------------- def num_max; $game_system.variable_max; end def num_min; $game_system.variable_min; end #-------------------------------------------------------------------------- # ● 数字の変更処理 #-------------------------------------------------------------------------- def process_digit_change return unless active if Input.repeat?(:UP) || Input.repeat?(:DOWN) Sound.play_cursor if @number == num_max && Input.trigger?(:UP) @number = num_min # ☆ elsif @number == num_min && Input.trigger?(:DOWN) @number = num_max # ☆ else place = 10 ** (@digits_max - 1 - @index) n = @number / place % 10 @number -= n * place n = (n + 1) % 10 if Input.repeat?(:UP) n = (n + 9) % 10 if Input.repeat?(:DOWN) @number += n * place @number = [[@number, num_min].max, num_max].min # ☆ end refresh end end end