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.

If battle is won, x happens...

Jason

Awesome Bro

Okay, the title may seem confusing, but you know how, if you make a battle in an event, you can have a Victory handler, so if you win, something can happen ?

Well basically, I would like to know, is there a way to do this with random battles ? It'd probably have something to do with scripts lol, I can't seem to get anything to work.

Thanks to anyone that can work something out here, and if you need me to explain further, just say so :thumb:
 

mawk

Sponsor

The simple solution would be to turn a switch on during the battle (presumably after the enemies are defeated,) then have an autorun event on the map that depends on that switch.

Would that do what you need it to?
 

Jason

Awesome Bro

Hmm, that sounds like a good idea, I'll test it out then come back and tell you my findings, lol.

Edit---

Hmm, I've tried it, and it fails, even using a common event won't work.
Thanks for trying though  :thumb:
 
Paste in a new script above Main, below Scene_Debug

Code:
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  # * Edit here to indicate which troops will turn on what switch,
  # in the format: {troop => switch_to_turn_on, troop2 => another_switch} etc
  #--------------------------------------------------------------------------
  BATTLE_VICTORY_SWITCHES = {1 => 1}
  #--------------------------------------------------------------------------
  # * Alias definitions
  #--------------------------------------------------------------------------
  alias jbrist_battle_victory_switches_battle_end battle_end
  #--------------------------------------------------------------------------
  # * Battle Ends
  #     result : results (0:win 1:lose 2:escape)
  #--------------------------------------------------------------------------
  def battle_end(result)
    jbrist_battle_victory_switches_battle_end(result)
    if BATTLE_VICTORY_SWITCHES.include?(@troop_id) and result == 0
      $game_switches[BATTLE_VICTORY_SWITCHES[@troop_id]] = true
    end
  end
end
 
the script's fucking instructions":3nly311v said:
#--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  # * Edit here to indicate which troops will turn on what switch,
  # in the format: {troop => switch_to_turn_on, troop2 => another_switch} etc
 

Jason

Awesome Bro

Oh yeah lol, sorry about that, hehe.

Thanks it works perfect :thumb:

Just a question, if I want something to happen when I loose, would I add:

  BATTLE_LOSE_SWITCHES = {x => x}    Where x = numbers

below

  BATTLE_VICTORY_SWITCHES = {1 => 10}
 
You could have said that in the op or avoided this line
you can have a Victory handler
and it would have saved me making the first one

Code:
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  # * Edit here to indicate which troops will turn on what switch,
  # in the format: {troop => switch_to_turn_on, troop2 => another_switch} etc
  #--------------------------------------------------------------------------
  BATTLE_VICTORY_SWITCHES = {1 => 1}
  BATTLE_LOSS_SWITCHES = {2 => 2}
  #--------------------------------------------------------------------------
  # * Battle Ends
  #     result : results (0:win 1:lose 2:escape)
  #--------------------------------------------------------------------------
  def battle_end(result)
    # Clear in battle flag
    $game_temp.in_battle = false
    # Clear entire party actions flag
    $game_party.clear_actions
    # Remove battle states
    for actor in $game_party.actors
      actor.remove_states_battle
    end
    # Clear enemies
    $game_troop.enemies.clear
    # Call battle callback
    unless BATTLE_LOSS_SWITCHES.include?(@troop_id)
      if $game_temp.battle_proc != nil
        $game_temp.battle_proc.call(result)
        $game_temp.battle_proc = nil
      end
    else
      $scene = Scene_Map.new
    end
    # Switch to map screen
    $scene = Scene_Map.new
    if BATTLE_VICTORY_SWITCHES.include?(@troop_id) and result == 0
      $game_switches[BATTLE_VICTORY_SWITCHES[@troop_id]] = true
    end
  end
  #--------------------------------------------------------------------------
  # * Determine Battle Win/Loss Results
  #--------------------------------------------------------------------------
  def judge
    # If all dead determinant is true, or number of members in party is 0
    if $game_party.all_dead? or $game_party.actors.size == 0
      # If possible to lose
      if $game_temp.battle_can_lose
        # Return to BGM before battle starts
        $game_system.bgm_play($game_temp.map_bgm)
        # Battle ends
        battle_end(2)
        # Return true
        return true
      end
      # Set game over flag
      unless BATTLE_LOSS_SWITCHES.include?(@troop_id)
        $game_temp.gameover = true 
      else
        $scene = Scene_Map.new
        $game_switches[BATTLE_LOSS_SWITCHES[@troop_id]] = true
      end
      # Return true
      return true
    end
    # Return false if even 1 enemy exists
    for enemy in $game_troop.enemies
      if enemy.exist?
        return false
      end
    end
    # Start after battle phase (win)
    start_phase5
    # Return true
    return true
  end
end
 

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