皆さん、こんにちは。RPGMaker XP用の「選択肢無効化」スクリプトを作成しようとしています。
HimesworkさんはVXAce用のものを作られていましたが、今はリンクが切れており、さらにRGSS3(RGSS1ではなく)を使用しているため、私には使えません(現在リンクが有効なものは、コードが何をするものなのかの説明がなく、すべて不明な状態です…)。
Google Search AIの助けを借りてここまで進めましたが、AIが整理してくれたコードは意図した通りに動作していません。
#==============================================================================
# ■ RPG Maker XP (RGSS1) 用 個別選択肢無効化
#==============================================================================
class Window_Command < Window_Selectable
#--- テキストタグを動的にクリーンアップするための初期化オーバーライト ---
alias xp_tag_choice_initialize initialize
def initialize(width, commands)
@raw_commands = commands.clone # タグを含む元のテキストを保存
clean_commands = commands.map { |text| text.gsub(/\\[Ss]\[\d+\]/, "") }
xp_tag_choice_initialize(width, commands)
end
#--- アイテムを描画。タグ付きスイッチがONの場合は色を変更 ---
def draw_item(index, color)
raw_text = @raw_commands[index]
if raw_text =~ /\\[Ss]\[(\d+)\]/
switch_id = $1.to_i
if $game_switches[switch_id] == true
self.contents.font.color = disabled_color
else
self.contents.font.color = color
end
else
self.contents.font.color = color
end
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @raw_commands[index])
end
#--- 選択プロセスが生のタグを参照できるようにするアクセサ ---
def raw_commands
return @raw_commands
end
end
#--- プレイヤーが無効なオプションを選択しようとした場合、入力をブロック ---
class Window_Selectable < Window_Base
alias xp_tag_choice_update update
def update
if self.active && @item_max > 0 && Input.trigger?(Input::C)
if self.is_a?(Window_Command)
raw_text = self.raw_commands[self.index]
if raw_text =~ /\\[Ss]\[(\d+)\]/
switch_id = $1.to_i
if $game_switches[switch_id] == true
$game_system.se_play($data_system.buzzer_se)
return
end
end
end
end
xp_tag_choice_update
end
end
このコードには重大な問題があるようです。実行すると、スイッチのテキスト(\s[1])が削除されるどころか、色の変更も行われません。おそらく、.cloneまたは.mapの処理で失敗していると思われます。