Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Working On A Battle Result Screen
SleepingSirenx
post Nov 4 2011, 09:58 PM
Post #1


The SMT Maniac
Group Icon

Group: Revolutionary
Posts: 125
Type: Developer
RM Skill: Undisclosed




after reading ( patienly ) some RGSS tutorials, i started creating some battle result script.
I have already created the basics for window structures and the scene ...
Then, how can I show the scene i created after the battle?
And how can i show the items obtained during battle?
And lastly, how can i show the skills learned if there is any skill learned after battle. ex. Leveling up.
Thank you.

Here is the script im working on :
CODE
#==============================================================================
# * Battle Statistics Window
#==============================================================================
class BRWindow < Window_Base
  def initialize
    super(0, 0, 640, 70)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 30
    self.visible = true
    refresh_BR
  end
  
  def refresh_BR
    self.contents.clear
    cx = contents.text_size("Battle Statistics").width
    self.contents.draw_text(225, 0, cx, 32, "Battle Statistics")
  end
end

#==============================================================================
# * Items Gained Window
#==============================================================================
class Items_GoldWindow < Window_Base
  
  def initialize (gold, treasures)
    @gold = gold
    @treasures = treasures
  end
  
  def initialize
    super(0, 70, 250, 350)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 30
    self.visible = true
    refresh_IG
  end
    
  def refresh_IG
    self.contents.clear
    self.contents.draw_text(40, 0, 150, 32, "Items and Gold Obtained")
    self.contents.draw_text(0, 40, 150, 32, $data_system.words.gold)
    self.contents.draw_text(0, 72, 150, 32, @gold.to_s)
    self.contents.draw_text(0, 104, 150, 32, $data_system.words.item)
  end
end

#==============================================================================
# Experience Gained Window
#==============================================================================
  
# * Window Initialization
class Exp_Window < Window_Base
  
  def initialize(exp)
    @exp = exp
  end
  
  def initialize
    super(250, 70, 390, 350)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 30
    self.visible = true
    refresh_Exp
  end
  
  def refresh_Exp
    self.contents.clear
    self.contents.draw_text(120, 0, 150, 32, "Experience Gained")
    for i in 0...$game_party.actors.size
      x = 20
      y = (i * 60) + 50
      actor = $game_party.actors[i]
    self.contents.font.color = text_color(3)
    self.contents.font.size = 28
    self.contents.draw_text(x, y, 150, 32, $game_party.actors[i].name)
    self.contents.font.color = text_color(6)
    self.contents.font.size = 18
    self.contents.draw_text(x, y + 20, 150, 32, actor.class_name)
    self.contents.font.size = 16
    cx = self.contents.text_size(@exp.to_s).width
    self.contents.draw_text(150, 90, cx, 32, @exp.to_s)
    self.contents.font.size = 16
    self.contents.draw_text(115, 20, 150, 32, "Experience Left Till Level Up")
    self.contents.font.size = 25
    draw_actor_exp(actor, x + 90, y)
  end
end
end

#==============================================================================
# Battle System Message Window
#==============================================================================

class BS_Window < Window_Base
  def initialize
    super(0, 420, 640, 60)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 20
    self.visible = true
    refresh_BS
  end
  
  def refresh_BS
    self.contents.clear
    self.contents.draw_text(0, 0, 150, 32, "Battle Info")
  end
end

#==============================================================================
# Battle Result Scene
#==============================================================================

class Scene_BattleResult
  
  def main
    # make window for BRWindow, Items_GoldWindow, Exp_Window and BS_Window
    @br_window = BRWindow.new
    @ig_window = Items_GoldWindow.new
    @exp_window = Exp_Window.new
    @bs_window = BS_Window.new
    # graphics transition
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    # prepare for transition
    Graphics.freeze
    # dispose windows
    @br_window.dispose
    @ig_window.dispose
    @exp_window.dispose
    @bs_window.dispose
  end
  
  # * Define Update
  def update
    @ig_window.update
    @exp_window.update
    @bs_window.update
    if Input.trigger?(Input::B) or if Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
      # Switch to Scene Map
      $scene = Scene_Map.new
    end
  end
end
end


This post has been edited by SleepingSirenx: Nov 4 2011, 09:59 PM


__________________________

My First Game .... Yeah .... ~♥
I'm In Need Of A Team To Help Me WIth The Development Of My Game PM Me. :)
- DEMO's On Progress!

I Support This Projects!



Please Teach Me How To Script. :(
I'm Learning How To Script. But Still Teach Me How To Script :)
Damn THERMODYNAMICS! Makes My Head Spin!
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Nov 6 2011, 02:12 AM
Post #2


Level 50
Group Icon

Group: +Gold Member
Posts: 1,520
Type: Scripter
RM Skill: Undisclosed




Just a couple things, firstly, that's quite impressive smile.gif

I'm not sure if you've seen how it looks, but it looks impressive

Attached File  BattleStats.png ( 92.77K ) Number of downloads: 19


Secondly, there was a couple mistakes with the initialize function and your if statements.
With the initialize, you had something along the lines of
CODE
def initialize(var1, var2)
  @var1, @var2 = var1, var2
end
def initialize
  super(0, 0, 640, 480)
  self.contents = Bitmap.new(width - 32, height - 32)
end

And because you made two initialize functions the second initialize overwrites the first, so the var1 and var2 were getting lost, so just make that into 1 big initialize function and it's all good smile.gif
The if statement problem was you had
CODE
if @var1 and if @var2
  // Do something
end
end

Ruby is a bit loose with it's coding formalities which is what may have caused the confusion, but you need to remember that you only need one if statement, so it becomes
CODE
if ( var1 and var2 )
  // Do something
end



I've done some other things as well, mostly just alias ( a better tutorial ) a few methods in Scene_Battle, so it will switch to the Scene_BattleResult when you win, and I've made a hash in $game_temp that holds the information about the experience, gold and treasures from the battle smile.gif
( Oh, and made the experience, gold and treasures readable from the window that is supposed to show it happy.gif )

code
CODE
#==============================================================================
# * Battle Statistics Window
#==============================================================================
class Game_Temp
  
  alias ssx_battleResults_initialize  initialize
  
  attr_accessor :items_gained_from_battle
  
  def initialize
    @items_gained_from_battle = {}
    # Run the original initialize
    ssx_battleResults_initialize
  end
end

#==============================================================================
# * Battle Statistics Window
#==============================================================================
class Window_BattleResult
  
  attr_reader :exp, :gold, :treasures
end

#==============================================================================
# * Battle Statistics Window
#==============================================================================
class BRWindow < Window_Base
  def initialize
    super(0, 0, 640, 70)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 30
    self.visible = true
    refresh_BR
  end
  
  def refresh_BR
    self.contents.clear
    cx = contents.text_size("Battle Statistics").width
    self.contents.draw_text(225, 0, cx, 32, "Battle Statistics")
  end
end

#==============================================================================
# * Items Gained Window
#==============================================================================
class Items_GoldWindow < Window_Base
  
  def initialize (gold, treasures)
    @gold = gold
    @treasures = treasures
    super(0, 70, 250, 350)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 30
    self.visible = true
    refresh_IG
  end
    
  def refresh_IG
    self.contents.clear
    self.contents.draw_text(40, 0, 150, 32, "Items and Gold Obtained")
    self.contents.draw_text(0, 40, 150, 32, $data_system.words.gold)
    self.contents.draw_text(0, 72, 150, 32, @gold.to_s)
    self.contents.draw_text(0, 104, 150, 32, $data_system.words.item)
  end
end

#==============================================================================
# Experience Gained Window
#==============================================================================
  
# * Window Initialization
class Exp_Window < Window_Base
  
  def initialize(exp)
    @exp = exp
    super(250, 70, 390, 350)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 30
    self.visible = true
    refresh_Exp
  end
  
  def refresh_Exp
    self.contents.clear
    self.contents.draw_text(120, 0, 150, 32, "Experience Gained")
    for i in 0...$game_party.actors.size
      x = 20
      y = (i * 60) + 50
      actor = $game_party.actors[i]
      self.contents.font.color = text_color(3)
      self.contents.font.size = 28
      self.contents.draw_text(x, y, 150, 32, $game_party.actors[i].name)
      self.contents.font.color = text_color(6)
      self.contents.font.size = 18
      self.contents.draw_text(x, y + 20, 150, 32, actor.class_name)
      self.contents.font.size = 16
      cx = self.contents.text_size(@exp.to_s).width
      self.contents.draw_text(150, 90, cx, 32, @exp.to_s)
      self.contents.font.size = 16
      self.contents.draw_text(115, 20, 150, 32, "Experience Left Till Level Up")
      self.contents.font.size = 25
      draw_actor_exp(actor, x + 90, y)
    end
  end
end

#==============================================================================
# Battle System Message Window
#==============================================================================

class BS_Window < Window_Base
  def initialize
    super(0, 420, 640, 60)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Calibri"
    self.contents.font.size = 20
    self.visible = true
    refresh_BS
  end
  
  def refresh_BS
    self.contents.clear
    self.contents.draw_text(0, 0, 150, 32, "Battle Info")
  end
end

#==============================================================================
# Battle Result Scene
#==============================================================================

class Scene_BattleResult
  
  def main
    # make window for BRWindow, Items_GoldWindow, Exp_Window and BS_Window
    @exp = $game_temp.items_gained_from_battle[:exp]
    @gold = $game_temp.items_gained_from_battle[:gold]
    @treasures = $game_temp.items_gained_from_battle[:treasures]
    # Reset the items_gained_from_battle
    $game_temp.items_gained_from_battle = {}
    @br_window = BRwindow.new
    @ig_window = Items_Goldwindow.new(@gold, @treasures)
    @exp_window = Exp_window.new(@exp)
    @bs_window = BS_window.new
    # graphics transition
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    # prepare for transition
    Graphics.freeze
    # dispose windows
    @br_window.dispose
    @ig_window.dispose
    @exp_window.dispose
    @bs_window.dispose
  end
  
  # * Define Update
  def update
    @ig_window.update
    @exp_window.update
    @bs_window.update
    if Input.trigger?(Input::B) or Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
      # Switch to Scene Map
      $scene = Scene_Map.new
    end
  end
end



#==============================================================================
# Battle Scene
#==============================================================================

class Scene_Battle
  
  alias ssx_battleResult_main          main
  alias ssx_battleResult_start_phase5  start_phase5
  
  def main
    # Run the original main
    ssx_battleResult_main
    # If it is transferring to the map then redirect to the battleresults window
    $scene = Scene_BattleResult.new if $scene.is_a?(Scene_Map)
  end
  
  def start_phase5
    # Run the original start_phase5
    ssx_battleResult_start_phase5
    # Get the items
    $game_temp.items_gained_from_battle[:exp] = @result_window.exp
    $game_temp.items_gained_from_battle[:gold] = @result_window.gold
    $game_temp.items_gained_from_battle[:treasures] = @result_window.treasures
    # Skip the rest, go straight to the Scene_BattleResults
    $scene = Scene_BattleResult.new
  end
end


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
SleepingSirenx
post Nov 6 2011, 02:53 AM
Post #3


The SMT Maniac
Group Icon

Group: Revolutionary
Posts: 125
Type: Developer
RM Skill: Undisclosed




Thank you for the compliment, though I still have a long way in scripting and thank you sir for the help you made. I now understand (somehow - laughs ) how to use alias smile.gif. Thank you again.

Side Note :
is this code syntax enough to make skill learned through level appear?
CODE
  def generate_data(initial_levels)
    i = 0
    # Actors gain level
    for actor in $game_party.actors
      @actors_data.push (ResultActor.new(actor, initial_levels[i],  
      [], 0))
      count = 0
      # Valid actor?
      if actor.cant_get_exp? == false
        difference = actor.level - @actors_initals_levels[i]
        # Check diff so can gain levels or exp
        if difference > 0
          
          # LEVEL UP.
          @actors_data.last.gained_levels = difference
          
          # SKILL GAIN UP.
          for lv in 0...difference
            # If it have skills learning
            for lea in $data_classes[actor.class_id].learnings
              if lea.level ==  @actors_initals_levels[i] + lv
                @actors_data.last.gained_skills.push (lea.skill_id)
              end
            end
          end
        end
      end
      i += 1
    end
  end



__________________________

My First Game .... Yeah .... ~♥
I'm In Need Of A Team To Help Me WIth The Development Of My Game PM Me. :)
- DEMO's On Progress!

I Support This Projects!



Please Teach Me How To Script. :(
I'm Learning How To Script. But Still Teach Me How To Script :)
Damn THERMODYNAMICS! Makes My Head Spin!
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Nov 7 2011, 12:07 AM
Post #4


Level 50
Group Icon

Group: +Gold Member
Posts: 1,520
Type: Scripter
RM Skill: Undisclosed




I have no way of knowing from this snippet alone.
You get passed the input initial_levels, which is an array of what I'm guessing is the actors initial levels, but later you get to finding the difference and you start using @actors_initals_levels.
And I am not sure what @actors_data contains.

But assuming that they all work, then yeah, it looks like it could work smile.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 21st May 2013 - 12:43 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker