O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

[XP] Erro no script Battle Narration

Iniciado por Moveto, 13/04/2022 às 21:37

13/04/2022 às 21:37 Última edição: 13/04/2022 às 21:56 por Moveto
E aí pessoal, nesse script que eu estou usando, nele há um erro que dá na linha 822, isso ocorre quando há 2 inimigos diferentes na batalha (na mensagem de erro aparece "undefined method `size' for nil:NilClass"), mas como não sou um perito na arte da programação, eu venho aqui humildemente pedir para que alguma alma boa faça o conserto desse script de rpg maker xp...  :T.T:
Spoiler

  module BattleTextSettings
    Aattacktext = {
    0 => ["~a tirou ~d de dano em ~t!"],
    1 => ["~a tirou ~d de dano em ~t!"]
    }
    Eattacktext = {
    1 => ["~a deu ~d de dano em ~t!"]
    }
    Amisstext = {
    0 => ["~a atacou e errou o alvo."]
    }
    Criticaltext = ["Smaaaaaaash! "]
    Emisstext = {
    0 => ["~a atacou e ~t desviou!"],
    1 => ["~a atacou e ~t desviou!"]
    }
    Statecuretext = {
    0 => ["~a retornou ao normal."],
    1 => ["~a voltou para a batalha!"],
    3 => ["O veneno saiu do corpo de ~a!"]
    }
    Stateaddtext = {
    0 => ["~a foi ~s!"],
    1 => ["~a entrou em colapso!"],
    2 => ["~a está em colapso!", "~a foi rasgado em pedaços!"],
    3 => ["~a foi envenenado!"]
    }
    Itemtext = {
    0 => ["~a tirou um ~s."]
    }
    Skilltext = {
    0 => ["~a tentou ~s!"],
    1 => ["~a tentou ~s!"]
    }
    Adeathtext = {
    0 => ["~a foi derrotado!"]
    }
    Edeathtext = {
    0 => ["~a foi derrotado!"],
    1 => ["~a se transformou em poeira!", "~a se derreteu no ar!"]
    }
    Damagetext = ["~a tomou ~d de dano!", "~a perdeu ~d de MP!",
                   "~a recuperou ~d de HP!", "~a recuperou ~d de MP!"]
    Itemmiss = {
    0 => ["Não teve efeito sobre ~a.", "Não teve efeito sobre ~a."]
    }
    Skillmiss = {
    0 => ["~a não afetou ~t.", "~a não foi afetado."]
    }
    Stataddtext = ["~a ~s adicionado por ~d!"]
    Poisontext = ["~a levou ~d de dano do veneno."]
    Partytext = ["o grupo inteiro", "o grupo inimigo"]
    Victorytext = ["VOCÊ GANHOU!"]
    Aescapetext = ["mas não conseguiu..."]
    Eescapetext = {
    0 => ["~a tentou dar no pé..."],
    1 => ["~a tenta escapar..."]
    }
    Guardtext = ["~a entrou em defesa!", "~a faz uma postura defensiva!"]
    Idletext = ["~a está olhando para o chão.", "~a pensa em seus sonhos."]
  end
class Scene_Battle
  include BattleTextSettings
  def main
    $displaytext = ""
    $damages = []
    $damages = []
    $espchange = []
    $aspchange = []
    $atargets = []
    $etargets = []
    $estatadd = []
    $astatadd = []
    $astateadd = []
    $itemuser = ""
    $skillitemname = ""
    $astateremove = []
    $estateadd = []
    $estateremove = []
    for i in 0..8
      $astateadd[i] = []
      $astateremove[i] = []
      $estateadd[i] = []
      $estateremove[i] = []
      $estatadd[i] = []
      $astatadd[i] = []
    end
    @displaywindow = Window_BattleText.new
    @displaywindow.opacity = 160
    @displaywindow.visible = false
    # Initialize each kind of temporary battle data
    $game_temp.in_battle = true
    $game_temp.battle_turn = 0
    $game_temp.battle_event_flags.clear
    $game_temp.battle_abort = false
    $game_temp.battle_main_phase = false
    $game_temp.battleback_name = $game_map.battleback_name
    $game_temp.forcing_battler = nil
    # Initialize battle event interpreter
    $game_system.battle_interpreter.setup(nil, 0)
    # Prepare troop
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    # Make actor command window
    s1 = $data_system.words.attack
    s2 = $data_system.words.skill
    s3 = $data_system.words.guard
    s4 = $data_system.words.item
    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
    @actor_command_window.y = 160
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
    # Make other windows
    @party_command_window = Window_PartyCommand.new
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.visible = false
    @status_window = Window_BattleStatus.new
    @message_window = Window_Message.new
    # Make sprite set
    @spriteset = Spriteset_Battle.new
    # Initialize wait count
    @wait_count = 0
    # Execute transition
    if $data_system.battle_transition == ""
      Graphics.transition(20)
    else
      Graphics.transition(40, "Graphics/Transitions/" +
        $data_system.battle_transition)
    end
    # Start pre-battle phase
    start_phase1
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Refresh map
    $game_map.refresh
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @actor_command_window.dispose
    @party_command_window.dispose
    @help_window.dispose
    @displaywindow.dispose
    @status_window.dispose
    @message_window.dispose
    if @skill_window != nil
      @skill_window.dispose
    end
    if @item_window != nil
      @item_window.dispose
    end
    if @result_window != nil
      @result_window.dispose
    end
    # Dispose of sprite set
    @spriteset.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
    # If switching from battle test to any screen other than game over screen
    if $BTEST and not $scene.is_a?(Scene_Gameover)
      $scene = nil
    end
  end
  def update_phase5
    # If wait count is larger than 0
    if @phase5_wait_count > 0
      # Decrease wait count
      @phase5_wait_count -= 1
      # If wait count reaches 0
      if @phase5_wait_count == 0
        @displaywindow.visible = false
        # Show result window
        @result_window.visible = true
        # Clear main phase flag
        $game_temp.battle_main_phase = false
        # Refresh status window
        @status_window.refresh
      end
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Battle ends
      battle_end(0)
    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
    # Use up SP
    @active_battler.sp -= @skill.sp_cost
    # Refresh status window
    @status_window.refresh
    # Set animation ID
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    # Set command event ID
    @common_event_id = @skill.common_event_id
    # Set target battlers
    set_target_battlers(@skill.scope)
    # Apply skill effect
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
    @displaywindow.set_text($displaytext, 1)
  end
  #--------------------------------------------------------------------------
  # * Make Basic Action Results
  #--------------------------------------------------------------------------
  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)
        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)
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      @displaywindow.set_text($displaytext, 1)
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      text = BattleTextSettings::Guardtext[rand(BattleTextSettings::Guardtext.size)].clone
      text.gsub!(/\~[Aa]/, "#{@active_battler.name.to_s}")
      @displaywindow.set_text(text, 1)
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      temp = BattleTextSettings::Eescapetext[@active_battler.id]
      if temp == nil
        temp = BattleTextSettings::Eescapetext[0]
      end
      text = temp[rand(temp.size)].clone
      text.gsub!(/\~[Aa]/, "#{@active_battler.name.to_s}")
      @displaywindow.set_text(text, 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      text = BattleTextSettings::Idletext[rand(BattleTextSettings::Idletext.size)].clone
      text.gsub!(/\~[Aa]/, "#{@active_battler.name.to_s}")
      @displaywindow.set_text(text, 1)
      battletextinput(50)
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
  def start_phase4
    # Shift to phase 4
    @phase = 4
    # Turn count
    $game_temp.battle_turn += 1
    # Search all battle event pages
    for index in 0...$data_troops[@troop_id].pages.size
      # Get event page
      page = $data_troops[@troop_id].pages[index]
      # If this page span is [turn]
      if page.span == 1
        # Clear action completed flags
        $game_temp.battle_event_flags[index] = false
      end
    end
    # Set actor as unselectable
    @actor_index = -1
    @active_battler = nil
    $edamages = []
    $adamages = []
    for i in 0..8
      $astateadd[i] = []
      $astateremove[i] = []
      $estateadd[i] = []
      $estateremove[i] = []
      $estatadd[i] = []
      $astatadd[i] = []
    end
    # Enable party command window
    @party_command_window.active = false
    @party_command_window.visible = false
    # Disable actor command window
    @actor_command_window.active = false
    @actor_command_window.visible = false
    # Set main phase flag
    $game_temp.battle_main_phase = true
    # Make enemy action
    for enemy in $game_troop.enemies
      enemy.make_action
    end
    # Make action orders
    make_action_orders
    # Shift to step 1
    @phase4_step = 1
  end
  def start_phase5
    # Shift to phase 5
    @phase = 5
    @displaywindow.set_text(BattleTextSettings::Victorytext[rand(BattleTextSettings::Victorytext.size)], 1)
    # Play battle end ME
    $game_system.me_play($game_system.battle_end_me)
    # Return to BGM before battle started
    $game_system.bgm_play($game_temp.map_bgm)
    # Initialize EXP, amount of gold, and treasure
    exp = 0
    gold = 0
    treasures = []
    # Loop
    for enemy in $game_troop.enemies
      # If enemy is not hidden
      unless enemy.hidden
        # Add EXP and amount of gold obtained
        exp += enemy.exp
        gold += enemy.gold
        # Determine if treasure appears
        if rand(100) < enemy.treasure_prob
          if enemy.item_id > 0
            treasures.push($data_items[enemy.item_id])
          end
          if enemy.weapon_id > 0
            treasures.push($data_weapons[enemy.weapon_id])
          end
          if enemy.armor_id > 0
            treasures.push($data_armors[enemy.armor_id])
          end
        end
      end
    end
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    # Obtaining gold
    $game_party.gain_gold(gold)
    # Obtaining treasure
    for item in treasures
      case item
      when RPG::Item
        $game_party.gain_item(item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(item.id, 1)
      end
    end
    # Make battle result window
    @result_window = Window_BattleResult.new(exp, gold, treasures)
    # Set wait count
    @phase5_wait_count = 100
  end
  def update_phase4_step1
    # Hide help window
    @help_window.visible = false
    # Determine win/loss
    if judge
      # If won, or if lost : end method
      return
    end
    # If an action forcing battler doesn't exist
    if $game_temp.forcing_battler == nil
      # Set up battle event
      setup_battle_event
      # If battle event is running
      if $game_system.battle_interpreter.running?
        return
      end
    end
    # If an action forcing battler exists
    if $game_temp.forcing_battler != nil
      # Add to head, or move
      @action_battlers.delete($game_temp.forcing_battler)
      @action_battlers.unshift($game_temp.forcing_battler)
    end
    # If no actionless battlers exist (all have performed an action)
    if @action_battlers.size == 0
      # Start party command phase
      start_phase2
      return
    end
    # Initialize animation ID and common event ID
    @animation1_id = 0
    @animation2_id = 0
    @common_event_id = 0
    # Shift from head of actionless battlers
    @active_battler = @action_battlers.shift
    # If already removed from battle
    if @active_battler.index == nil
      return
    end
    # Slip damage
    if @active_battler.hp > 0 and @active_battler.slip_damage?
      @active_battler.slip_damage_effect
      @active_battler.damage_pop = true
      @displaywindow.set_text($displaytext, 1)
      battletextinput(50)
    end
[close]

Essa é a segunda parte do script, não tava aparecendo tudo, então tive que separar, essa parte vai junto com a primeira no mesmo script.
Spoiler

    # Natural removal of states
    @active_battler.remove_states_auto
    # Refresh status window
    @status_window.refresh
    # Shift to step 2
    @phase4_step = 2
  end
  #--------------------------------------------------------------------------
  # * Frame Update (party command phase: escape)
  #--------------------------------------------------------------------------
  def update_phase2_escape
    # Calculate enemy agility average
    enemies_agi = 0
    enemies_number = 0
    for enemy in $game_troop.enemies
      if enemy.exist?
        enemies_agi += enemy.agi
        enemies_number += 1
      end
    end
    if enemies_number > 0
      enemies_agi /= enemies_number
    end
    # Calculate actor agility average
    actors_agi = 0
    actors_number = 0
    for actor in $game_party.actors
      if actor.exist?
        actors_agi += actor.agi
        actors_number += 1
      end
    end
    if actors_number > 0
      actors_agi /= actors_number
    end
    # Determine if escape is successful
    success = rand(100) < 50 * actors_agi / enemies_agi
    # If escape is successful
    if success
      # Play escape SE
      $game_system.se_play($data_system.escape_se)
      # Return to BGM before battle started
      $game_system.bgm_play($game_temp.map_bgm)
      # Battle ends
      battle_end(1)
    # If escape is failure
    else
      text = BattleTextSettings::Aescapetext[rand(BattleTextSettings::Aescapetext.size)]
      @displaywindow.set_text(text, 1)
      battletextinput(50)
      # Clear all party member actions
      $game_party.clear_actions
      # Start main phase
      start_phase4
    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
    # 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
    $itemuser = @active_battler.name.to_s
    for target in @target_battlers
      target.item_effect(@item)
    end
    @displaywindow.set_text($displaytext, 1)
  end
  alias jaberbattletextphase2 start_phase2
  def start_phase2
    @displaywindow.visible = false
    jaberbattletextphase2
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 6 : refresh)
  #--------------------------------------------------------------------------
  def update_phase4_step6
    # Clear battler being forced into action
    $game_temp.forcing_battler = nil
    # If common event ID is valid
    if @common_event_id > 0
      # Set up event
      common_event = $data_common_events[@common_event_id]
      $game_system.battle_interpreter.setup(common_event.list, 0)
    end
    battletextinput
    for target in @target_battlers
      for i in 0..$estateremove[target.index].size
        if $estateremove[target.index][i] == nil
          break
        else
          temp = BattleTextSettings::Statecuretext[$estateremove[target.index][i]]
          if temp == nil
            temp = BattleTextSettings::Statecuretext[0]
          end
          text = temp[rand(temp.size)].clone
          text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
          @displaywindow.set_text(text, 1)
          battletextinput(50)
        end
      end
      $estateremove[target.index] = []
      for i in 0..$astateremove[target.index].size
        if $astateremove[target.index][i] == nil
          break
        else
          temp = BattleTextSettings::Statecuretext[$astateremove[target.index][i]]
          if temp == nil
            temp = BattleTextSettings::Statecuretext[0]
          end
          text = temp[rand(temp.size)].clone
          text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
          @displaywindow.set_text(text, 1)
          battletextinput(50)
        end
      end
      $astateremove[target.index] = []
      unless $edamages[target.index] == nil
      if $edamages[target.index] == "ITEM"
        temp = BattleTextSettings::Itemmiss[$skillitemname.id]
        if temp == nil
          temp = BattleTextSettings::Itemmiss[0]
        end
        text = temp[rand(temp.size)].clone
      elsif $edamages[target.index] == "SKILL"
        temp = BattleTextSettings::Skillmiss[$skillitemname.id]
        if temp == nil
          temp = BattleTextSettings::Skillmiss[0]
        end
        text = temp[rand(temp.size)].clone
      elsif $edamages[target.index] > 0
        text = BattleTextSettings::Damagetext[0].clone
      elsif $edamages[target.index] < 0
        text = BattleTextSettings::Damagetext[2].clone
        $edamages[target.index] *= -1
      end
      text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
      text.gsub!(/\~[Ss]/, "#{$skillitemname.name.to_s}")
      text.gsub!(/\~[Dd]/, "#{$edamages[target.index].to_s}")
      @displaywindow.set_text(text, 1)
      $edamages[target.index] = nil
      battletextinput(50)
      end
      unless $adamages[target.index] == nil
      if $adamages[target.index] == "ITEM"
        temp = BattleTextSettings::Itemmiss[$skillitemname.id]
        if temp == nil
          temp = BattleTextSettings::Itemmiss[0]
        end
        text = temp[rand(temp.size)].clone
      elsif $adamages[target.index] == "SKILL"
        temp = BattleTextSettings::Skillmiss[$skillitemname.id]
        if temp == nil
          temp = BattleTextSettings::Skillmiss[0]
        end
        text = temp[rand(temp.size)].clone
      elsif $adamages[target.index] > 0
        text = BattleTextSettings::Damagetext[0].clone
      elsif $adamages[target.index] < 0
        text = BattleTextSettings::Damagetext[2].clone
        $adamages[target.index] *= -1
      end
      text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
      text.gsub!(/\~[Ss]/, "#{$skillitemname.name.to_s}")
      text.gsub!(/\~[Dd]/, "#{$adamages[target.index].to_s}")
      @displaywindow.set_text(text, 1)
      $adamages[target.index] = nil
      battletextinput(50)
      end
     unless $espchange[target.index] == nil
      if $espchange[target.index] > 0
        text = BattleTextSettings::Damagetext[1].clone
      elsif $espchange[target.index] < 0
        text = BattleTextSettings::Damagetext[3].clone
        $espchange[target.index] *= -1
      end
      text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
      text.gsub!(/\~[Ss]/, "#{$skillitemname.name.to_s}")
      text.gsub!(/\~[Dd]/, "#{$espchange[target.index].to_s}")
      @displaywindow.set_text(text, 1)
      $espchange[target.index] = nil
      battletextinput(50)
      end
    unless $aspchange[target.index] == nil
      if $aspchange[target.index] > 0
        text = BattleTextSettings::Damagetext[1].clone
      elsif $aspchange[target.index] < 0
        text = BattleTextSettings::Damagetext[3].clone
        $aspchange[target.index] *= -1
      end
      text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
      text.gsub!(/\~[Ss]/, "#{$skillitemname.name.to_s}")
      text.gsub!(/\~[Dd]/, "#{$aspchange[target.index].to_s}")
      @displaywindow.set_text(text, 1)
      $aspchange[target.index] = nil
      battletextinput(50)
      end
    unless $estatadd[target.index][1] == nil
      if $estatadd[target.index][1] > 0
        text = BattleTextSettings::Stataddtext[rand(BattleTextSettings::Stataddtext.size)].clone
        text.gsub!(/\~[Tt]/, "#{target.name.to_s}")
        text.gsub!(/\~[Ss]/, "#{$estatadd[target.index][0].to_s}")
        text.gsub!(/\~[Dd]/, "#{$estatadd[target.index][1].to_s}")
        $estatadd[target.index][1] = nil
        @displaywindow.set_text(text, 1)
        battletextinput(50)
      end
      end
      unless $astatadd[target.index][1] == nil
      if $astatadd[target.index][1] > 0
        text = BattleTextSettings::Stataddtext[rand(BattleTextSettings::Stataddtext.size)].clone
        text.gsub!(/\~[Tt]/, "#{target.name.to_s}")
        text.gsub!(/\~[Ss]/, "#{$astatadd[target.index][0].to_s}")
        text.gsub!(/\~[Dd]/, "#{$astatadd[target.index][1].to_s}")
        $astatadd[target.index][1] = nil
        @displaywindow.set_text(text, 1)
        battletextinput(50)
      end
      end
     for i in 0..$astateadd[target.index].size
        if $astateadd[target.index][i] == nil
          break
        else
          statename = $data_states[$astateadd[target.index][i]]
          temp = BattleTextSettings::Stateaddtext[statename.id]
          if temp == nil
            temp = BattleTextSettings::Stateaddtext[0]
          end
          text = temp[rand(temp.size)].clone
          text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
          text.gsub!(/\~[Ss]/, "#{statename.name.to_s}")
          @displaywindow.set_text(text, 1)
          battletextinput(50)
        end
      end
      $astateadd[target.index] = []
      for i in 0..$estateadd[target.index].size
        if $estateadd[target.index][i] == nil
          break
        else
          statename = $data_states[$estateadd[target.index][i]]
          temp = BattleTextSettings::Stateaddtext[statename.id]
          if temp == nil
            temp = BattleTextSettings::Stateaddtext[0]
          end
          text = temp[rand(temp.size)].clone
          text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
          text.gsub!(/\~[Ss]/, "#{statename.name.to_s}")
          @displaywindow.set_text(text, 1)
          battletextinput(50)
        end
      end
      $estateadd[target.index] = []
      if target.dead?
        if target.is_a?(Game_Enemy)
          temp = BattleTextSettings::Edeathtext[target.id]
          if temp == nil
            temp = BattleTextSettings::Edeathtext[0]
          end
        else
          temp = BattleTextSettings::Adeathtext[target.id]
          if temp == nil
            temp = BattleTextSettings::Adeathtext[0]
          end
        end
        text = temp[rand(temp.size)].clone
        text.gsub!(/\~[Aa]/, "#{target.name.to_s}")
        @displaywindow.set_text(text, 1)
        battletextinput(50)
      end
    end
    @phase4_step = 1
  end
  
  def battletextinput(framelimit = $game_variables[25])
    framesorz = 0
    framelimit = $game_variables[1] if framelimit < $game_variables[1] or $game_variables[1] == -1
    loop do
      unless framelimit == -1
        framesorz += 1
        break if framesorz >= framelimit
      end
      Input.update
      Graphics.update
      @spriteset.update
      break if Input.trigger?(Input::C)
    end
    return
  end
end

class Game_Battler
  include BattleTextSettings
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      atk = [attacker.atk - self.pdef / 2, 0].max
      self.damage = atk * (20 + attacker.str) / 20
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      if attacker.is_a?(Game_Actor)
        temp = BattleTextSettings::Aattacktext[attacker.weapon_id]
        if temp == nil
          temp = BattleTextSettings::Aattacktext[0]
        end
      elsif attacker.is_a?(Game_Enemy)
        temp = BattleTextSettings::Eattacktext[attacker.id]
        if temp == nil
          temp = BattleTextSettings::Eattacktext[0]
        end
      end
      text = temp[rand(temp.size)].clone
      # If damage value is strictly positive
      if self.damage > 0
        # Critical correction
        if rand(100) < 4 * attacker.dex / self.agi
          self.damage *= 2
          self.critical = true
        end
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    # If hit occurs
    if hit_result == true
      if self.critical == true
        text = BattleTextSettings::Criticaltext[rand(BattleTextSettings::Criticaltext.size)].clone + text
      end
      text.gsub!(/\~[Tt]/, "#{self.name.to_s}")
      text.gsub!(/\~[Aa]/, "#{attacker.name.to_s}")
      text.gsub!(/\~[Dd]/, "#{self.damage.to_s}")
      $displaytext = text
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      if self.damage >= self.hp and self.is_a?(Game_Actor)
        if self.hp <= 10
          self.hp -= self.damage
        else
          self.hp = 1
        end
      else
        self.hp -= self.damage
      end
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      if self.is_a?(Game_Actor)
        temp = BattleTextSettings::Amisstext[self.id]
        if temp == nil
          temp = BattleTextSettings::Amisstext[0]
        end
      else
        temp = BattleTextSettings::Emisstext[self.id]
        if temp == nil
          temp = BattleTextSettings::Emisstext[0]
        end
      end
      text = temp[rand(temp.size)].clone
      text.gsub!(/\~[Tt]/, "#{self.name.to_s}")
      text.gsub!(/\~[Aa]/, "#{attacker.name.to_s}")
      $displaytext = text
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      self.critical = false
    end
    # End Method
    return true
  end
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #     user  : the one using skills (battler)
  #     skill : skill
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    attacker = user
    # Clear critical flag
    self.critical = false
    # If skill scope is for ally with 1 or more HP, and your own HP = 0,
    # or skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    if self.is_a?(Game_Enemy)
      $etargets[self.index] = self.name.to_s
    else
      $etargets[self.index] = self.name.to_s
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= skill.common_event_id > 0
    # First hit detection
    hit = skill.hit
    if skill.atk_f > 0
      hit *= user.hit / 100
    end
    hit_result = (rand(100) < hit)
    # Set effective flag if skill is uncertain
    effective |= hit < 100
    if BattleTextSettings::Skilltext[skill.id] == nil
      temp = BattleTextSettings::Skilltext[0]
      else
        temp = BattleTextSettings::Skilltext[skill.id]
      end
      text = temp[rand(temp.size)].clone
      text.gsub!(/\~[Aa]/, "#{user.name.to_s}")
      text.gsub!(/\~[Ss]/, "#{skill.name.to_s}")
      case skill.scope
      when 2
        text.gsub!(/\~[Tt]/, "#{BattleTextSettings::Partytext[1].to_s}")
      when 4
        text.gsub!(/\~[Tt]/, "#{BattleTextSettings::Partytext[0].to_s}")
      when 6
        text.gsub!(/\~[Tt]/, "#{BattleTextSettings::Partytext[0].to_s}")
      else
        text.gsub!(/\~[Tt]/, "#{self.name.to_s}")
      end
      $displaytext = text.to_s
    $skillitemname = skill
    # If hit occurs
    if hit_result == true
      # Calculate power
      power = skill.power + user.atk * skill.atk_f / 100
      if power > 0
        power -= self.pdef * skill.pdef_f / 200
        power -= self.mdef * skill.mdef_f / 200
        power = [power, 0].max
      end
      # Calculate rate
      rate = 20
      rate += (user.str * skill.str_f / 100)
      rate += (user.dex * skill.dex_f / 100)
      rate += (user.agi * skill.agi_f / 100)
      rate += (user.int * skill.int_f / 100)
      # Calculate basic damage
      self.damage = power * rate / 20
      # Element correction
      self.damage *= elements_correct(skill.element_set)
      self.damage /= 100
    # If hit occurs
      # If damage value is strictly positive
      if self.damage > 0
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if skill.variance > 0 and self.damage.abs > 0
        amp = [self.damage.abs * skill.variance / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / user.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
      # Set effective flag if skill is uncertain
      effective |= hit < 100
    end
    # If hit occurs
    if hit_result == true
      
      # If physical attack has power other than 0
      if skill.power != 0 and skill.atk_f > 0
        # State Removed by Shock
        remove_states_shock
        # Set to effective flag
        effective = true
      end
      # Substract damage from HP
      last_hp = self.hp
      if self.damage >= self.hp and self.is_a?(Game_Actor)
        if self.hp <= 10
          self.hp -= self.damage
        else
          self.hp = 1
        end
      else
        self.hp -= self.damage
      end
      effective |= self.hp != last_hp
        if self.is_a?(Game_Enemy)
          $edamages[self.index] = self.damage
        else
          $adamages[self.index] = self.damage
        end
      # State change
      @state_changed = false
      effective |= states_plus(skill.plus_state_set)
      effective |= states_minus(skill.minus_state_set)
      if self.damage == 0
        unless @state_changed
        if self.is_a?(Game_Enemy)
        $edamages[self.index] = "SKILL"
      else
        $adamages[self.index] = "SKILL"
      end
    end
    end
      # If power is 0
      if skill.power == 0
        # Set damage to an empty string
        self.damage = ""
        # If state is unchanged
        unless @state_changed
          # Set damage to "Miss"
          self.damage = "Miss"
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
      if self.is_a?(Game_Enemy)
        $edamages[self.index] = "SKILL"
      else
        $adamages[self.index] = "SKILL"
      end
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  def item_effect(item)
    # Clear critical flag
    self.critical = false
    # If item scope is for ally with 1 or more HP, and your own HP = 0,
    # or item scope is for ally with 0 HP, and your own HP = 1 or more
    if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
       ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= item.common_event_id > 0
    # Determine hit
    hit_result = (rand(100) < item.hit)
    # Set effective flag is skill is uncertain
    effective |= item.hit < 100
    if BattleTextSettings::Itemtext[item.id] == nil
      temp = BattleTextSettings::Itemtext[0]
      else
        temp = BattleTextSettings::Itemtext[item.id]
      end
      text = temp[rand(temp.size)].clone
      text.gsub!(/\~[Aa]/, "#{$itemuser.to_s}")
      text.gsub!(/\~[Tt]/, "#{self.name.to_s}")
      text.gsub!(/\~[Ss]/, "#{item.name.to_s}")
      $displaytext = text.to_s
      $skillitemname = item
    # If hit occurs
    if hit_result == true
      # Calculate amount of recovery
      recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
      recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
      if recover_hp < 0
        recover_hp += self.pdef * item.pdef_f / 20
        recover_hp += self.mdef * item.mdef_f / 20
        recover_hp = [recover_hp, 0].min
      end
      # Element correction
      recover_hp *= elements_correct(item.element_set)
      recover_hp /= 100
      recover_sp *= elements_correct(item.element_set)
      recover_sp /= 100
      # Dispersion
      if item.variance > 0 and recover_hp.abs > 0
        amp = [recover_hp.abs * item.variance / 100, 1].max
        recover_hp += rand(amp+1) + rand(amp+1) - amp
      end
      if item.variance > 0 and recover_sp.abs > 0
        amp = [recover_sp.abs * item.variance / 100, 1].max
        recover_sp += rand(amp+1) + rand(amp+1) - amp
      end
      # If recovery code is negative
      if recover_hp < 0
        # Guard correction
        if self.guarding?
          recover_hp /= 2
        end
      end
      # Set damage value and reverse HP recovery amount
      self.damage = -recover_hp
      # HP and SP recovery
      last_hp = self.hp
      last_sp = self.sp
      if self.is_a?(Game_Actor)
        if recover_hp > 0
          self.hp += recover_hp
        else
          if self.damage >= self.hp
            if self.hp <= 10
              self.hp += recover_hp
            else
              self.hp = 1
            end
          else
            self.hp += recover_hp
          end
        end
      else
        self.hp += recover_hp
      end
      self.sp += recover_sp
      effective |= self.hp != last_hp
      effective |= self.sp != last_sp
      if recover_hp != 0
        if self.is_a?(Game_Enemy)
          $edamages[self.index] = -recover_hp
        else
          $adamages[self.index] = -recover_hp
        end
      end
      if recover_sp != 0
        if self.is_a?(Game_Enemy)
          $espchange[self.index] = -recover_sp
        else
          $aspchange[self.index] = -recover_sp
        end
      end
      # State change
      @state_changed = false
      effective |= states_plus(item.plus_state_set)
      effective |= states_minus(item.minus_state_set)
      # If parameter value increase is effective
      if item.parameter_type > 0 and item.parameter_points != 0
        # Branch by parameter
        case item.parameter_type
        when 1  # Max HP
          @maxhp_plus += item.parameter_points
        when 2  # Max SP
          @maxsp_plus += item.parameter_points
        when 3  # Strength
          @str_plus += item.parameter_points
        when 4  # Dexterity
          @dex_plus += item.parameter_points
        when 5  # Agility
          @agi_plus += item.parameter_points
        when 6  # Intelligence
          @int_plus += item.parameter_points
        end
        if self.is_a?(Game_Enemy)
          $estatadd[self.index][0] = Stataddtext[item.parameter_type - 1]
          $estatadd[self.index][1] = item.parameter_points
        else
          $astatadd[self.index][0] = Stataddtext[item.parameter_type - 1]
          $astatadd[self.index][1] = item.parameter_points
        end
        # Set to effective flag
        effective = true
      end
      # If HP recovery rate and recovery amount are 0
      if item.recover_hp_rate == 0 and item.recover_hp == 0
        # Set damage to empty string
        self.damage = ""
        # If SP recovery rate / recovery amount are 0, and parameter increase
        # value is ineffective.
        if item.recover_sp_rate == 0 and item.recover_sp == 0 and
           (item.parameter_type == 0 or item.parameter_points == 0)
          # If state is unchanged
          unless @state_changed
            # Set damage to "Miss"
            self.damage = "Miss"
          end
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    if effective == false
      if self.is_a?(Game_Enemy)
        $edamages[self.index] = "ITEM"
        $espchange[self.index] = nil
      else
        $adamages[self.index] = "ITEM"
        $aspchange[self.index] = nil
      end
    end
    # End Method
    return effective
  end
  #--------------------------------------------------------------------------
  # * Application of Slip Damage Effects
  #--------------------------------------------------------------------------
  def slip_damage_effect
    # Set damage
    if self.is_a?(Game_Actor)
      self.damage = (self.maxhp - 10) / 10
    else
      self.damage = self.maxhp / 10
    end
    # Dispersion
    if self.damage.abs > 0
      amp = [self.damage.abs * 15 / 100, 1].max
      self.damage += rand(amp+1) + rand(amp+1) - amp
    end
    # Subtract damage from HP
    self.hp -= self.damage
    text = BattleTextSettings::Poisontext[rand(BattleTextSettings::Poisontext.size)].clone
    text.gsub!(/\~[Aa]/, "#{self.name.to_s}")
    text.gsub!(/\~[Dd]/, "#{self.damage.to_s}")
    $displaytext = text
    # End Method
    return true
  end
  #--------------------------------------------------------------------------
  # * State Change (+) Application
  #     plus_state_set  : State Change (+)
  #--------------------------------------------------------------------------
  def states_plus(plus_state_set)
    # Clear effective flag
    effective = false
    # Loop (added state)
    for i in plus_state_set
      # If this state is not guarded
      unless self.state_guard?(i)
        # Set effective flag if this state is not full
        effective |= self.state_full?(i) == false
        # If states offer [no resistance]
        if $data_states[i].nonresistance
          # Set state change flag
          @state_changed = true
          # Add a state
          add_state(i)
          if self.is_a?(Game_Enemy)
            $estateadd[self.index].push(i)
          else
            $astateadd[self.index].push(i)
          end
        # If this state is not full
        elsif self.state_full?(i) == false
          # Convert state effectiveness to probability,
          # compare to random numbers
          if rand(100) < [0,100,80,60,40,20,0][self.state_ranks[i]]
            # Set state change flag
            @state_changed = true
            # Add a state
            add_state(i)
            if self.is_a?(Game_Enemy)
              $estateadd[self.index].push(i)
            else
              $astateadd[self.index].push(i)
            end
          end
        end
      end
    end
    # End Method
    return effective
  end
  def remove_state(state_id, force = false)
    # If this state is added
    if state?(state_id)
      # If a forcefully added state is not forcefully removed
      if @states_turn[state_id] == -1 and not force
        # End Method
        return
      end
      # If current HP is at 0 and options are effective [regarded as HP 0]
      if @hp == 0 and $data_states[state_id].zero_hp
        # Determine if there's another state [regarded as HP 0] or not
        zero_hp = false
        for i in @states
          if i != state_id and $data_states[i].zero_hp
            zero_hp = true
          end
        end
        # Change HP to 1 if OK to remove incapacitation.
        if zero_hp == false
          
          @hp = 11
        end
      end
      if $game_temp.in_battle and zero_hp == false
        if self.is_a?(Game_Enemy)
          $estateremove[self.index].push(state_id)
        else
          $astateremove[self.index].push(state_id)
        end
      end
      # Delete state ID from @states and @states_turn hash array
      @states.delete(state_id)
      @states_turn.delete(state_id)
    end
    # Check maximum value for HP and SP
    @hp = [@hp, self.maxhp].min
    @sp = [@sp, self.maxsp].min
  end
end
#==============================================================================
# Window_BattleText
#==============================================================================
class Window_BattleText < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 72)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.pause = true
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #  text  : text string displayed in window
  #  align : alignment (0..flush left, 1..center, 2..flush right)
  #--------------------------------------------------------------------------
  def set_text(text1, align = 0)
      # Redraw text
      self.contents.clear
      self.contents.font.color = normal_color
      self.contents.font.size = 22
      self.contents.draw_text(4, -8, self.width - 40, 32, @text1, align) unless @text1 == nil
      self.contents.draw_text(4, 16, self.width - 40, 32, text1, align)
      @text1 = text1
      @align = align
      @actor = nil
    self.visible = true
  end
end
[close]