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.

Modification of Scene Battle 1

SP27

Sponsor

Hello everyone.
Before I continue, let me tell you that I have no expert level of scripting knowledge, just so you all know. :biggrin:

Okay, now for my problem with RMXP's default script; Scene_Battle (part 1)

What I wanted to get:
Make 2 ways to go 'game over', method one; the original way and method 2; that will trigger a common event.

Now please take a look on line 277 to 292:
Code:
#==============================================================================

# ** Scene_Battle (part 1)

#------------------------------------------------------------------------------

#  This class performs battle screen processing.

#==============================================================================

 

class Scene_Battle

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Initialize each kind of temporary battle data

    $game_temp.in_battle = true

    $game_temp.battle_turn = 0

    $game_temp.battle_event_flags.clear

    $game_temp.battle_abort = false

    $game_temp.battle_main_phase = false

    $game_temp.battleback_name = $game_map.battleback_name

    $game_temp.forcing_battler = nil

    # Initialize battle event interpreter

    $game_system.battle_interpreter.setup(nil, 0)

    # Prepare troop

    @troop_id = $game_temp.battle_troop_id

    $game_troop.setup(@troop_id)

    # Make actor command window

    s1 = $data_system.words.attack

    s2 = $data_system.words.skill

    s3 = $data_system.words.guard

    s4 = $data_system.words.item

    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])

    @actor_command_window.y = 160

    @actor_command_window.back_opacity = 160

    @actor_command_window.active = false

    @actor_command_window.visible = false

    # Make other windows

    @party_command_window = Window_PartyCommand.new

    @help_window = Window_Help.new

    @help_window.back_opacity = 160

    @help_window.visible = false

    @status_window = Window_BattleStatus.new

    @message_window = Window_Message.new

    # Make sprite set

    @spriteset = Spriteset_Battle.new

    # Initialize wait count

    @wait_count = 0

    # Execute transition

    if $data_system.battle_transition == ""

      Graphics.transition(20)

    else

      Graphics.transition(77, "Graphics/Transitions/" +

        $data_system.battle_transition)

    end

    # Start pre-battle phase

    start_phase1

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Refresh map

    $game_map.refresh

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @actor_command_window.dispose

    @party_command_window.dispose

    @help_window.dispose

    @status_window.dispose

    @message_window.dispose

    if @skill_window != nil

      @skill_window.dispose

    end

    if @item_window != nil

      @item_window.dispose

    end

    if @result_window != nil

      @result_window.dispose

    end

    # Dispose of sprite set

    @spriteset.dispose

    # If switching to title screen

    if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end

    # If switching from battle test to any screen other than game over screen

    if $BTEST and not $scene.is_a?(Scene_Gameover)

      $scene = nil

    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

      $game_temp.gameover = true

      # 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

  #--------------------------------------------------------------------------

  # * 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

    if $game_temp.battle_proc != nil

      $game_temp.battle_proc.call(result)

      $game_temp.battle_proc = nil

    end

    # Switch to map screen

    $scene = Scene_Map.new

  end

  #--------------------------------------------------------------------------

  # * Battle Event Setup

  #--------------------------------------------------------------------------

  def setup_battle_event

    # If battle event is running

    if $game_system.battle_interpreter.running?

      return

    end

    # Search for all battle event pages

    for index in 0...$data_troops[@troop_id].pages.size

      # Get event pages

      page = $data_troops[@troop_id].pages[index]

      # Make event conditions possible for reference with c

      c = page.condition

      # Go to next page if no conditions are appointed

      unless c.turn_valid or c.enemy_valid or

             c.actor_valid or c.switch_valid

        next

      end

      # Go to next page if action has been completed

      if $game_temp.battle_event_flags[index]

        next

      end

      # Confirm turn conditions

      if c.turn_valid

        n = $game_temp.battle_turn

        a = c.turn_a

        b = c.turn_b

        if (b == 0 and n != a) or

           (b > 0 and (n < 1 or n < a or n % b != a % b))

          next

        end

      end

      # Confirm enemy conditions

      if c.enemy_valid

        enemy = $game_troop.enemies[c.enemy_index]

        if enemy == nil or enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp

          next

        end

      end

      # Confirm actor conditions

      if c.actor_valid

        actor = $game_actors[c.actor_id]

        if actor == nil or actor.hp * 100.0 / actor.maxhp > c.actor_hp

          next

        end

      end

      # Confirm switch conditions

      if c.switch_valid

        if $game_switches[c.switch_id] == false

          next

        end

      end

      # Set up event

      $game_system.battle_interpreter.setup(page.list, 0)

      # If this page span is [battle] or [turn]

      if page.span <= 1

        # Set action completed flag

        $game_temp.battle_event_flags[index] = true

      end

      return

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # If battle event is running

    if $game_system.battle_interpreter.running?

      # Update interpreter

      $game_system.battle_interpreter.update

      # If a battler which is forcing actions doesn't exist

      if $game_temp.forcing_battler == nil

        # If battle event has finished running

        unless $game_system.battle_interpreter.running?

          # Rerun battle event set up if battle continues

          unless judge

            setup_battle_event

          end

        end

        # If not after battle phase

        if @phase != 5

          # Refresh status window

          @status_window.refresh

        end

      end

    end

    # Update system (timer) and screen

    $game_system.update

    $game_screen.update

    # If timer has reached 0

    if $game_system.timer_working and $game_system.timer == 0

      # Abort battle

      $game_temp.battle_abort = true

    end

    # Update windows

    @help_window.update

    @party_command_window.update

    @actor_command_window.update

    @status_window.update

    @message_window.update

    # Update sprite set

    @spriteset.update

    # If transition is processing

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      if $game_temp.transition_name == ""

        Graphics.transition(20)

      else

        Graphics.transition(40, "Graphics/Transitions/" +

          $game_temp.transition_name)

      end

    end

    # If message window is showing

    if $game_temp.message_window_showing

      return

    end

    # If effect is showing

    if @spriteset.effect?

      return

    end

    # If game over

    if $game_temp.gameover

      # Switch to game over or defeated screen [Marked]

      if $game_switches[327] == false

         $game_system.bgm_play($game_temp.map_bgm)

         # Battle ends

         battle_end(2)

         # Back to map

         $scene = Scene_Map.new

         # Trigger Common Event

         $data_common_events[170].trigger

      elsif $game_switches[327] == true

        $scene = Scene_Gameover.new

      return

    end

    end

    # If returning to title screen

    if $game_temp.to_title

      # Switch to title screen

      $scene = Scene_Title.new

      return

    end

    # If battle is aborted

    if $game_temp.battle_abort

      # Return to BGM used before battle started

      $game_system.bgm_play($game_temp.map_bgm)

      # Battle ends

      battle_end(1)

      return

    end

    # If waiting

    if @wait_count > 0

      # Decrease wait count

      @wait_count -= 1

      return

    end

    # If battler forcing an action doesn't exist,

    # and battle event is running

    if $game_temp.forcing_battler == nil and

       $game_system.battle_interpreter.running?

      return

    end

    # Branch according to phase

    case @phase

    when 1  # pre-battle phase

      update_phase1

    when 2  # party command phase

      update_phase2

    when 3  # actor command phase

      update_phase3

    when 4  # main phase

      update_phase4

    when 5  # after battle phase

      update_phase5

    end

  end

end
For as far as my knowledge goes, this should bring the player back to the map and trigger the second game over method if the switch is OFF and when the switch is ON it's the normal game over method is triggered, which works just a-ok.

What happens though, when the switch is OFF and the player loses it does end the battle and it does go back to the map BUT it will not trigger the common event and instead it just goes to the game over screen.

Have I overlooked something or am I just plain stupid? :haha:
Thank you for your time.
 
Try battle_end(1) instead of battle_end(2).

I think $data_common_events[170].trigger won't work because it just returns the triggertype of the Common Event.
It would be much easier to call the Common Event in a Parallel Process/Autostart instead of calling it with a script.
 

SP27

Sponsor

I've tried battle_end(*) *0~3 and I've also tried to use a trigger switch like you said to trigger a auto run event, but nothing.

Instead it either stops or I can walk on the map endlessly without being able to call debug, trigger any events nor call the menu. :eek::

It's too bad I'm at a halt right now because I was on a roll with other modifications.

Thank you for trying.
 
I'm only guessing here, but I believe
$game_temp.gameover cannot be true if you want to keep running the game (and call a common event). If you use the 2nd GameOver, pull a switch like $game_switches[328] = true, and reset $game_temp.gameover to false.
Make your common event start when switch 328 is ON.
 
Okay... this works :3
Code:
class Scene_Battle

  

  Switch_Which_Has_To_Be_On_If_Gameover_Will_Be_Normal = 327

  Switch_Which_Is_Set_To_On_When_You_Go_Gameover_In_The_New_Way = 328

  

  def frame_update_game_over_nb

    if $game_temp.gameover

      if $game_switches[Switch_Which_Has_To_Be_On_If_Gameover_Will_Be_Normal] == true

        $scene = Scene_Gameover.new

        return

      else

        $game_temp.battle_abort = true

        $game_switches[Switch_Which_Is_Set_To_On_When_You_Go_Gameover_In_The_New_Way] = true

      end

    end

  end

  

  alias_method :sdgfuandfasgduibasdf, :main

  def main

    sdgfuandfasgduibasdf

    b = $game_switches[Switch_Which_Has_To_Be_On_If_Gameover_Will_Be_Normal]

    $game_temp.gameover = $game_temp.gameover && b

  end

  

  def update

    if $game_system.battle_interpreter.running?

      $game_system.battle_interpreter.update

      if $game_temp.forcing_battler == nil

        unless $game_system.battle_interpreter.running?

          unless judge

            setup_battle_event

          end

        end

        if @phase != 5

          @status_window.refresh

        end

      end

    end

    $game_system.update

    $game_screen.update

    if $game_system.timer_working and $game_system.timer == 0

      $game_temp.battle_abort = true

    end

    @help_window.update

    @party_command_window.update

    @actor_command_window.update

    @status_window.update

    @message_window.update

    @spriteset.update

    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

    if @spriteset.effect?

      return

    end

    frame_update_game_over_nb

    if $game_temp.to_title

      $scene = Scene_Title.new

      return

    end

    if $game_temp.battle_abort

      $game_system.bgm_play($game_temp.map_bgm)

      battle_end(1)

      return

    end

    if @wait_count > 0

      @wait_count -= 1

      return

    end

    if $game_temp.forcing_battler == nil and

       $game_system.battle_interpreter.running?

      return

    end

    case @phase

    when 1; update_phase1

    when 2; update_phase2

    when 3; update_phase3

    when 4; update_phase4

    when 5; update_phase5

    end

  end

end

 

class Interpreter

  def command_311

    value = operate_value(@parameters[1], @parameters[2], @parameters[3])

    iterate_actor(@parameters[0]) do |actor|

      if actor.hp > 0

        if @parameters[4] == false and actor.hp + value <= 0

          actor.hp = 1

        else

          actor.hp += value

        end

      end

    end

    n = Scene_Battle::Switch_Which_Has_To_Be_On_If_Gameover_Will_Be_Normal

    $game_temp.gameover = $game_party.all_dead? && $game_switches[n]

    return true

  end

end

You can define one switch, which is responsible for normal Gameover (when ON) and Just-Return-To-Map-And-Call-Common-Event-Gameover (when OFF) and one switch, which will be set to ON when you lose in your special way so you can call a Common Event with it :)
 

SP27

Sponsor

Awesome! It does work, but I seem to have hit a snag I'm afraid... :cry:

You see, it loops the common event endlessly and I have no idea why this occurs.
Have a look on this common event setup. (it's CE#170 I actually have over 500 common events.)

Please keep in mind that this event is still being developed, I just need a proof of concept before I'll pour myself into perfecting this system. (I.E variable re-spawn places, and so forth.)
event.png
As you can see it just puts the player to another map, healed and fixed and in this case a house, but the event runs everything except for the transfer player command and it just loops loops and then loops some more and then just to loop it loops again. You get the picture :tongue:

Now, I do not know if this is a script mistake, an event mistake or just plain old over sight on my end, but yeah that's what's the problem now I'm afraid.

I'm wondering though, where have you put the common event ID? I cannot find it! :crazy:

Thanks again for your trouble.

EDIT

Scratch all that!
It was an over sight on my end. :haha:

I've got it working now!
Thank you very, very much!
You actually went through all the trouble of making a script from scratch! :biggrin:

You should go ahead and publish it since it's your work. :thumb:
As a matter of fact, this was the final modification/feature I needed for my ambitious project!

So, to go straight to the point, how would you like to be credited?
Neo-Bahamut, or another alias?

I cannot thank you enough for your assistance.

Just out of my own curiosity and eager to learn, but what's up with the alias method called sdgfuandfasgduibasdf?
Is that actual ruby language or could such a thing be anything you want?

No need to answer that if you don't want to, but I cannot help but wonder why it's like that. :tongue:
 
So, to go straight to the point, how would you like to be credited?
Neo-Bahamut, or another alias?
Neo-Bahamut, please :)

Is that actual ruby language or could such a thing be anything you want?
It's just the name of a method. I could also have named it neo_bahamuts_script_alias_switch_makes_another_game_over_code_made_for_sp27 ;D
And also it could have been Scene_Banana or Asgiusbngsdh instead of Scene_Battle. It's just to help other people understanding your code ;)
 

SP27

Sponsor

Neo-Bahamut it is! :biggrin:
Neo-Bahamut":3tpnmavv said:
It's just the name of a method. I could also have named it neo_bahamuts_script_alias_switch_makes_another_game_over_code_made_for_sp27 ;D
And also it could have been Scene_Banana or Asgiusbngsdh instead of Scene_Battle. It's just to help other people understanding your code ;)

:haha: I thought scripting was 100x more strict, little did I know you could have something called Scene_Banana! :tongue:

Thanks again Neo-Bahamut. :grin:
 

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