VX Battle Retry script by Woratana

posted on 05 Mar 2009 20:34 by boxsuke  in Resources, ScriptsVX, WoraScripts

* สคริปต์นี้จะทำให้ตอนที่ต่อสู้แพ้แล้วไป Gameover เราสามารถเลือกที่จะกลับไปต่อสู้อีกครั้งในการต่อสู้เดิมได้ครับผม ^^/ สามารถเปิดปิดสคริปต์นี้ได้ด้วยสวิตช์ ทำให้อนุญาตการ Retry เฉพาะในบางการต่อสู้ที่โหด ๆ ก็ได้ฮะ เจอบั๊กแจ้งได้เลยครับผม สคริปต์ก็อปได้ด้านล่าง~

Battle Retry
Version 1.0
by Woratana
Release Date: 05/03/2009


Introduction
I saw this kind of script in Gamebaker before.
Now that site is temporarily close, so think it would be a good practice to write it myself.

What this script basically does is after player lose the battle and go to Gameover screen,
there will be a choice for player to choose whether to retry the battle again, or go to title screen.

This script can be enable/disable in game.
This way you can make player not be able to retry in specific battle.

You can also choose to record the party's HP/MP/state before battle.
Therefore, when player chose battle retry, party members will not have full HP/MP and have no bad status.

Enjoy~^^


Features
Version 1.0
- Set switch ID to enable/disable battle retry during the game
- Editable command's text, command's window width and Y-coordinate
- You can choose to record party actors stat (HP/MP/States) before battle


Screenshots



Script
I decided to keep script on my blog. So it will be easier to update. ^^
#===============================================================
# ● [VX] ◦ Battle Retry ◦ □
# * Enable player to retry the battle after losing *
# ** Note: Read the setup part before using this script **
#--------------------------------------------------------------
# ◦ by Woratana [woratana@hotmail.com]
# ◦ Thaiware RPG Maker Community
# ◦ Released on: 29/02/2009
# ◦ Version: 1.0
#--------------------------------------------------------------
# ◦ Update:
#--------------------------------------------------------------
# □ Version 1.0 (29/02/2009)
# - Set switch ID to enable/disable battle retry during the game
# - Editable command's text, command's window width and Y-coordinate
# - You can choose to record party actors stat (HP/MP/States) before battle
#
#--------------------------------------------------------------
# ◦ Compatibility:
#--------------------------------------------------------------
# □ This script will rewrite 0 method(s):
#
#
# □ This script will alias 5 method(s):
#     Scene_Gameover.perform_transition
#     Scene_Gameover.terminate
#     Scene_Gameover.update
#     Scene_Battle.battle_end
#     Game_Interpreter.command_301
#
# □ This script should work with most scripts, except for some modifications
# of Scene_Gameover
#
#--------------------------------------------------------------
# ◦ Installation:
#--------------------------------------------------------------
# 1) This script should be placed JUST BEFORE ▼ Main Process.
#
# □ Like this:
# ▼ Materials
# ...
# ...
# * Battle Retry
# ▼ Main Process
# Main
#
# 2) Setup this script in Setup Part below.
#
#--------------------------------------------------------------
# ◦ How to use:
#--------------------------------------------------------------
# □ Place this script and setup in the setup part.
#
#=================================================================

class Scene_Gameover < Scene_Base

  #=================================================================
  # ++ Setup Part
  #-----------------------------------------------------------------
  BATRETRY_SWITCH_ID = 1
  # Enable Battle Retry if this switch ID is ON
  # Disable Battle Retry if this switch ID is OFF

  BATRETRY_COMMANDS = ['Retry Battle', 'Return to Title Screen']
  # Text on command window asking for Battle Retry
  # E.g. ['Go back to battle', 'Exit to title screen']

  BATRETRY_WINDOW_Y = 288
  # Command window's Y-coordinate (Top: 0, Bottom: 416)

  BATRETRY_WINDOW_WIDTH = 200
  # Command windows' width

  BATRETRY_RECORD_PARTY_STAT = true
  # Record party members' HP/MP/status before going to battle? (true/false)
  #
  # - If this set to true, if Ralph has HP 30 before battle and got poisoned.
  # When player retry the battle, Ralph will still has HP 30 and poisoned.
  #
  # - If this set to false, all the members will get full HP/MP and no bad status
  # after retry the battle.
  #=================================================================

  alias wora_batretry_scego_pertran perform_transition
  alias wora_batretry_scego_term terminate
  alias wora_batretry_scego_upd update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update(*args)
    if $game_temp.battle_retry?
      super
      @command_window.update
      if Input.trigger?(Input::C)
        case @command_window.index
        when 0 # Battle Retry
          # If recorded party stat, load recorded data
          unless $game_temp.last_troop_actor.nil?
            $game_temp.last_troop_actor.each_key do |id|
              data = $game_temp.last_troop_actor[id]
              $game_actors[id].hp = data[0]
              $game_actors[id].mp = data[1]
              $game_actors[id].real_states = data[2]
            end
          else # If not, recover party members
            $game_party.members.each {|actor| actor.recover_all }
          end
          # Setup battle
          last_troop = $game_temp.last_troop_id
          $game_troop.setup(last_troop[0])
          $game_troop.can_escape = last_troop[1]
          $game_troop.can_lose = false
          $game_temp.next_scene = "battle"
          $scene = Scene_Battle.new
        when 1 # Go to Title Screen
          $scene = Scene_Title.new
          Graphics.fadeout(120)
        end
      end
    else # Normal Gameover scene
      wora_batretry_scego_upd(*args)
    end
  end
  #--------------------------------------------------------------------------
  # * Execute Transition
  #--------------------------------------------------------------------------
  def perform_transition(*args)
    if $game_temp.battle_retry?
      # Add command window if need battle retry
      @command_window = Window_Command.new(BATRETRY_WINDOW_WIDTH, BATRETRY_COMMANDS)
      # Show battle retry window in the middle
      @command_window.x = (Graphics.width - @command_window.width) / 2
      @command_window.y = BATRETRY_WINDOW_Y
      @command_window.openness = 0
      @command_window.open
      # Perform transition
      wora_batretry_scego_pertran(*args)
      # Open command window
      until @command_window.openness == 255
        @command_window.update
        Graphics.update
      end
      @command_window.active = true
    else # Normal Gameover scene
      wora_batretry_scego_pertran(*args)
    end
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate(*args)
    @command_window.dispose unless @command_window.nil?
    wora_batretry_scego_term(*args)
  end
end

class Scene_Battle < Scene_Base
  alias wora_batretry_scebat_batend battle_end
  #--------------------------------------------------------------------------
  # * End Battle
  #--------------------------------------------------------------------------
  def battle_end(*args)
    unless (args[0] == 2 and !$game_troop.can_lose)
      # Remove last troop data if won battle
      $game_temp.last_troop_id = nil
      $game_temp.last_troop_actor = nil
    end
    wora_batretry_scebat_batend(*args)
  end

end

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :last_troop_id, :last_troop_actor

  #--------------------------------------------------------------------------
  # * Check if battle can be retry
  #--------------------------------------------------------------------------
  def battle_retry?
    return ($game_switches[Scene_Gameover::BATRETRY_SWITCH_ID] and
  !@last_troop_id.nil?)
  end
end

class Game_Interpreter
  alias wora_batretry_gamint_com301 command_301
  #--------------------------------------------------------------------------
  # * Battle Processing
  #--------------------------------------------------------------------------
  def command_301(*args)
    # If enable to record party stat before battle..
    if Scene_Gameover::BATRETRY_RECORD_PARTY_STAT
      $game_temp.last_troop_actor = {}
      $game_party.members.each do |actor|
        $game_temp.last_troop_actor[actor.id] = [actor.hp, actor.mp, actor.real_states]
      end
    end
    # Store last troop ID in Game_System
    troop_id = @params[0] == 0 ? @params[1] : $game_variables[@params[1]]
    $game_temp.last_troop_id = [troop_id, @params[2]] unless $game_temp.in_battle
    wora_batretry_gamint_com301(*args)
  end
end

class Game_Battler
  #--------------------------------------------------------------------------
  # * Return real states
  #--------------------------------------------------------------------------
  def real_states
    return @states.clone
  end

  #--------------------------------------------------------------------------
  # * Set states with states ID array
  #--------------------------------------------------------------------------
  def real_states=(states_id_array)
    @states = states_id_array
  end
end



Instruction
- Setup script in the SETUP part
- The complete instruction is included in the script


Author's Notes
Free for use in your work if credit is included.
If you want to post it on any forum, please link to this topic.


Bug Report?
Please give me these informations:
QUOTE
- What is it says in error window?
- When is it get error? (Right after run game, when you choose something, etc.)
- What have you changed in setting part?
- Do you have any other scripts running in your game that may crash with this script?

 

 

 

 

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry

Tweet

Looks good wora! Better than the one we had made... we went the lazy route and saved the game at the start of every battle :)

#1 By sandy (70.49.249.205) on 2009-03-05 22:05

อะนะ ยังไม่ค่อยโปรเลย แต่เอาตัวอย่างที่สร้างเล่นมะกี้ มาลงใน Gamemaker แล้วลองดูแล้วกัน ยังไม่เสร็จ แค่เป็นตัวอย่างอะนะ เพราะยังติดปัญหาเกี่ยวกับ Ai Boss มันโง่ๆ อะเดี๋ยวต้องขอสร้างให้สมบูรณ์ก่อนแล้วเดี๋ยวจะเอามาแจกใหม่นะ
#1
Thanks Sandy. ^^
You really should put gamebaker back on again. question There are so many useful scripts that can only be found there. cry

#2
ตอบในบลอคท่านแล้วฮะ open-mounthed smile

#3 By [+Boxsuke+] on 2009-03-05 23:23

เดี๋ยวแก้ให้นะ ชักอายๆแหะเพราะพึ่งทำเกมครั้งแรกแต่ ผมว่าคงมีคนต้องการ คู่มือแน่เลย(เพราะตัวเองโดนมาแล้วหนังสือขายหมดทั่วประเทศ ) จึงพยายทำเท่าทีทำได้อยู่ แต่ ตัวอย่างผมยังไม่มีเวลาทำมากผมเลยทำเล่นๆ มาให้ชมก่อนนะ แล้วยังไม่ค่อยเก่งด้วย เอาเป็นว่าไม่มีอะไรเลยแล้วกัน ดูแล้วอย่าคิดมากนะsad smile
อีกอย่างนะครับ ถ้ามีโอกาส ผมอยากขอความกรุณา อยากลองคุยกับคุณใน MSN บางพอได้ไหมครับ อยากคุยกับคนที่มีความรู้ เพราะตัวเองยังไม่ค่อยเก่งมากครับ เพื่อจะได้รับประสบการณ์ดีๆ จากคุณบ้าง ผมได้ add e-mail : woraXXXX@hotmail.com
ได้นะครับ ผมทำ XXXX ไว้ถ้าคุณไม่ต้องการบอก อีเมลใคร (แต่จริงๆมันก็มีเขียนอยู่แล้วละ cry) ถ้าไม่สะดวกยังไงผมก็ ขออภัยมานะที่นี้ด้วยนะครับ ที่รบกวนคุณใน Blog cry
เมลผมไม่ใช่ความลับไรน้อ มันอยู่ในสคริปต์ทุกอันที่ผมเขียนอยู่แล้วง่ะ sad smile

#6 By [+Boxsuke+] on 2009-03-06 09:06

ก็เห็นอยู่แล้วครับแต่เกงใจเพราะเป็นการโพท ส่วนตัวเลยใจไว้ก่อนครับ กันปัญหา confused smile
hey i love you script. except when i retry the batle there is no BGM. how do i fiz this/

#8 By AA (207.112.85.175) on 2009-03-12 03:10

I will fix that for the next version!

Thanks for reporting bug. ^^

#9 By [+Boxsuke+] on 2009-03-12 16:30

-*- เวง ไม่ทันและ ผมเขียนไปแล้วอะ เหอๆ (น่าจะเอามาเรวๆหน่อย - -*)

#10 By ๏Luvi`KunG๏ (124.121.70.95) on 2009-03-23 19:04

A great script, I congratulate you.

#11 By Nick (68.44.90.223) on 2009-03-24 03:12

It rocks. Anyone who doesn't think it does can go .... themselves. I don't know what u guys said in thai, but if u said something bad about it, you can also go .... yourself.

#12 By DuffDaddy Senior (90.184.36.235) on 2009-08-11 20:02

Can anyone help me because the battle music goes off when I click on retry battle. And what language are you guys writing in because I don't understand.big smile

#13 By Coolguy1234 (97.120.82.53) on 2009-08-18 06:32