Scene_Exit Script

I named this script Scene_Exit. It's my first so it might be not very interresting when you look at the others scripts but, it's an useful script. This script asks the player whether they’d like to save & quit, quit or just return to their game. If the player is not allowed to save then the Save & Quit will be displayed in gray. The player can choose to go to title screen or really shutdown the game. Little something, this script replaces Scene_Menu, Scene_End and Scene_Save. If you need to edit any of those you should do it in the new Scene_Exit script.

  1. ################################################################################
  2. #                                                                              #
  3. #                                  Scene_Exit                                  #
  4. #                                                                              #
  5. #    By: NuKa_BuBble                                                           #
  6. #    Version: Final                                                            #
  7. #    Started: 23/10/2011                                                       #
  8. #                                                                              #
  9. #    You can find me on these websites:                                        #
  10. #    http://gameface101.playogame.com/                                         #
  11. #    http://www.hbgames.org/                                                   #
  12. #                                                                              #
  13. ################################################################################
  14.  
  15. class Scene_Exit
  16. def main
  17. s1 = "Save & exit"
  18. s2 = "Exit"
  19. s3 = "Cancel"
  20. @command_window = Window_Command.new(200, [s1, s2, s3])
  21. @command_window.x = 320 - @command_window.width / 2
  22. @command_window.y = 240 - @command_window.height / 2
  23. if $game_system.save_disabled
  24. # Disable save
  25.   @command_window.disable_item(0)
  26. end
  27. Graphics.transition
  28. loop do
  29. Graphics.update
  30. Input.update
  31. update
  32. if $scene != self
  33. break
  34. end
  35. end
  36. Graphics.freeze
  37. @command_window.dispose
  38. end
  39. def update
  40. @command_window.update
  41. if Input.trigger?(Input::B)
  42. $game_system.se_play($data_system.cancel_se)
  43. command_cancel
  44. return
  45. end
  46. if Input.trigger?(Input::C)
  47. case @command_window.index
  48. when 0
  49. # If saving is forbidden
  50.   if $game_system.save_disabled
  51.   # Play buzzer SE
  52.   $game_system.se_play($data_system.buzzer_se)
  53.   return
  54.   end
  55.   # Play decision SE
  56.   $game_system.se_play($data_system.decision_se)
  57.   # Switch to save screen
  58.   $scene = Scene_Save.new
  59. when 1
  60. command_leave
  61. when 2
  62.   command_cancel
  63. end
  64. return
  65. end
  66. end
  67. def command_leave
  68. $game_system.se_play($data_system.decision_se)
  69. Audio.bgm_fade(800)
  70. Audio.bgs_fade(800)
  71. Audio.me_fade(800)
  72. # If player choosed to title option
  73. if $quit_option == 1
  74. $scene = Scene_Title.new
  75. end
  76. # If player choosed Exit game option
  77. if $quit_option == 2
  78. $scene = nil
  79. end
  80. end
  81. def command_cancel
  82. $game_system.se_play($data_system.decision_se)
  83. Audio.bgm_fade(800)
  84. Audio.bgs_fade(800)
  85. Audio.me_fade(800)
  86. $quit_option = 0
  87. $scene = Scene_Menu.new
  88. end
  89. end
  90.  
  91. #==============================================================================
  92. # ** Scene_Save
  93. #------------------------------------------------------------------------------
  94. #  This class performs save screen processing.
  95. #==============================================================================
  96.  
  97. class Scene_Save < Scene_File
  98.   #--------------------------------------------------------------------------
  99.   # * Object Initialization
  100.   #--------------------------------------------------------------------------
  101.   def initialize
  102.     super("Which file would you like to save to?")
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # * Decision Processing
  106.   #--------------------------------------------------------------------------
  107.   def on_decision(filename)
  108.     # Play save SE
  109.     $game_system.se_play($data_system.save_se)
  110.     # Write save data
  111.     file = File.open(filename, "wb")
  112.     write_save_data(file)
  113.     file.close
  114.     # If called from event
  115.     if $game_temp.save_calling
  116.       # Clear save call flag
  117.       $game_temp.save_calling = false
  118.       # Switch to map screen
  119.       $scene = Scene_Map.new
  120.       return
  121.     end
  122.     # Switch to menu screen
  123.   if $quit_option == 0
  124.     $scene = Scene_Menu.new(4)
  125.   elsif $quit_option == 1
  126.     $scene = Scene_Title.new
  127.   elsif $quit_option == 2
  128.     $scene = nil
  129.   end
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # * Cancel Processing
  133.   #--------------------------------------------------------------------------
  134.   def on_cancel
  135.     # Play cancel SE
  136.     $game_system.se_play($data_system.cancel_se)
  137.     # If called from event
  138.     if $game_temp.save_calling
  139.       # Clear save call flag
  140.       $game_temp.save_calling = false
  141.       # Switch to map screen
  142.       $scene = Scene_Map.new
  143.       return
  144.     end
  145.     # Switch to menu screen
  146.     $scene = Scene_Menu.new(4)
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # * Write Save Data
  150.   #     file : write file object (opened)
  151.   #--------------------------------------------------------------------------
  152.   def write_save_data(file)
  153.     # Make character data for drawing save file
  154.     characters = []
  155.     for i in 0...$game_party.actors.size
  156.       actor = $game_party.actors[i]
  157.       characters.push([actor.character_name, actor.character_hue])
  158.     end
  159.     # Write character data for drawing save file
  160.     Marshal.dump(characters, file)
  161.     # Wrire frame count for measuring play time
  162.     Marshal.dump(Graphics.frame_count, file)
  163.     # Increase save count by 1
  164.     $game_system.save_count += 1
  165.     # Save magic number
  166.     # (A random value will be written each time saving with editor)
  167.     $game_system.magic_number = $data_system.magic_number
  168.     # Write each type of game object
  169.     Marshal.dump($game_system, file)
  170.     Marshal.dump($game_switches, file)
  171.     Marshal.dump($game_variables, file)
  172.     Marshal.dump($game_self_switches, file)
  173.     Marshal.dump($game_screen, file)
  174.     Marshal.dump($game_actors, file)
  175.     Marshal.dump($game_party, file)
  176.     Marshal.dump($game_troop, file)
  177.     Marshal.dump($game_map, file)
  178.     Marshal.dump($game_player, file)
  179.   end
  180. end
  181.  
  182. #==============================================================================
  183. # ** Scene_End
  184. #------------------------------------------------------------------------------
  185. #  This class performs game end screen processing.
  186. #==============================================================================
  187.  
  188. class Scene_End
  189.   #--------------------------------------------------------------------------
  190.   # * Main Processing
  191.   #--------------------------------------------------------------------------
  192.   def main
  193.     # Make command window
  194.     s1 = "Main menu"
  195.     s2 = "Close the game"
  196.     s3 = "Cancel"
  197.     @command_window = Window_Command.new(192, [s1, s2, s3])
  198.     @command_window.x = 320 - @command_window.width / 2
  199.     @command_window.y = 240 - @command_window.height / 2
  200.     # Execute transition
  201.     Graphics.transition
  202.     # Main loop
  203.     loop do
  204.       # Update game screen
  205.       Graphics.update
  206.       # Update input information
  207.       Input.update
  208.       # Frame Update
  209.       update
  210.       # Abort loop if screen is changed
  211.       if $scene != self
  212.         break
  213.       end
  214.     end
  215.     # Prepare for transition
  216.     Graphics.freeze
  217.     # Dispose of window
  218.     @command_window.dispose
  219.     # If switching to title screen
  220.     if $scene.is_a?(Scene_Title)
  221.       # Fade out screen
  222.       Graphics.transition
  223.       Graphics.freeze
  224.     end
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # * Frame Update
  228.   #--------------------------------------------------------------------------
  229.   def update
  230.     # Update command window
  231.     @command_window.update
  232.     # If B button was pressed
  233.     if Input.trigger?(Input::B)
  234.       # Play cancel SE
  235.       $game_system.se_play($data_system.cancel_se)
  236.       # Switch to menu screen
  237.       $scene = Scene_Menu.new(5)
  238.       return
  239.     end
  240.     # If C button was pressed
  241.     if Input.trigger?(Input::C)
  242.       # Branch by command window cursor position
  243.       case @command_window.index
  244.       when 0  # to title
  245.         $quit_option = 1
  246.         command_to_title
  247.       when 1  # shutdown
  248.         $quit_option = 2
  249.         command_shutdown
  250.       when 2  # quit
  251.         $quit_option = 0
  252.         command_cancel
  253.       end
  254.       return
  255.     end
  256.   end
  257.   #--------------------------------------------------------------------------
  258.   # * Process When Choosing [To Title] Command
  259.   #--------------------------------------------------------------------------
  260.   def command_to_title
  261.     # Play decision SE
  262.     $game_system.se_play($data_system.decision_se)
  263.     # Fade out BGM, BGS, and ME
  264.     Audio.bgm_fade(800)
  265.     Audio.bgs_fade(800)
  266.     Audio.me_fade(800)
  267.     # Switch to title screen
  268.     $scene = Scene_Exit.new
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Process When Choosing [Shutdown] Command
  272.   #--------------------------------------------------------------------------
  273.   def command_shutdown
  274.     # Play decision SE
  275.     $game_system.se_play($data_system.decision_se)
  276.     # Fade out BGM, BGS, and ME
  277.     Audio.bgm_fade(800)
  278.     Audio.bgs_fade(800)
  279.     Audio.me_fade(800)
  280.     # Shutdown
  281.     $scene = Scene_Exit.new
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # *  Process When Choosing [Cancel] Command
  285.   #--------------------------------------------------------------------------
  286.   def command_cancel
  287.     # Play decision SE
  288.     $game_system.se_play($data_system.decision_se)
  289.     # Switch to menu screen
  290.     $scene = Scene_Menu.new(5)
  291.   end
  292. end
  293.  
  294. #==============================================================================
  295. # ** Scene_Menu
  296. #------------------------------------------------------------------------------
  297. #  This class performs menu screen processing.
  298. #==============================================================================
  299.  
  300. class Scene_Menu
  301.   #--------------------------------------------------------------------------
  302.   # * Object Initialization
  303.   #     menu_index : command cursor's initial position
  304.   #--------------------------------------------------------------------------
  305.   def initialize(menu_index = 0)
  306.     @menu_index = menu_index
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # * Main Processing
  310.   #--------------------------------------------------------------------------
  311.   def main
  312.     # Make command window
  313.     s1 = $data_system.words.item
  314.     s2 = $data_system.words.skill
  315.     s3 = $data_system.words.equip
  316.     s4 = "Status"
  317.     s5 = "Save"
  318.     s6 = "End Game"
  319.     @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
  320.     @command_window.index = @menu_index
  321.     # If number of party members is 0
  322.     if $game_party.actors.size == 0
  323.       # Disable items, skills, equipment, and status
  324.       @command_window.disable_item(0)
  325.       @command_window.disable_item(1)
  326.       @command_window.disable_item(2)
  327.       @command_window.disable_item(3)
  328.     end
  329.     # If save is forbidden
  330.     if $game_system.save_disabled
  331.       # Disable save
  332.       @command_window.disable_item(4)
  333.     end
  334.     # Make play time window
  335.     @playtime_window = Window_PlayTime.new
  336.     @playtime_window.x = 0
  337.     @playtime_window.y = 224
  338.     @command_window.height = 224
  339.     # Make steps window
  340.     @steps_window = Window_Steps.new
  341.     @steps_window.x = 0
  342.     @steps_window.y = 320
  343.     # Make gold window
  344.     @gold_window = Window_Gold.new
  345.     @gold_window.x = 0
  346.     @gold_window.y = 416
  347.     # Make status window
  348.     @status_window = Window_MenuStatus.new
  349.     @status_window.x = 160
  350.     @status_window.y = 0
  351.     # Execute transition
  352.     Graphics.transition
  353.     # Main loop
  354.     loop do
  355.       # Update game screen
  356.       Graphics.update
  357.       # Update input information
  358.       Input.update
  359.       # Frame update
  360.       update
  361.       # Abort loop if screen is changed
  362.       if $scene != self
  363.         break
  364.       end
  365.     end
  366.     # Prepare for transition
  367.     Graphics.freeze
  368.     # Dispose of windows
  369.     @command_window.dispose
  370.     @playtime_window.dispose
  371.     @steps_window.dispose
  372.     @gold_window.dispose
  373.     @status_window.dispose
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # * Frame Update
  377.   #--------------------------------------------------------------------------
  378.   def update
  379.     # Update windows
  380.     @command_window.update
  381.     @playtime_window.update
  382.     @steps_window.update
  383.     @gold_window.update
  384.     @status_window.update
  385.     # If command window is active: call update_command
  386.     if @command_window.active
  387.       update_command
  388.       return
  389.     end
  390.     # If status window is active: call update_status
  391.     if @status_window.active
  392.       update_status
  393.       return
  394.     end
  395.   end
  396.   #--------------------------------------------------------------------------
  397.   # * Frame Update (when command window is active)
  398.   #--------------------------------------------------------------------------
  399.   def update_command
  400.     # If B button was pressed
  401.     if Input.trigger?(Input::B)
  402.       # Play cancel SE
  403.       $game_system.se_play($data_system.cancel_se)
  404.       # Switch to map screen
  405.       $scene = Scene_Map.new
  406.       return
  407.     end
  408.     # If C button was pressed
  409.     if Input.trigger?(Input::C)
  410.       # If command other than save or end game, and party members = 0
  411.       if $game_party.actors.size == 0 and @command_window.index < 4
  412.         # Play buzzer SE
  413.         $game_system.se_play($data_system.buzzer_se)
  414.         return
  415.       end
  416.       # Branch by command window cursor position
  417.       case @command_window.index
  418.       when 0  # item
  419.         # Play decision SE
  420.         $game_system.se_play($data_system.decision_se)
  421.         # Switch to item screen
  422.         $scene = Scene_Item.new
  423.       when 1  # skill
  424.         # Play decision SE
  425.         $game_system.se_play($data_system.decision_se)
  426.         # Make status window active
  427.         @command_window.active = false
  428.         @status_window.active = true
  429.         @status_window.index = 0
  430.       when 2  # equipment
  431.         # Play decision SE
  432.         $game_system.se_play($data_system.decision_se)
  433.         # Make status window active
  434.         @command_window.active = false
  435.         @status_window.active = true
  436.         @status_window.index = 0
  437.       when 3  # status
  438.         # Play decision SE
  439.         $game_system.se_play($data_system.decision_se)
  440.         # Make status window active
  441.         @command_window.active = false
  442.         @status_window.active = true
  443.         @status_window.index = 0
  444.       when 4  # save
  445.         # If saving is forbidden
  446.         if $game_system.save_disabled
  447.           # Play buzzer SE
  448.           $game_system.se_play($data_system.buzzer_se)
  449.           return
  450.         end
  451.         # Play decision SE
  452.         $game_system.se_play($data_system.decision_se)
  453.         # Switch to save screen
  454.         $quit_option = 0
  455.         $scene = Scene_Save.new
  456.       when 5  # end game
  457.         # Play decision SE
  458.         $game_system.se_play($data_system.decision_se)
  459.         # Switch to end game screen
  460.         $scene = Scene_End.new
  461.       end
  462.       return
  463.     end
  464.   end
  465.   #--------------------------------------------------------------------------
  466.   # * Frame Update (when status window is active)
  467.   #--------------------------------------------------------------------------
  468.   def update_status
  469.     # If B button was pressed
  470.     if Input.trigger?(Input::B)
  471.       # Play cancel SE
  472.       $game_system.se_play($data_system.cancel_se)
  473.       # Make command window active
  474.       @command_window.active = true
  475.       @status_window.active = false
  476.       @status_window.index = -1
  477.       return
  478.     end
  479.     # If C button was pressed
  480.     if Input.trigger?(Input::C)
  481.       # Branch by command window cursor position
  482.       case @command_window.index
  483.       when 1  # skill
  484.         # If this actor's action limit is 2 or more
  485.         if $game_party.actors[@status_window.index].restriction >= 2
  486.           # Play buzzer SE
  487.           $game_system.se_play($data_system.buzzer_se)
  488.           return
  489.         end
  490.         # Play decision SE
  491.         $game_system.se_play($data_system.decision_se)
  492.         # Switch to skill screen
  493.         $scene = Scene_Skill.new(@status_window.index)
  494.       when 2  # equipment
  495.         # Play decision SE
  496.         $game_system.se_play($data_system.decision_se)
  497.         # Switch to equipment screen
  498.         $scene = Scene_Equip.new(@status_window.index)
  499.       when 3  # status
  500.         # Play decision SE
  501.         $game_system.se_play($data_system.decision_se)
  502.         # Switch to status screen
  503.         $scene = Scene_Status.new(@status_window.index)
  504.       end
  505.       return
  506.     end
  507.   end
  508. end
  509.  
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76001