#◆◇◆◇◆ チャットスクリプトVX ver 1.01 ◇◆◇◆◇ # サポート掲示板 http://www2.ezbbs.net/21/minto-aaa/ # by みんと =begin ■ 更新履歴 ○ ver 1.01(2012/03/17) リセットでエラー落ちするミスを修正 ○ ver 1.00(2009/03/06) 公開 ■ 説明 指定したボタンを押すことで開始されるイベントを設定できます。 チャットのタイトルはイベント中か、 指定スイッチがオンのときに不可視になります。 チャットイベントは、専用のプロジェクトで作成してください。 (通常のプロジェクトでは作成できません) チャット作成用のプロジェクトでデータを作成し、 テストプレイのボタンを押してください。 (ホップアップウィンドウが出た後に強制終了します。 その後はメッセージに従い、データの貼り付けを行ってください。) 設定はソース内部を参照してください。 =end #============================================================================== # ☆ MINTO #------------------------------------------------------------------------------ # 様々なフラグを扱うメインモジュールです。 #============================================================================== module MINTO # チャットスクリプトを有効化 ( true で有効 / false で無効 ) RGSS["チャットスクリプト"] = true end # チャットスクリプトが有効な場合に以降の処理を実行する if MINTO::RGSS["チャットスクリプト"] == true then #============================================================================== # ☆ カスタマイズ #------------------------------------------------------------------------------ # 機能のカスタマイズをここで行います。 #============================================================================== module Game_Chat # チャット進行度を管理する変数のID Chat_ID = 1 # チャットを無効にするスイッチ # (オンの時に実行できなくなります。 # その際、タイトルも表示されません) Chat_Visible_ID = 1 # チャット実行ボタン # "A", "B", "C", "X", "Y", "Z", "L", "R" # キーボード上の認識は Z, X, C, A, S, D, Q, W Chat_Key = "Z" # キーガイドの表記タイプ( "ゲームパッド" / "キーボード" ) Chat_Guide_Key = "ゲームパッド" #-------------------------------------------------------------------------- # ● データ初期化 #-------------------------------------------------------------------------- def self.reset # タイトルデータをロード @title_data = load_data("Data/ChatData/chat_titles.rvdata") # チャットID管理用のハッシュを初期化 @chat_data = {} # @chat_data[チャット進行度] = [実行するチャットのID] # 必ず配列式で記入してください。 # チャットは、左から順に実行されます。 # 一番右のチャット以外は、一度実行されると再実行されません。 # スタート時 @chat_data[0] = [1, 2, 3] # ロビーに着いた @chat_data[1] = [4] # 最初の森 @chat_data[2] = [5, 6] end end #============================================================================== # ■ Bitmap #------------------------------------------------------------------------------ #  画像そのものを扱う組み込みクラスです。 #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● キーアイコンの描写 # x : 描写先 X 座標 # y : 描写先 Y 座標 # key : 描写キー #-------------------------------------------------------------------------- def draw_key(x, y, key) # キーアイコンを読み込む icon = Cache.picture("Keys") # キーに応じて分岐 case key when "A" then rect = Rect.new(24 * 0, 24 * 0, 24, 24) when "B" then rect = Rect.new(24 * 1, 24 * 0, 24, 24) when "C" then rect = Rect.new(24 * 2, 24 * 0, 24, 24) when "X" then rect = Rect.new(24 * 0, 24 * 1, 24, 24) when "Y" then rect = Rect.new(24 * 1, 24 * 1, 24, 24) when "Z" then rect = Rect.new(24 * 2, 24 * 1, 24, 24) when "L" then rect = Rect.new(24 * 0, 24 * 2, 24, 24) when "R" then rect = Rect.new(24 * 1, 24 * 2, 24, 24) end # キーボード表記の場合 if Game_Chat::Chat_Guide_Key == "キーボード" then # 転送座標をずらす rect.x += 24 * 3 end # 描写範囲を消す self.rect_clear(x, y, 24, 24) # アイコンを描写 self.blt(x, y, icon, rect) end #-------------------------------------------------------------------------- # ● 縁文字描写 # x : 文章の X 座標 # y : 文章の Y 座標 # width : 文章の描写範囲(横幅) # height : 文章の描写範囲(高さ) # text : 文章 # align : アラインメント (0..左揃え、1..中央揃え、2..右揃え) #-------------------------------------------------------------------------- def frame_text(x, y, width, height, text, ag = 0) # 元の色を保存 ori_color = font.color.clone font.shadow = false # 縁の色を定義 font.color.set(0, 0, 0) # 縁文字を描写 draw_text(x-1, y, width, height, text, ag) draw_text(x+1, y, width, height, text, ag) draw_text(x, y-1, width, height, text, ag) draw_text(x, y+1, width, height, text, ag) # 本体の色を定義 font.color.set(255, 255, 255) # 本体の文字を描写 draw_text(x, y, width, height, text, ag) # 元の色に戻す font.color = ori_color end #-------------------------------------------------------------------------- # ● 指定範囲のクリア #-------------------------------------------------------------------------- def rect_clear(x, y, width, height) # 対象の範囲を消す rect = Rect.new(x, y, width, height) self.fill_rect(rect, Color.new(0, 0, 0, 0)) end end #============================================================================== # ■ Sprite #------------------------------------------------------------------------------ #  スプライト表示を扱う組み込みクラスです。 #============================================================================== class Sprite #-------------------------------------------------------------------------- # ● 座標の設定 #-------------------------------------------------------------------------- def rect_set(x, y, z = 100) self.x = x if x self.y = y if y self.z = z if z end end #============================================================================== # ■ Numeric #------------------------------------------------------------------------------ #  数値全般を扱う組み込みクラスです。 #============================================================================== class Numeric #-------------------------------------------------------------------------- # ● 最大値の設定 # max : 求められた最大の数値 #-------------------------------------------------------------------------- def to_m(max) if self > max return max else return self end end #-------------------------------------------------------------------------- # ● 最小値の設定 # min : 求められた最小の数値 #-------------------------------------------------------------------------- def to_min(min) if self < min return min else return self end end end #============================================================================== # ■ Game_Chat #------------------------------------------------------------------------------ #  PTチャットの内容を扱うモジュールです。 #============================================================================== module Game_Chat #-------------------------------------------------------------------------- # ● チャット開始キーの取得 #-------------------------------------------------------------------------- def self.get_key # キーコードに応じて分岐 case Chat_Key when "A" then return 11 when "B" then return 12 when "C" then return 13 when "X" then return 14 when "Y" then return 15 when "Z" then return 16 when "L" then return 17 when "R" then return 18 end end #-------------------------------------------------------------------------- # ● チャットデータの取得 #-------------------------------------------------------------------------- def self.chat_data return @chat_data end #-------------------------------------------------------------------------- # ● 実行データの取得 #-------------------------------------------------------------------------- def self.data return @data end #-------------------------------------------------------------------------- # ● 会話のIDの取得 #-------------------------------------------------------------------------- def self.index # インデックスの最大値を設定 max = @chat_data[$game_variables[Chat_ID]].size - 1 # 現在のインデックスを返す return $game_system.chat_index.to_m(max) end #-------------------------------------------------------------------------- # ● PTチャットの内容の準備 #-------------------------------------------------------------------------- def self.standby_chat # 検索用のデータを取得 data = @chat_data[$game_variables[Chat_ID]][self.index] # 実際のチャットの内容を読み込む @data = load_data("Data/ChatData/chat#{data}.rvdata") # インデックスを進める $game_system.chat_hash[$game_variables[Chat_ID]] += 1 end #-------------------------------------------------------------------------- # ● PTチャットのタイトルの取得 #-------------------------------------------------------------------------- def self.get_chat_title index = self.chat_data[$game_variables[Chat_ID]][self.index] - 1 # タイトルを返す return @title_data[index] end end #============================================================================== # ■ Party_Chat #------------------------------------------------------------------------------ #  PTチャットの処理を管理するモジュールです。 #============================================================================== module Party_Chat #-------------------------------------------------------------------------- # ● チャットの開始 #-------------------------------------------------------------------------- def self.start gx = Graphics.width gy = Graphics.height @tone_rate = 0 # ビューポートを作成 @viewport = Viewport.new(0, 0, gx, gy) # インタプリンタを作成 @interpreter = Game_Interpreter.new # 画面を暗転 self.blackout(0, 10, 100, @viewport) # フィルターを表示 self.back_filter # PT会話を読み込む Game_Chat.standby_chat # チャットを設定 @interpreter.setup(Game_Chat.data.list, 0) # メイン処理を実行 self.main end #-------------------------------------------------------------------------- # ● フィルターカラーの取得 #-------------------------------------------------------------------------- def self.filter_collar return Color.new(0, 0, 0) end #-------------------------------------------------------------------------- # ● 暗転モード処理 # type : 暗転タイプ(0 :開始, 1 :解除) # power : 暗転の速度 # max : 暗転の上限値 # sprite : 暗転させるスプライト #-------------------------------------------------------------------------- def self.blackout(type, power, max, sprite) @tone_power = power @tone_type = type @tone_max = max self.update_blackout(sprite) end #-------------------------------------------------------------------------- # ● フレーム更新 (暗転処理) # sprite : 更新するスプライト #-------------------------------------------------------------------------- def self.update_blackout(sprite) # 暗転タイプに応じて分岐 case @tone_type # 暗転開始 when 0 then # 暗転しきっていない場合 if @tone_rate != -@tone_max then # スプライトを暗転させる @tone_rate = (@tone_rate - @tone_power).to_min(-@tone_max) sprite.tone.red = @tone_rate sprite.tone.green = @tone_rate sprite.tone.blue = @tone_rate end # 暗転解除 when 1 then # 暗転が完全に解除されていない場合 if @tone_rate != 0 then # スプライト暗転を解除させる @tone_rate = (@tone_rate + @tone_power).to_m(0) sprite.tone.red = @tone_rate sprite.tone.green = @tone_rate sprite.tone.blue = @tone_rate end end end #-------------------------------------------------------------------------- # ● バックフィルター作成 #-------------------------------------------------------------------------- def self.back_filter gx = Graphics.width gy = Graphics.height # スプライトを作成 @sprite = Sprite.new @sprite.bitmap = Bitmap.new(gx, 32) # チャットタイトル表示用のフィルターを描写 @sprite.bitmap.fill_rect(0, 0, gx, 32, self.filter_collar) # チャットタイトルを描写 @sprite.bitmap.draw_text(0, 0, gx, 32, Game_Chat.get_chat_title, 1) # スプライトの位置を補正 @sprite.y = -64 @sprite.z = 5001 # メインフィルターを作成 self.filter(0, gy * 70 / 100, Graphics.width, gy * 64 / 100) # フィルターを出現させる self.pt_filter_update(0) end #-------------------------------------------------------------------------- # ● フィルター表示 # x : フィルターのX座標 # y : フィルターのY座標 # width : フィルターの横幅 # height : フィルターの縦幅 #-------------------------------------------------------------------------- def self.filter(x, y, width, height) gx = Graphics.width gy = Graphics.height # フィルター用のスプライトを作成 @filter_sprite = Sprite.new @filter_sprite.z = 199 @filter_sprite.opacity = 0 @filter_sprite.bitmap = Bitmap.new(gx, gy) # 暗転フィルターを描写 @filter_sprite.bitmap.fill_rect(x, y, width, height, self.filter_collar) end #-------------------------------------------------------------------------- # ● PTフィルター更新 # type : 実行タイプ #-------------------------------------------------------------------------- def self.pt_filter_update(type) # 実行タイプに応じて分岐 case type # 開始 when 0 then # ループ処理 while @sprite.y != 0 do # 画面の情報を更新 Graphics.update # Y座標を加算 @sprite.y += 3.2 # 不透明度を加算 @filter_sprite.opacity += 16 # 暗転処理を更新 self.update_blackout(@viewport) end # 終了 when 1 then # ループ処理 while @sprite.y > -64 do # 画面の情報を更新 Graphics.update # Y座標を減算 @sprite.y -= 3.2 # 不透明度を減算 @filter_sprite.opacity -= 16 # 暗転処理を更新 self.update_blackout(@viewport) end end end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- def self.end_effect # トランジション実行 Graphics.transition(20) # タイトル表示を更新 $scene.chat_title.refresh # 画面を暗転を解除 self.blackout(1, 10, 100, @viewport) # フィルターを解放 self.pt_filter_update(1) # スプライトを解放 @filter_sprite.bitmap.dispose @filter_sprite.dispose @filter_sprite = nil @sprite.bitmap.dispose @sprite.dispose @sprite = nil # ビューポートを解放 @viewport.dispose @viewport = nil end #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def self.main # メインループ self.main_loop # 終了処理を実行 self.end_effect end #-------------------------------------------------------------------------- # ● メインループ #-------------------------------------------------------------------------- def self.main_loop # 更新フラグをオン @self_active = true # メインループ処理(更新フラグがオンな限り繰り返す) while @self_active == true do # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update # フレーム更新 update end end #-------------------------------------------------------------------------- # ● フレーム更新(基本情報) #-------------------------------------------------------------------------- def self.update_screen # マップを更新 $game_map.update # ピクチャーを更新 $scene.spriteset.update_picture # メッセージウィンドウを更新 $scene.message_window.update end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def self.update # 画面の基本情報を更新 self.update_screen # インタプリタを更新 @interpreter.update # インタプリタの実行が終わった場合 if @interpreter.running? == false then # インタプリタを消去 @interpreter = nil # トランジション準備 Graphics.freeze # 画面の基本情報を更新 self.update_screen # 更新フラグをクリア @self_active = false end end end #============================================================================== # ■ Game_System #------------------------------------------------------------------------------ #  システム周りのデータを扱うクラスです。BGM などの管理も行います。このクラス # のインスタンスは $game_system で参照されます。 #============================================================================== class Game_System #-------------------------------------------------------------------------- # ● チャット進行度データの取得 #-------------------------------------------------------------------------- def chat_hash # 無効なデータの場合 if @chat_hash.nil? then # データを初期化 @chat_hash = {} end return @chat_hash end #-------------------------------------------------------------------------- # ● チャット進行度の取得 #-------------------------------------------------------------------------- def chat_index # 進行度を取得 hash = self.chat_hash[$game_variables[Game_Chat::Chat_ID]].to_i # 進行度を代入 self.chat_hash[$game_variables[Game_Chat::Chat_ID]] = hash # 進行度を返す return hash end end #============================================================================== # ■ Spriteset_Map #------------------------------------------------------------------------------ #  マップ画面のスプライトやタイルマップなどをまとめたクラスです。このクラスは # Scene_Map クラスの内部で使用されます。 #============================================================================== class Spriteset_Map #-------------------------------------------------------------------------- # ● フレーム更新(ピクチャー) #-------------------------------------------------------------------------- def update_picture update_tilemap update_parallax update_characters update_shadow update_weather update_pictures update_viewports end end #============================================================================== # ■ ViewData_PartyTalk #------------------------------------------------------------------------------ #  PT会話の題名を表示するクラスです。 #============================================================================== class ViewData_PartyTalk #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize x = ((Graphics.width / 2) - 16) y = Graphics.height - 32 @sprite = Sprite.new @sprite.rect_set(x, y, 198) @sprite.bitmap = Bitmap.new(Graphics.width / 2, 32) @blink_count = 0 @turn = 0 @sprite.visible = false refresh end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose @sprite.bitmap.dispose @sprite.dispose @sprite = nil end #-------------------------------------------------------------------------- # ● 通常文字色の取得 #-------------------------------------------------------------------------- def normal_color return Color.new(255, 255, 255) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # チャット無効スイッチがオフの場合 unless $game_switches[Game_Chat::Chat_Visible_ID] then # スプライトの可視状態を求める(イベント実行中は不可視になる) @sprite.visible = ($game_map.interpreter.running? == false) # タイトル強制不可視スイッチがオンの場合 else # スプライトを不可視にする @sprite.visible = false end # 点滅ターンが0の場合 if @turn == 0 then # ブリンクカウントを加算 @blink_count += 0.125 # ブリンクカウントが6の場合 if @blink_count == 6 then # 点滅ターンを進める @turn = 1 end # 点滅ターンが1の場合 else # ブリンクカウントを減算 @blink_count -= 0.125 # ブリンクカウントが0の場合 if @blink_count == 0 then # 点滅ターンを戻す @turn = 0 end end # スプライトの不透明度を設定 @sprite.opacity = 255 / @blink_count.to_min(1) end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh # ビットマップをクリア @sprite.bitmap.clear # 通常色を読み込む @sprite.bitmap.font.color = normal_color # チャットタイトルを取得 text = ": " + Game_Chat.get_chat_title # タイトルの幅を計って調節する x = Graphics.width / 2 - @sprite.bitmap.text_size(text).width # キーアイコンを描写 @sprite.bitmap.draw_key(x - 34, 4, Game_Chat::Chat_Key) # チャットタイトルを描写 @sprite.bitmap.frame_text(x, 0, Graphics.width / 2, 32, text) end end #============================================================================== # ■ Game_Interpreter #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_System クラ # スや Game_Event クラスの内部で使用されます。 #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ● 変数の操作 #-------------------------------------------------------------------------- alias :command_122_MINTO_Chat :command_122 def command_122 # 元の処理を実行 bool = command_122_MINTO_Chat # マップ画面の場合 if $scene.is_a?(Scene_Map) == true then # チャットタイトルを更新 $scene.chat_title.refresh end return bool end end #============================================================================== # ■ Scene_Map #------------------------------------------------------------------------------ #  マップ画面の処理を行うクラスです。 #============================================================================== class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :spriteset # スプライトセット attr_reader :chat_title # チャットタイトルスプライト attr_reader :message_window # メッセージウィンドウ #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- alias :start_MINTO_Chat :start def start # チャットタイトルスプライトを作成 @chat_title = ViewData_PartyTalk.new # 元の処理を実行 start_MINTO_Chat end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- alias :terminate_MINTO_Chat :terminate def terminate # チャットタイトルスプライトを解放 @chat_title.dispose # 元の処理を実行 terminate_MINTO_Chat end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias :update_MINTO_Chat :update def update # 元の処理を実行 update_MINTO_Chat # チャットタイトルスプライトを更新 @chat_title.update # イベント実行中でない場合 unless $game_map.interpreter.running? then # チャット無効スイッチがオフの場合 unless $game_switches[Game_Chat::Chat_Visible_ID] then # チャット開始ボタンが押された場合 if Input.trigger?(Game_Chat.get_key) then # チャットを実行 Party_Chat.start end end end end end # チャットデータの初期化 Game_Chat.reset end