#============================================================================== # ■ RGSS2 アイテム/スキル使用時スイッチ/変数変更 Ver1.00 by 星潟 #------------------------------------------------------------------------------ # 使用時にスイッチ/変数を変更するアイテム/スキルの作成が可能になります。 # コモンイベントと異なり、アイテム/スキル画面で使用しても # 毎回マップ画面に切り替わるという事はなくなります。 #------------------------------------------------------------------------------ # ★設定例(アイテム/スキルのメモ欄に指定) #------------------------------------------------------------------------------ # <スイッチ変更:1,true> # 使用後、スイッチID1がONになります。 #------------------------------------------------------------------------------ # <スイッチ変更:1,false> # 使用後、スイッチID1がOFFになります。 #------------------------------------------------------------------------------ # <変数変更:2,=,0> # 変数2の値を0にします。 #------------------------------------------------------------------------------ # <変数変更:2,+,1> # 変数2の値を1加算します。 #------------------------------------------------------------------------------ # <変数変更:2,-,2> # 変数2の値を2減算します。 #------------------------------------------------------------------------------ # <変数変更:2,*,3> # 変数2の値を3で乗算します。 #------------------------------------------------------------------------------ # <変数変更:2,/,4> # 変数2の値を4で除算します。 #------------------------------------------------------------------------------ # <変数変更:2,%,5> # 変数2の値を5の剰余とします。 #------------------------------------------------------------------------------ # ★条件付きでの変更(スクリプトにある程度の理解がある方向け) #------------------------------------------------------------------------------ # <スイッチ変更:11,true,$game_switches[20]> # 使用後、スイッチID20がONの場合に限り、スイッチID11がONになります。 #------------------------------------------------------------------------------ # <変数変更:12,+,1,rand(2)==0> # 使用後、1/2の確率で変数12の値を1加算します。 #============================================================================== module USE_ITEM_SVC #スイッチ変更用のキーワードを指定。 WORD1 = "スイッチ変更" #変数変更用のキーワードを指定。 WORD2 = "変数変更" end class Scene_Item < Scene_Base #-------------------------------------------------------------------------- # 対象以外への効果 #-------------------------------------------------------------------------- alias use_item_nontarget_switches_variables use_item_nontarget def use_item_nontarget #本来の処理を実行。 use_item_nontarget_switches_variables #アイテム使用時のスイッチ変更を実行。 @item.use_switches_change @item.use_variables_change end end class Scene_Skill < Scene_Base #-------------------------------------------------------------------------- # 対象以外への効果 #-------------------------------------------------------------------------- alias use_skill_nontarget_switches_variables use_skill_nontarget def use_skill_nontarget #本来の処理を実行。 use_skill_nontarget_switches_variables #スキル使用時のスイッチ変更を実行。 @skill.use_switches_change @skill.use_variables_change end end class Scene_Battle < Scene_Base #-------------------------------------------------------------------------- # スキルの実行 #-------------------------------------------------------------------------- alias execute_action_skill_switches_variables execute_action_skill def execute_action_skill #本来の処理を実行。 execute_action_skill_switches_variables #スキルを取得。 skill = @active_battler.action.skill #スキル使用時のスイッチ変更を実行。 skill.use_switches_change skill.use_variables_change end #-------------------------------------------------------------------------- # アイテムの実行 #-------------------------------------------------------------------------- alias execute_action_item_switches_variables execute_action_item def execute_action_item #本来の処理を実行。 execute_action_item_switches_variables #アイテムを取得。 item = @active_battler.action.item #アイテム使用時のスイッチ変更を実行。 item.use_switches_change item.use_variables_change end end class RPG::UsableItem < RPG::BaseItem #-------------------------------------------------------------------------- # アイテム使用時のスイッチ変更 #-------------------------------------------------------------------------- def use_switches_change return if switches_change.empty? switches_change.each {|s| $game_switches[s[0]] = eval(s[1]) if eval(s[2])} end #-------------------------------------------------------------------------- # アイテム使用時の変数変更 #-------------------------------------------------------------------------- def use_variables_change return if variables_change.empty? variables_change.each {|s| next unless eval(s[3]) case s[1] when "=" $game_variables[s[0]] = eval(s[2]) when "+" $game_variables[s[0]] += eval(s[2]) when "-" $game_variables[s[0]] -= eval(s[2]) when "*" $game_variables[s[0]] *= eval(s[2]) when "/" $game_variables[s[0]] /= eval(s[2]) when "%" $game_variables[s[0]] %= eval(s[2]) end } end #-------------------------------------------------------------------------- # スイッチ変更用データ #-------------------------------------------------------------------------- def switches_change #キャッシュが存在する場合はキャッシュを返す。 return @switches_change if @switches_change != nil #スイッチの配列を作成。 @switches_change = [] #メモ欄の各行からデータを取得。 self.note.each_line {|l| memo = l.scan(/<#{USE_ITEM_SVC::WORD1}[::](\S+)>/).flatten #データが存在する場合は分割して配列に入れる。 if memo != nil && !memo.empty? #配列を作成。 array = [] #データを分割する。 data = memo[0].split(/\s*,\s*/) #データを整理する。 data.each_with_index {|d, i| array.push(i == 0 ? d.to_i : d)} if data.size > 1 #配列の要素が不足している場合は文字列のtrueを加える。 array.push("true") if data.size == 2 #配列をスイッチの配列に加える。 @switches_change.push(array) end } #データを返す。 @switches_change end #-------------------------------------------------------------------------- # 変数変更用データ #-------------------------------------------------------------------------- def variables_change #キャッシュが存在する場合はキャッシュを返す。 return @variables_change if @variables_change != nil #変数の配列を作成。 @variables_change = [] #メモ欄の各行からデータを取得。 self.note.each_line {|l| memo = l.scan(/<#{USE_ITEM_SVC::WORD2}[::](\S+)>/).flatten #データが存在する場合は分割して配列に入れる。 if memo != nil && !memo.empty? #配列を作成。 array = [] #データを分割する。 data = memo[0].split(/\s*,\s*/) #データを整理する。 data.each_with_index {|d, i| array.push(i == 0 ? d.to_i : d)} if data.size > 2 #配列の要素が不足している場合は文字列のtrueを加える。 array.push("true") if data.size == 3 #配列を変数の配列に加える。 @variables_change.push(array) end } #データを返す。 @variables_change end end