Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

party actor check...

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!
[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]


Thanks to any who help in anyway!!!
 
The actors array in Game_Party is a standard array that starts at 0. So Party member 1 would be $game_party.actors[0] and party member 2 would be $game_party.actors[1]. So when you were trying your code, it was referencing the second party member, who probably wasn't present. Just change that 1 to a 0 and you should be set.

I don't really see much of what you can do to clean your code up...I'm sure you might be able to scrunch up all of those draw_texts with an array and an iterator...but it's not necessary.
 
Hey freak,

a couple things strike me as odd:

In Window_Battle_Result, where you're doing all the draw_text statements, in the first section (EXP, Gold), you update x using cx to control the spacing. That's cool.
But in the second section (Stats - Level), you set x once, use it once, then hardcode each x location. this is ok.
However, you continue to set cx, but are now using for the width of the text. You don't need to do this with fixed position text.
Just make the width on all of them the same, big enough to hold the largest string you will draw.
Then you keep increasing the height (4th parameter) from 72, 120, 160. You haven't changed the text size, so these could all be 32.
neither one of these matter since the draw text method uses a transparent background (it only draws the character pixels). But it will help clean it up a bit.
You could also rearrange the draw texts so you draw all of the system color together, and then the normal color. then you don't keep switching back & forth.

you can combine lines 98 & 99

$game_variables[100] = @level = $game_actors[1].level

again, all minor.

Be Well
 
yeah, so I really wasn't sure what the cx was for, but i could tell it had something to do with the x value so I just kept it in there. And yes, I know I could do 32, but 40 is just a little more space in between so it looks just a touch cleaner.

So, a question for you, second_crimson mentioned using an array to clean up all the draw_text commands, how would I go about doing that?
 
An array is a container that's basically lets you keep a bunch of values in one place. Say I wanted to make an array of colors.

colors = ["Red","Green","Blue"]

Now if I wanted to call up "Red" I could use colors[0] and "Blue" would be colors[2]. It starts from 0, and goes up from there.

Now, by putting all of your texts into an array:
text = ["stats","Max HP","STR"]
(and so on)

You can then use these with an iterator. An iterator is a grouping of code that you can control to repeat itself according to certain parameters.

The one I'd suggest you use is a For iterator.
ex.
[rgss]For i in 0...text.size
cx = contents.text_size(text).width
self.contents.draw_text(4, 0+(32*i), cx, 120, text)
end
 
[/rgss]
Something like that. What that will do is run through the code in between the For and End. Each run through i will hold a value. It starts at 0 then goes up to 1 less than the size of your array you made earlier. Then inside the iterator, you have it draw the text based on which number it's on and reference the array accordingly.
 
ok, I got ya. I'll definitely try that and see what happens.

So, now I have another question. I'm trying to figure out how to hide different states, so that on the bottom, when you have sleep or something, that still shows up, but states between numbers say, 20-25 would not show up when applied. Would I be looking at creating a new script for that? Or is there some mod that I would need to make? I looked through Game_Battler2 where the state is applied and such, but I didn't see anything that would draw the text, and even if I did, I don't know what code I would use to do this. Any help is greatly appreciated.
Thanks!
~xgamexfreakx
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top