xgamexfreakx
Member
Well, this is kinda confusing but then again not, so I dunno...
I've been testing my scripting skills here and have attempted to make a simple enhanced battle results window. It's coming along pretty well, however, I've run into a small problem. I can't get the actor's max hp to come right. I've gotten it to work if I use,
[rgss]@maxhp = $game_actors[1].maxhp
[/rgss]
but then it just uses the maxhp of the first character in the list, not the party. So that doesn't work. So then I tried this,
[rgss]@actor1 = $game_party.actors[1]
@maxhp = @actor1.maxhp
[/rgss]
But this just give me an error because actor1 doesn't have a mxhp....any idea's on how to do this???
Also, I was wondering if you would look over what I've done to the code and tell me how to improve it. To make it cleaner and such....Thanks!
Thanks to any who help in anyway!!!
I've been testing my scripting skills here and have attempted to make a simple enhanced battle results window. It's coming along pretty well, however, I've run into a small problem. I can't get the actor's max hp to come right. I've gotten it to work if I use,
[rgss]@maxhp = $game_actors[1].maxhp
[/rgss]
but then it just uses the maxhp of the first character in the list, not the party. So that doesn't work. So then I tried this,
[rgss]@actor1 = $game_party.actors[1]
@maxhp = @actor1.maxhp
[/rgss]
But this just give me an error because actor1 doesn't have a mxhp....any idea's on how to do this???
Also, I was wondering if you would look over what I've done to the code and tell me how to improve it. To make it cleaner and such....Thanks!
[rgss]Â
#==============================================================================
# ** Window_BattleResult
#------------------------------------------------------------------------------
# Â This window displays amount of gold and EXP acquired at the end of a battle.
# Â This section has been completely redone by me, xgamexfreakx, to have a much
# Â smoother level up window.
#==============================================================================
Â
class Window_BattleResult < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #   exp    : EXP
 #   gold    : amount of gold
 #   treasures : treasures
 #--------------------------------------------------------------------------
 def initialize(exp, gold, treasures, stats)
  @exp = exp
  @gold = gold
  @treasures = treasures
  @stats = stats
  super(160, 0, 320, @treasures.size * 32 + 192)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.y = 160 - height / 2
  self.back_opacity = 160
  self.visible = false
  @maxhp = $game_actors[1].maxhp
  @maxsp = $game_actors[1].maxsp
  @str = $game_actors[1].str
  @agi = $game_actors[1].agi
  @dex = $game_actors[1].dex
  @int = $game_actors[1].int
  refresh
 end
 #==========================================================================
 #  New Refresh
 #==========================================================================
 def refresh
  self.contents.clear
  x = 76
  self.contents.font.color = normal_color
  cx = contents.text_size(@exp.to_s).width
  self.contents.draw_text(x, 0, cx, 32, @exp.to_s)
  x += cx + 4
  self.contents.font.color = system_color
  cx = contents.text_size("EXP").width
  self.contents.draw_text(x, 0, 64, 32, "EXP")
  x += cx + 16
  self.contents.font.color = normal_color
  cx = contents.text_size(@gold.to_s).width
  self.contents.draw_text(x, 0, cx, 32, @gold.to_s)
  x += cx + 4
  self.contents.font.color = system_color
  self.contents.draw_text(x, 0, 128, 32, $data_system.words.gold)
  y = 32
  for item in @treasures
   draw_item_name(item, 4, y)
   y += 32
  end
  y = 64
  x = 120
  self.contents.font.color = normal_color
  cx = contents.text_size("Stats").width
  self.contents.draw_text(x, 0, cx, 72, "Stats")
  self.contents.font.color = system_color
  cx = contents.text_size("Max HP").width
  self.contents.draw_text(4, 0, cx, 120, "Max HP")
  self.contents.font.color = normal_color
  self.contents.draw_text(92, 0, cx, 120, @maxhp.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("Max SP").width
  self.contents.draw_text(160, 0, cx, 120, "Max SP")
  self.contents.font.color = normal_color
  self.contents.draw_text(248, 0, cx, 120, @maxsp.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("STR").width
  self.contents.draw_text(4, 0, cx, 160, "STR")
  self.contents.font.color = normal_color
  self.contents.draw_text(92, 0, cx, 160, @str.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("AGI").width
  self.contents.draw_text(160, 0, cx, 160, "AGI")
  self.contents.font.color = normal_color
  self.contents.draw_text(248, 0, cx, 160, @agi.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("DEX").width
  self.contents.draw_text(4, 0, cx, 200, "DEX")
  self.contents.font.color = normal_color
  self.contents.draw_text(92, 0, cx, 200, @dex.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("INT").width
  self.contents.draw_text(160, 0, cx, 200, "INT")
  self.contents.font.color = normal_color
  self.contents.draw_text(248, 0, cx, 200, @int.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("Current Level").width
  self.contents.draw_text(60, 0, cx, 260, "Current Level")
  $game_variables[100] = $game_actors[1].level
  @level = $game_actors[1].level
  self.contents.font.color = normal_color
  self.contents.draw_text(190, 0, cx, 260, @level.to_s)
  if
   $game_variables[100] > $game_variables[99]
  then
  common_event = $data_common_events[30]
  $game_system.battle_interpreter.setup(common_event.list, 0)
  end
  #===============================================
 end
end
Â
[/rgss]
#==============================================================================
# ** Window_BattleResult
#------------------------------------------------------------------------------
# Â This window displays amount of gold and EXP acquired at the end of a battle.
# Â This section has been completely redone by me, xgamexfreakx, to have a much
# Â smoother level up window.
#==============================================================================
Â
class Window_BattleResult < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #   exp    : EXP
 #   gold    : amount of gold
 #   treasures : treasures
 #--------------------------------------------------------------------------
 def initialize(exp, gold, treasures, stats)
  @exp = exp
  @gold = gold
  @treasures = treasures
  @stats = stats
  super(160, 0, 320, @treasures.size * 32 + 192)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.y = 160 - height / 2
  self.back_opacity = 160
  self.visible = false
  @maxhp = $game_actors[1].maxhp
  @maxsp = $game_actors[1].maxsp
  @str = $game_actors[1].str
  @agi = $game_actors[1].agi
  @dex = $game_actors[1].dex
  @int = $game_actors[1].int
  refresh
 end
 #==========================================================================
 #  New Refresh
 #==========================================================================
 def refresh
  self.contents.clear
  x = 76
  self.contents.font.color = normal_color
  cx = contents.text_size(@exp.to_s).width
  self.contents.draw_text(x, 0, cx, 32, @exp.to_s)
  x += cx + 4
  self.contents.font.color = system_color
  cx = contents.text_size("EXP").width
  self.contents.draw_text(x, 0, 64, 32, "EXP")
  x += cx + 16
  self.contents.font.color = normal_color
  cx = contents.text_size(@gold.to_s).width
  self.contents.draw_text(x, 0, cx, 32, @gold.to_s)
  x += cx + 4
  self.contents.font.color = system_color
  self.contents.draw_text(x, 0, 128, 32, $data_system.words.gold)
  y = 32
  for item in @treasures
   draw_item_name(item, 4, y)
   y += 32
  end
  y = 64
  x = 120
  self.contents.font.color = normal_color
  cx = contents.text_size("Stats").width
  self.contents.draw_text(x, 0, cx, 72, "Stats")
  self.contents.font.color = system_color
  cx = contents.text_size("Max HP").width
  self.contents.draw_text(4, 0, cx, 120, "Max HP")
  self.contents.font.color = normal_color
  self.contents.draw_text(92, 0, cx, 120, @maxhp.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("Max SP").width
  self.contents.draw_text(160, 0, cx, 120, "Max SP")
  self.contents.font.color = normal_color
  self.contents.draw_text(248, 0, cx, 120, @maxsp.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("STR").width
  self.contents.draw_text(4, 0, cx, 160, "STR")
  self.contents.font.color = normal_color
  self.contents.draw_text(92, 0, cx, 160, @str.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("AGI").width
  self.contents.draw_text(160, 0, cx, 160, "AGI")
  self.contents.font.color = normal_color
  self.contents.draw_text(248, 0, cx, 160, @agi.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("DEX").width
  self.contents.draw_text(4, 0, cx, 200, "DEX")
  self.contents.font.color = normal_color
  self.contents.draw_text(92, 0, cx, 200, @dex.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("INT").width
  self.contents.draw_text(160, 0, cx, 200, "INT")
  self.contents.font.color = normal_color
  self.contents.draw_text(248, 0, cx, 200, @int.to_s)
  self.contents.font.color = system_color
  cx = contents.text_size("Current Level").width
  self.contents.draw_text(60, 0, cx, 260, "Current Level")
  $game_variables[100] = $game_actors[1].level
  @level = $game_actors[1].level
  self.contents.font.color = normal_color
  self.contents.draw_text(190, 0, cx, 260, @level.to_s)
  if
   $game_variables[100] > $game_variables[99]
  then
  common_event = $data_common_events[30]
  $game_system.battle_interpreter.setup(common_event.list, 0)
  end
  #===============================================
 end
end
Â
[/rgss]
[rgss]Â
#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
# Â This class performs battle screen processing.
#==============================================================================
Â
class Scene_Battle
 #--------------------------------------------------------------------------
 # * Start Pre-Battle Phase
 #--------------------------------------------------------------------------
 def start_phase1
  # Shift to phase 1
  @phase = 1
  # Clear all party member actions
  $game_party.clear_actions
  # Set up battle event
  setup_battle_event
 end
 #--------------------------------------------------------------------------
 # * Frame Update (pre-battle phase)
 #--------------------------------------------------------------------------
 def update_phase1
  # Determine win/loss situation
  if judge
   # If won or lost: end method
   return
  end
  # Start party command phase
  start_phase2
 end
 #--------------------------------------------------------------------------
 # * Start Party Command Phase
 #--------------------------------------------------------------------------
 def start_phase2
  # Shift to phase 2
  @phase = 2
  # Set actor to non-selecting
  @actor_index = -1
  @active_battler = nil
  # Enable party command window
  @party_command_window.active = true
  @party_command_window.visible = true
  # Disable actor command window
  @actor_command_window.active = false
  @actor_command_window.visible = false
  # Clear main phase flag
  $game_temp.battle_main_phase = false
  # Clear all party member actions
  $game_party.clear_actions
  # If impossible to input command
  unless $game_party.inputable?
   # Start main phase
   start_phase4
  end
 end
 #--------------------------------------------------------------------------
 # * Frame Update (party command phase)
 #--------------------------------------------------------------------------
 def update_phase2
  # If C button was pressed
  if Input.trigger?(Input::C)
   # Branch by party command window cursor position
   case @party_command_window.index
   when 0  # fight
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Start actor command phase
    start_phase3
   when 1  # escape
    # If it's not possible to escape
    if $game_temp.battle_can_escape == false
     # Play buzzer SE
     $game_system.se_play($data_system.buzzer_se)
     return
    end
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Escape processing
    update_phase2_escape
   end
   return
  end
 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
   # Clear all party member actions
   $game_party.clear_actions
   # Start main phase
   start_phase4
  end
 end
 #--------------------------------------------------------------------------
 # * Start After Battle Phase
 #--------------------------------------------------------------------------
 def start_phase5
  # Shift to phase 5
  @phase = 5
  # 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
   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
  #================================================================
  # Add the Stat increase window
  # Addition made by xgamexfreakx
  #================================================================
  # Stat Increase
  stats = []
  maxhp = $game_actors[1].maxhp
  maxsp = $game_actors[1].maxsp
  str = $game_actors[1].str
  agi = $game_actors[1].agi
  dex = $game_actors[1].dex
  int = $game_actors[1].int
  # 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, stats)
  # Set wait count
  @phase5_wait_count = 100
 end
 #--------------------------------------------------------------------------
 # * Frame Update (after battle phase)
 #--------------------------------------------------------------------------
 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
    # 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
end
Â
Â
[/rgss]
#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
# Â This class performs battle screen processing.
#==============================================================================
Â
class Scene_Battle
 #--------------------------------------------------------------------------
 # * Start Pre-Battle Phase
 #--------------------------------------------------------------------------
 def start_phase1
  # Shift to phase 1
  @phase = 1
  # Clear all party member actions
  $game_party.clear_actions
  # Set up battle event
  setup_battle_event
 end
 #--------------------------------------------------------------------------
 # * Frame Update (pre-battle phase)
 #--------------------------------------------------------------------------
 def update_phase1
  # Determine win/loss situation
  if judge
   # If won or lost: end method
   return
  end
  # Start party command phase
  start_phase2
 end
 #--------------------------------------------------------------------------
 # * Start Party Command Phase
 #--------------------------------------------------------------------------
 def start_phase2
  # Shift to phase 2
  @phase = 2
  # Set actor to non-selecting
  @actor_index = -1
  @active_battler = nil
  # Enable party command window
  @party_command_window.active = true
  @party_command_window.visible = true
  # Disable actor command window
  @actor_command_window.active = false
  @actor_command_window.visible = false
  # Clear main phase flag
  $game_temp.battle_main_phase = false
  # Clear all party member actions
  $game_party.clear_actions
  # If impossible to input command
  unless $game_party.inputable?
   # Start main phase
   start_phase4
  end
 end
 #--------------------------------------------------------------------------
 # * Frame Update (party command phase)
 #--------------------------------------------------------------------------
 def update_phase2
  # If C button was pressed
  if Input.trigger?(Input::C)
   # Branch by party command window cursor position
   case @party_command_window.index
   when 0  # fight
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Start actor command phase
    start_phase3
   when 1  # escape
    # If it's not possible to escape
    if $game_temp.battle_can_escape == false
     # Play buzzer SE
     $game_system.se_play($data_system.buzzer_se)
     return
    end
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Escape processing
    update_phase2_escape
   end
   return
  end
 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
   # Clear all party member actions
   $game_party.clear_actions
   # Start main phase
   start_phase4
  end
 end
 #--------------------------------------------------------------------------
 # * Start After Battle Phase
 #--------------------------------------------------------------------------
 def start_phase5
  # Shift to phase 5
  @phase = 5
  # 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
   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
  #================================================================
  # Add the Stat increase window
  # Addition made by xgamexfreakx
  #================================================================
  # Stat Increase
  stats = []
  maxhp = $game_actors[1].maxhp
  maxsp = $game_actors[1].maxsp
  str = $game_actors[1].str
  agi = $game_actors[1].agi
  dex = $game_actors[1].dex
  int = $game_actors[1].int
  # 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, stats)
  # Set wait count
  @phase5_wait_count = 100
 end
 #--------------------------------------------------------------------------
 # * Frame Update (after battle phase)
 #--------------------------------------------------------------------------
 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
    # 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
end
Â
Â
[/rgss]
Thanks to any who help in anyway!!!