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.

Before Battle Switch problem

Hi people. I'm having a problem with this script:

Before Battle Switch by Slipknot
http://www.rmxp.org/forums/index.php?topic=868
#==============================================================================
# ** Before Battle Switch
#------------------------------------------------------------------------------
# Slipknot
# 1.0
# 04.20.06
#==============================================================================

Battle_Switch = 5

class Scene_Map
  #--------------------------------------------------------------------------
  alias slipknot_battleswitch_main main
  #--------------------------------------------------------------------------
  def main
    @battle_called = false
    slipknot_battleswitch_main
  end
  #--------------------------------------------------------------------------
  def update
    loop do
      $game_map.update
      $game_system.map_interpreter.update
      $game_player.update
      $game_system.update
      $game_screen.update
      unless $game_temp.player_transferring
        break
      end
      transfer_player
      if $game_temp.transition_processing
        break
      end
    end
    @spriteset.update
    @message_window.update
    if $game_temp.gameover
      $scene = Scene_Gameover.new
      return
    end
    if $game_temp.to_title
      $scene = Scene_Title.new
      return
    end
    if $game_temp.transition_processing
      $game_temp.transition_processing = false
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end
    if $game_temp.message_window_showing
      return
    end
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # Added
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    if @battle_called
      $game_temp.map_bgm = $game_system.playing_bgm
      @battle_called = false
      $game_system.bgm_stop
      $game_system.se_play($data_system.battle_start_se)
      $game_system.bgm_play($game_system.battle_bgm)
      $game_player.straighten
      $scene = Scene_Battle.new
      return
    end
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      unless $game_system.map_interpreter.running? or
            $game_system.encounter_disabled
        n = rand($game_map.encounter_list.size)
        troop_id = $game_map.encounter_list[n]
        if $data_troops[troop_id] != nil
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = troop_id
          $game_temp.battle_can_escape = true
          $game_temp.battle_can_lose = false
          $game_temp.battle_proc = nil
        end
      end
    end
    if Input.trigger?(Input::B)
      unless $game_system.map_interpreter.running? or
            $game_system.menu_disabled
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end
    if $DEBUG and Input.press?(Input::F9)
      $game_temp.debug_calling = true
    end
    unless $game_player.moving?
      if $game_temp.battle_calling
        call_battle
      elsif $game_temp.shop_calling
        call_shop
      elsif $game_temp.name_calling
        call_name
      elsif $game_temp.menu_calling
        call_menu
      elsif $game_temp.save_calling
        call_save
      elsif $game_temp.debug_calling
        call_debug
      end
    end
  end
  #--------------------------------------------------------------------------
  def call_battle
    $game_temp.battle_calling = false
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    $game_player.make_encounter_count
    @battle_called = true
    $game_switches[Battle_Switch] = true
    $game_map.need_refresh = true
  end
end

class Scene_Battle
  #--------------------------------------------------------------------------
  alias slipknot_battleswitch_main main
  #--------------------------------------------------------------------------
  def main
    slipknot_battleswitch_main
    $game_switches[Battle_Switch] = false
  end
end

I am using the non-SDK version. What it does is, it turns on a switch right before a battle, then turns it off right after a battle.
The problem is, the script disables the "Continue Even When Loser" option. It doesn't allow any of the commands when you Win OR Lose to commence.

This is a very simple problem, I don't know how else to make it clearer and more precise.
Any help would be greatly appreciated, Thank you in advance.
 

poccil

Sponsor

Can't you just replace the script above with the one below, which does much the same thing?
Code:
Battle_Switch = 5
class Scene_Battle
  alias slipknot_battleswitch_main main
  def main
    $game_switches[Battle_Switch] = true
    slipknot_battleswitch_main
    $game_switches[Battle_Switch] = false
  end
end
Also, instead of using a switch, you can check whether a battle is active by using event commands like the following:
Code:
@> Conditional Branch: Script: $game_temp.in_battle
   @> Text: Currently in battle
   @>
 : Branch End
I hope this helps.
 
Thanks a lot for the help Poccil, unfortunately neither of those worked in the end. If anybody else is willing to look at the script and make a few changes, I would be very grateful.

Thanks in advance.
 
I decided to "write" a new script for you instead of changing the original code you posted simply for the reason that it can be done with alot less code. Anyways, here is the script:

Code:
#==============================================================================
# ** Before Battle Switch
#------------------------------------------------------------------------------
#
#  Replace the number in "Switch" to the id of the switch you wish to turn ON/OFF
#  whenever a fight begin/end.
#
#==============================================================================
class Scene_Battle

  Switch = 5
  
  #--------------------------------------------------------------------------
  # * Aliasing
  #--------------------------------------------------------------------------
  alias seita_battle_end battle_end
  alias seita_main main

  #--------------------------------------------------------------------------
  # * battle_end
  #--------------------------------------------------------------------------
  def battle_end(result)
    $game_switches[Switch] = false
    seita_battle_end(result)
  end

  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    $game_switches[Switch] = true
    seita_main
  end
end

If you have any questions don't hesitate to tell me. :thumb:

Over and out - Gando
 
Thanks a lot. I'm just wondering why it doesn't work. I basically have a common event that allows the characters sprite-sheet to change when the switch is on. It works with the script I've been using, though I would love it if this one worked.
 

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