バトルイベントの発生条件に変数を追加

フォーラムルール
素材の利用規約を決めたいけど、どんなことを書けばいいのか分からない場合は、
素材のテンプレートをご利用下さい。
ショウ
記事: 149
登録日時: 2016年8月10日(水) 19:52

バトルイベントの発生条件に変数を追加

投稿記事by ショウ » 2019年11月25日(月) 20:51

前回の謎の存在同様作ったけど使わなかった掘り出し物
昔マップイベントには変数を条件に出来るのにバトルイベントには無いのが気に食わなくて
作ったスクリプト。(なお結局自分は今の所使ってないという無駄骨)
例えば特定の戦闘でアイテムやスキルを一定回数使ったら発生とかも工夫次第で可能なはず。
アクターID100をダミーアクターとして使い変数ID100を使える様にしてます。
弄れば使える変数を増やしたりも出来ますが自己責任で。
あんまテストはした記憶は無いのでミスがあるかも。
使用方法は下の画像とスクリプトの中見てね。
仕様:データベースで設定する都合上変数の中身は現状0~9999しか使用出来ません。
   10000以上を条件にしたい場合は自分で改造してね。
素材単体での販売以外自由

コード: 全て選択

#==============================================================================
# バトルイベントの発生条件に変数を追加
# byショウ
#利用規約
#素材単体での販売以外自由
#==============================================================================

class Game_Troop < Game_Unit
  #--------------------------------------------------------------------------
  # ● バトルイベント (ページ) の条件合致判定
  #     page : バトルイベントページ
  #--------------------------------------------------------------------------
  def conditions_met?(page)
    c = page.condition
    if not c.turn_ending and not c.turn_valid and not c.enemy_valid and
       not c.actor_valid and not c.switch_valid
      return false      # 条件未設定…実行しない
    end
    if @event_flags[page]
      return false      # 実行済み
    end
    if c.turn_ending    # ターン終了時
      return false unless @turn_ending
    end
    dammy = 100#ダミーアクター設定用(便宜上100にしてるけど自由に)
    if c.actor_valid and c.turn_valid and c.actor_id == dammy
       #比較演算子設定(c.actor_hpの数値で設定)
      if c.actor_hp == 0#等しい
       return true if $game_variables[c.actor_id] == c.turn_a
        elsif c.actor_hp == 1#等しくない
          return true if $game_variables[c.actor_id] != c.turn_a
        elsif c.actor_hp == 2#小さい
          return true if $game_variables[c.actor_id] < c.turn_a
        elsif c.actor_hp == 3#大きい
          return true if $game_variables[c.actor_id] > c.turn_a
        elsif c.actor_hp == 4#以下
          return true if $game_variables[c.actor_id] <= c.turn_a
        elsif c.actor_hp == 5#以上
          return true if $game_variables[c.actor_id] >= c.turn_a
      end
       #比較演算子設定(c.actor_hpの数値で設定)
    end
    if c.turn_valid# ターン数
      n = @turn_count
      a = c.turn_a
      b = c.turn_b
      return false if (b == 0 and n != a)
      return false if (b > 0 and (n < 1 or n < a or n % b != a % b))
    end
    if c.enemy_valid    # 敵キャラ
      enemy = $game_troop.members[c.enemy_index]
      return false if enemy == nil
      return false if enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
    end
    if c.actor_valid# アクター
      actor = $game_actors[c.actor_id]
      return false if actor == nil
      return false if actor.hp * 100.0 / actor.maxhp > c.actor_hp
    end
    if c.switch_valid   # スイッチ
      return false if $game_switches[c.switch_id] == false
    end
    return true         # 条件合致
  end
end
添付ファイル
説明画像.jpg

ショウ
記事: 149
登録日時: 2016年8月10日(水) 19:52

Re: バトルイベントの発生条件に変数を追加

投稿記事by ショウ » 2019年11月27日(水) 12:17

数年前に作ったスクリプトとはいえあまりに使い勝手が悪そうなのでちょっと改良、
ダミーアクターは完全に判定用にして変数ID1~9999まで使えるようにしてみた。
仕様変更内容
ターン数項目の左側が変数の中身の指定なのはそのままだが右側でIDを指定出来る様に
した。

VXの素材屋をめっきり見なくなった昨今いまだにVX使ってる同類達、
今更VXを買った者達、使うなり改造するなり好きにしてやってくれ。

コード: 全て選択

#==============================================================================
# バトルイベントの発生条件に変数を追加Ver.2
# byショウ
#利用規約
#素材単体での販売以外自由
#==============================================================================

class Game_Troop < Game_Unit
  #--------------------------------------------------------------------------
  # ● バトルイベント (ページ) の条件合致判定
  #     page : バトルイベントページ
  #--------------------------------------------------------------------------
  def conditions_met?(page)
    c = page.condition
    if not c.turn_ending and not c.turn_valid and not c.enemy_valid and
       not c.actor_valid and not c.switch_valid
      return false      # 条件未設定…実行しない
    end
    if @event_flags[page]
      return false      # 実行済み
    end
    if c.turn_ending    # ターン終了時
      return false unless @turn_ending
    end
    dammy = 100#ダミーアクター設定用(便宜上100にしてるけど自由に)
    if c.actor_valid and c.turn_valid and c.actor_id >= dammy
       #比較演算子設定(c.actor_hpの数値で設定)
      if c.actor_hp == 0#等しい
       return true if $game_variables[c.turn_b] == c.turn_a
        elsif c.actor_hp == 1#等しくない
          return true if $game_variables[c.turn_b] != c.turn_a
        elsif c.actor_hp == 2#小さい
          return true if $game_variables[c.turn_b] < c.turn_a
        elsif c.actor_hp == 3#大きい
          return true if $game_variables[c.turn_b] > c.turn_a
        elsif c.actor_hp == 4#以下
          return true if $game_variables[c.turn_b] <= c.turn_a
        elsif c.actor_hp == 5#以上
          return true if $game_variables[c.turn_b] >= c.turn_a
      end
       #比較演算子設定(c.actor_hpの数値で設定)
    end
    if c.turn_valid# ターン数
      n = @turn_count
      a = c.turn_a
      b = c.turn_b
      return false if (b == 0 and n != a)
      return false if (b > 0 and (n < 1 or n < a or n % b != a % b))
    end
    if c.enemy_valid    # 敵キャラ
      enemy = $game_troop.members[c.enemy_index]
      return false if enemy == nil
      return false if enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
    end
    if c.actor_valid# アクター
      actor = $game_actors[c.actor_id]
      return false if actor == nil
      return false if actor.hp * 100.0 / actor.maxhp > c.actor_hp
    end
    if c.switch_valid   # スイッチ
      return false if $game_switches[c.switch_id] == false
    end
    return true         # 条件合致
  end
end

“VX:スクリプト素材(RGSS2)” へ戻る