Black_Mage icon

Special Invulnerable State Script RMXP

Black_Mage | PRO | 11/09/15 06:18:35 AM UTC | 0 ⭐ | 1242 👁️ | Never ⏰ | []
Ruby |

19.28 KB

|

None

|

0 👍

/

0 👎

################################################################################
# Special Invulnerable State Script By Black Mage (Credit required to use)
# Version : 1.3
# https://burningwizard.wordpress.com/2015/11/09/special-invulnerable-state-script/
################################################################################
 
# WARNING : This script is heavily modified the targeting system and how things
# related to them is handled, thus make this script might not compatible with
# many custom battle script. If you found some incompatibility, with another 
# script, make sure to report to : 
# https://burningwizard.wordpress.com/2015/11/09/special-invulnerable-state-script/
# so we can solve the problem.
 
# To use this script, put it above Main script in the script editor, and make sure
# to put it BELOW any script that alter the battle system.
 
# Character inflicted by these states are treated as they not existed in the party.
# Insert the states ID to the brackets below.
$special_states1 = [1,17]
 
# Character inflicted by these states can't be attacked by the enemies.
# If player insisted to attack the target, it'll change into another target.
# It still work on skill that target self.
# Insert the states ID to the brackets below.
$special_states2 = [17]
 
# Character inflicted by these states are grayed out.
# You can modified the value of $special_tone to get your own color.
# Insert the states ID to the brackets below.
$special_states3 = [17]
$special_tone = [0,0,0,255]
 
class Game_Party
  #--------------------------------------------------------------------------
  # * Determine wether state 2 is in effect or not
  #--------------------------------------------------------------------------
  def state2_invulnerable(target)
    # If it fits the conditions
    @special_states = false
    # Check whether special state available
    for i in 0..($special_states2.size - 1)
      if target.state?($special_states2[i])
        @special_states = true
      end
    end
    if @special_states == true
      return true
    else
      return false
    end
  end
  
  #--------------------------------------------------------------------------
  # * Determine Everyone is Dead
  #--------------------------------------------------------------------------
  def all_dead?
    # If number of party members is 0
    if $game_party.actors.size == 0
      return false
    end
    # If an actor is in the party with 0 or more HP
    @special_game_over = 0
    for actor in @actors
      @special_states = false
      if actor.hp == 0
        @special_game_over = @special_game_over + 1
      elsif actor.hp > 0
        # If it fits the conditions
        if $special_states1.size == 0
          return false
        else
          for i in 0..($special_states1.size - 1)
            if actor.state?($special_states1[i])
              @special_states = true              
            end
          end
        end
      end
      if @special_states == true
        @special_game_over = @special_game_over + 1
      end
    end
    # All members dead
    if @special_game_over == @actors.size
      return true
    else
      return false
    end
  end
 
  #--------------------------------------------------------------------------
  # * Random Selection of Target Actor
  #     hp0 : limited to actors with 0 HP
  #--------------------------------------------------------------------------
  def random_target_actor(hp0 = false)
    # Initialize roulette
    roulette = []
    # Loop
    for actor in @actors
      if state2_invulnerable(actor) == false
        if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
          # Get actor class [position]
          position = $data_classes[actor.class_id].position
          # Front guard: n = 4; Mid guard: n = 3; Rear guard: n = 2
          n = 4 - position
          # Add actor to roulette n times
          n.times do
            roulette.push(actor)
          end
        end
      end
    end
    # If roulette size is 0
    if roulette.size == 0
      return nil
    end
    # Spin the roulette, choose an actor
    return roulette[rand(roulette.size)]
  end
 
  #--------------------------------------------------------------------------
  # * Smooth Selection of Target Actor
  #     actor_index : actor index
  #--------------------------------------------------------------------------
  def smooth_target_actor(actor_index)
    # Get an actor
    actor = @actors[actor_index]
    # If an actor exists
    if actor != nil and actor.exist?
      if state2_invulnerable(actor) == false
        return actor
      end
    end
    # Loop
    for actor in @actors
      # If an actor exists
      if actor.exist?
        if state2_invulnerable(actor) == false
          return actor
        end
      end
    end
    actor = $game_party.random_target_actor
    return actor
  end
  
end
 
#----------------------------------------------------------------------------
class Scene_Battle
#----------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  # * Determine wether state 2 is in effect or not
  #--------------------------------------------------------------------------
  def state2_invulnerable(target)
    # If it fits the conditions
    @special_states = false
    # Check whether target is exist
    if target == nil
      return false
    else
      # Check whether special state available
      for i in 0..($special_states2.size - 1)
        if target.state?($special_states2[i])
          @special_states = true
        end
      end
      if @special_states == true
        return true
      else
        return false
      end
    end
  end
 
  #--------------------------------------------------------------------------
  # * Set Targeted Battler for Skill or Item
  #     scope : effect scope for skill or item
  #--------------------------------------------------------------------------
  def set_target_battlers(scope)
    # If battler performing action is enemy
    if @active_battler.is_a?(Game_Enemy)
      # Branch by effect scope
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        actortemp = $game_party.smooth_target_actor(index)
        if state2_invulnerable(actortemp) == false
          @target_battlers.push($game_party.smooth_target_actor(index))
        end
      when 2  # all enemies
        for actor in $game_party.actors
          if actor.exist?
            if state2_invulnerable(actor) == false
              @target_battlers.push(actor)
            end
          end
        end
      when 3  # single ally
        index = @active_battler.current_action.target_index
        enemytemp = $game_troop.smooth_target_enemy(index)
        if state2_invulnerable(enemytemp) == false
          @target_battlers.push($game_troop.smooth_target_enemy(index))
        end
      when 4  # all allies
        for enemy in $game_troop.enemies
          if enemy.exist?
            if state2_invulnerable(enemy) == false
              @target_battlers.push(enemy)
            end
          end
        end
      when 5  # single ally (HP 0) 
        index = @active_battler.current_action.target_index
        enemy = $game_troop.enemies[index]
        if enemy != nil and enemy.hp0?
          if state2_invulnerable(enemy) == false
            @target_battlers.push(enemy)
          end
        end
      when 6  # all allies (HP 0) 
        for enemy in $game_troop.enemies
          if enemy != nil and enemy.hp0?
            if state2_invulnerable(enemy) == false
              @target_battlers.push(enemy)
            end
          end
        end
      when 7  # user
        @target_battlers.push(@active_battler)
      end
    end
    # If battler performing action is actor
    if @active_battler.is_a?(Game_Actor)
      # Branch by effect scope
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        enemytemp = $game_troop.smooth_target_enemy(index)
        if state2_invulnerable(enemytemp) == false
          @target_battlers.push($game_troop.smooth_target_enemy(index))
        end
      when 2  # all enemies
        for enemy in $game_troop.enemies
          if enemy.exist?
            if state2_invulnerable(enemy) == false
              @target_battlers.push(enemy)
            end
          end
        end
      when 3  # single ally
        index = @active_battler.current_action.target_index
        actortemp = $game_party.smooth_target_actor(index)
        if state2_invulnerable(actortemp) == false
          @target_battlers.push($game_party.smooth_target_actor(index))
        end
      when 4  # all allies
        for actor in $game_party.actors
          if actor.exist?
            if state2_invulnerable(actor) == false
              @target_battlers.push(actor)
            end
          end
        end
      when 5  # single ally (HP 0) 
        index = @active_battler.current_action.target_index
        actor = $game_party.actors[index]
        if actor != nil and actor.hp0?
          if state2_invulnerable(actor) == false
            @target_battlers.push(actor)
          end
        end
      when 6  # all allies (HP 0) 
        for actor in $game_party.actors
          if actor != nil and actor.hp0?
            if state2_invulnerable(actor) == false
              @target_battlers.push(actor)
            end
          end
        end
      when 7  # user
        @target_battlers.push(@active_battler)
      end
    end
  end
 
  #--------------------------------------------------------------------------
  # * Make Skill Action Results
  #--------------------------------------------------------------------------
  def make_skill_action_result
    # Get skill
    @skill = $data_skills[@active_battler.current_action.skill_id]
    # If not a forcing action
    unless @active_battler.current_action.forcing
      # If unable to use due to SP running out
      unless @active_battler.skill_can_use?(@skill.id)
        # Clear battler being forced into action
        $game_temp.forcing_battler = nil
        # Shift to step 1
        @phase4_step = 1
        return
      end
    end
    
    # Set target battlers
    set_target_battlers(@skill.scope)
    if @target_battlers == nil
    else
      # Use up SP
      @active_battler.sp -= @skill.sp_cost
      # Refresh status window
      @status_window.refresh
      # Show skill name on help window
      @help_window.set_text(@skill.name, 1)
      # Set animation ID
      @animation1_id = @skill.animation1_id
      @animation2_id = @skill.animation2_id
      # Set command event ID
      @common_event_id = @skill.common_event_id
      # Apply skill effect
      for target in @target_battlers
        if target != nil
          target.skill_effect(@active_battler, @skill)
        end
      end
    end
  end
 
  #--------------------------------------------------------------------------
  # * Make Item Action Results
  #--------------------------------------------------------------------------
  def make_item_action_result
    # Get item
    @item = $data_items[@active_battler.current_action.item_id]
    # If unable to use due to items running out
    unless $game_party.item_can_use?(@item.id)
      # Shift to step 1
      @phase4_step = 1
      return
    end
    # If consumable
    if @item.consumable
      # Decrease used item by 1
      $game_party.lose_item(@item.id, 1)
    end
    # Display item name on help window
    @help_window.set_text(@item.name, 1)
    # Set animation ID
    @animation1_id = @item.animation1_id
    @animation2_id = @item.animation2_id
    # Set common event ID
    @common_event_id = @item.common_event_id
    # Decide on target
    index = @active_battler.current_action.target_index
    target = $game_party.smooth_target_actor(index)
    # Set targeted battlers
    set_target_battlers(@item.scope)
    # Apply item effect
    for target in @target_battlers
      if target != nil
        target.item_effect(@item)
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 4 : animation for target)
  #--------------------------------------------------------------------------
  def update_phase4_step4
    # Animation for target
    for target in @target_battlers
      if target != nil
        target.animation_id = @animation2_id
        target.animation_hit = (target.damage != "Miss")
      end
    end
    # Animation has at least 8 frames, regardless of its length
    @wait_count = 8
    # Shift to step 5
    @phase4_step = 5
  end
 
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 5 : damage display)
  #--------------------------------------------------------------------------
  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    # Display damage
    for target in @target_battlers
      if target != nil
        if target.damage != nil
          target.damage_pop = true
        end
      end
    end
    # Shift to step 6
    @phase4_step = 6
  end
 
end
 
###########################################################################
#--------------------------------------------------------------------------
# * This section enables the first two states to be inflicted onto enemies
#--------------------------------------------------------------------------
###########################################################################
class Game_Troop
 
  #--------------------------------------------------------------------------
  # * Determine wether state 2 is in effect or not
  #--------------------------------------------------------------------------
  def state2_invulnerable(target)
    # If it fits the conditions
    @special_states = false
    # Check whether special state available
    for i in 0..($special_states2.size - 1)
      if target.state?($special_states2[i])
        @special_states = true
      end
    end
    if @special_states == true
      return true
    else
      return false
    end
  end
  
  def random_target_enemy(hp0 = false)
    # Initialize roulette
    roulette = []
    # Loop
    for enemy in @enemies
      if state2_invulnerable(enemy) == false
        if (not hp0 and enemy.exist?) or (hp0 and enemy.hp0?)
          # Add an enemy to the roulette
          roulette.push(enemy)
        end
      end
    end
    # If roulette size is 0
    if roulette.size == 0
      return nil
    end
    # Spin the roulette, choose an enemy
    return roulette[rand(roulette.size)]
  end
 
  #--------------------------------------------------------------------------
  # * Smooth Selection of a Target Enemy
  #     enemy_index : enemy index
  #--------------------------------------------------------------------------
  def smooth_target_enemy(enemy_index)
    # Get an enemy
    enemy = @enemies[enemy_index]
    # If an enemy exists
    if enemy != nil and enemy.exist?
      if state2_invulnerable(enemy) == false
        return enemy
      end
    end
    # Loop
    for enemy in @enemies
      # If an enemy exists
      if enemy.exist?
        if state2_invulnerable(enemy) == false
          return enemy
        end
      end
      enemy = $game_troop.random_target_enemy
      return enemy
    end
  end
end
 
#----------------------------------------------------------------------------
class Scene_Battle
#----------------------------------------------------------------------------
  def make_basic_action_result
    # If attack
    if @active_battler.current_action.basic == 0
      # Set anaimation ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # If action battler is enemy
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.restriction == 3
          target = $game_troop.random_target_enemy
        elsif @active_battler.restriction == 2
          target = $game_party.random_target_actor
        else
          index = @active_battler.current_action.target_index
          target = $game_party.smooth_target_actor(index)
          if state2_invulnerable(target) == false
          else
            target = $game_troop.random_target_actor
          end
        end
      end
      # If action battler is actor
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          index = @active_battler.current_action.target_index
          target = $game_troop.smooth_target_enemy(index)
          if state2_invulnerable(target) == false
          else
            target = $game_troop.random_target_enemy
          end
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      if target != nil
        for target in @target_battlers
          target.attack_effect(@active_battler)
        end
      end
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      # Display "Escape" in help window
      @help_window.set_text("Escape", 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
 
end
 
 
###########################################################################
#--------------------------------------------------------------------------
# * This section enables grey battler sprite
#--------------------------------------------------------------------------
###########################################################################
class Sprite_Battler < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Determine wether state 3 is in effect or not
  #--------------------------------------------------------------------------
  def state3_gray(target)
    # If it fits the conditions
    @special_states = false
    # Check whether special state available
    for i in 0..($special_states3.size - 1)
      if target.state?($special_states3[i])
        @special_states = true
      end
    end
    if @special_states == true
      return true
    else
      return false
    end
  end
  
  alias black_sprite_update update
  def update
    black_sprite_update
    if @battler != nil
      if state3_gray(@battler) == true
        self.tone.set($special_tone[0],$special_tone[1],$special_tone[2],$special_tone[3])
      end
    end
  end
  
end

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎