[XP] Gameover with Quick Restart Options

Started by karldaylo, May 08, 2011, 01:44:45 am

Previous topic - Next topic

karldaylo

May 08, 2011, 01:44:45 am Last Edit: May 09, 2011, 03:59:16 am by karldaylo
Gameover Menu
Authors: Karl D
Version: 1.30
Type: GameOver Add-on
Key Term: Title / Save / Load / GameOver Add-on



Introduction

Inspired with Alundra's Gameover Scene,
this is my first script that i made, if you found a problem or logical error within my script, please tell me how should i resolve it :P


Features


  • Fade to black Before Gameover Graphics to show up

  • Optional Menu on Game over

  • Quick Restart/Quick Load last saved Game




Screenshots

Spoiler: ShowHide



Demo

-None-


Script


Spoiler: ShowHide
Quote
#==============================================================================
# Gameover addon thingie
# by Karl D
#------------------------------------------------------------------------------
# ver 1.3
#==============================================================================
class Scene_Gameover
#------------------------------------------------------------------------------
# Main Processing
#------------------------------------------------------------------------------
 def main
   # Make game over graphic
   @sprite = Sprite.new
   # Stop all unnesesary sound
   $game_system.bgm_play(nil)
   $game_system.bgs_play(nil)
   $game_system.me_play(nil)
   $game_system.se_play(nil)    
   # Execute transition
   Graphics.transition(75)
   # Prepare for transition
   Graphics.freeze    
   # Play game over ME
   $game_system.me_play($data_system.gameover_me)
   # Creates gameover graphic
   @sprite.bitmap = RPG::Cache.gameover($data_system.gameover_name)
   # Execute transition
   Graphics.transition(120)
  @sprite.bitmap = RPG::Cache.gameover($data_system.gameover_name)
   # Make command window
   s1 = "Quick Restart"
   s2 = "Load Game"
   s3 = "Return to Title"
   @command_window = Window_Command.new(192, [s1, s2, s3])
   @command_window.back_opacity = 200
   @command_window.x = 320 - @command_window.width / 2
   @command_window.y = 370 - @command_window.height / 2
   # Saved Game data determinant
   # Disable "Load Game" option
   @continue_enabled = false
   for i in 0..3
     # If any save file exist
     if FileTest.exist?("Save#{i+1}.rxdata")
       # Enable "Load Game" option
       @continue_enabled = true
     end
   end
   # if "Load Game" option is enabled
   if @continue_enabled
     # Enable "Load Game" button
     @command_window.index = 1
   else
     # Disable "Load Game" button
     @command_window.disable_item(1)
   end
   # Enable "Quick Restart" option
   @restart_enabled = true
   # Last Saved Game from present session determinant
   # If save file from present session exist
   if $game_system.last_save < 1
    # Disable "Quick Restart" options
    @restart_enabled = false
  end
   # If "Quick Restart" options disabled
   if @restart_enabled == false
     # Disable "Quick Restart" button
     @command_window.disable_item(0)
   end    
   # Execute transition
   Graphics.transition(120)
   # 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
   # Prepare for transition
   Graphics.freeze
   # Dispose everything
   @sprite.bitmap.dispose
   @sprite.dispose
   @command_window.dispose
   Graphics.transition(40)
 end
#------------------------------------------------------------------------------
# Frame Update
#------------------------------------------------------------------------------
 def update
   # Update command window
   @command_window.update
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play buzzer SE
     $game_system.se_play($data_system.buzzer_se)
     return
   end
   # If C button was pressed
   if Input.trigger?(Input::C)
     # Branch by command window cursor position
     case @command_window.index
     when 0  #to quick restart
        command_to_Restart
     when 1  #to load
       command_Load
     when 2  #to title
       command_title
     end
     return
   end
 end
#------------------------------------------------------------------------------
# Process When Choosing [Quick Restart] Command
#------------------------------------------------------------------------------
 def command_to_Restart
   # If Restart is disabled
   unless @restart_enabled
     # Play buzzer SE
     $game_system.se_play($data_system.buzzer_se)
     return
   end
   #Play decision SE
   $game_system.se_play($data_system.decision_se)
   #Quick Load save data
   file = File.open("Save#{$game_system.last_save}.rxdata", "rb")
   read_save_data(file)
   file.close
   # Restore BGM and BGS
   $game_system.bgm_play($game_system.playing_bgm)
   $game_system.bgs_play($game_system.playing_bgs)
   # Update map (run parallel process event)
   $game_map.update
   # Switch to map screen
   $scene = Scene_Map.new    
 end
#------------------------------------------------------------------------------
# Process When Choosing [Load Game] Command
#------------------------------------------------------------------------------
 def command_Load
   # If Restart is disabled
   unless @continue_enabled
     # Play buzzer SE
     $game_system.se_play($data_system.buzzer_se)
     return
   end
   #Play desicion SE
   $game_system.se_play($data_system.decision_se)
   #Load Scene_load
   $scene = Scene_Load.new
 end
#------------------------------------------------------------------------------
# Process When Choosing [Return to Title] Command
#------------------------------------------------------------------------------
   def command_title
    #Play desicion SE
   $game_system.se_play($data_system.decision_se)
   $scene = Scene_Title.new
   end
#------------------------------------------------------------------------------
# * Read Save Data
#   file : file object for reading (opened)
#------------------------------------------------------------------------------
 def read_save_data(file)
   # Read character data for drawing save file
   characters = Marshal.load(file)
   # Read frame count for measuring play time
   Graphics.frame_count = Marshal.load(file)
   # Read each type of game object
   $game_system        = Marshal.load(file)
   $game_switches      = Marshal.load(file)
   $game_variables     = Marshal.load(file)
   $game_self_switches = Marshal.load(file)
   $game_screen        = Marshal.load(file)
   $game_actors        = Marshal.load(file)
   $game_party         = Marshal.load(file)
   $game_troop         = Marshal.load(file)
   $game_map           = Marshal.load(file)
   $game_player        = Marshal.load(file)
   # If magic number is different from when saving
   # (if editing was added with editor)
   if $game_system.magic_number != $data_system.magic_number
     # Load map
     $game_map.setup($game_map.map_id)
     $game_player.center($game_player.x, $game_player.y)
   end
   # Refresh party members
   $game_party.refresh
 end  
   # If battle test
   if $BTEST
     $scene = nil
   end
 
end
#=============================================================================
# * game_guy's cool script
#   it actually exist!!!!
#=============================================================================
class Game_System
 attr_accessor :last_save
 alias gg_init_quick_restart_lat initialize
 def initialize
   @last_save = 0
   return gg_init_quick_restart_lat
 end
end
class Scene_Save
 alias gg_save_last_save_lat on_decision
 def on_decision(filename)
   $game_system.last_save = @file_index + 1
   gg_save_last_save_lat(filename)
 end
end




Instructions

Plug and Play


Compatibility

PLEASE LIST AS MANY COMPATIBILITY ISSUES AS YOU CAN IF THERE ARE ANY


Credits and Thanks


  • Karl D - creator

  • Game_guy - for helping me out how to figure thing out

  • Darklord and Blue Elf - for their autosave script(removed)




Author's Notes

My first time scripting, sorry if its full of bug(if ther is one)
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

Zexion


Spaceman McConaughey


karldaylo

Quote from: Zexion on May 08, 2011, 02:20:31 am
what does the quick restart do?


it loads last saved game... the latest one... instantly
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

G_G

Great (first?) script. Easy, a bit redundant coding wise, but useful.

I was going to have an entire post on how the script could be more efficient, I than realized before I posted that I ended up writing an entire script for you. (Not cool) Anyways, just some pointers on improving this.

  • Instead of saving Quick.rxdata, you could check to see which last save was chosen

    • This'll require some work, add a variable to Game_System called "last_save"

    • In Scene_Save under on_decision, write before the line "write_data" add $game_system.last_save = @file_index

  • Instead of having a whole different game over scene (Scene_GameoverS) just use the original Scene_Gameover, no need to make another class. You're already making the old Scene_Gameover unusable, might as well just add in your code in there.

  • On your Quick Restart option, make it load up the last save by checking to see if there has been a last save.

    • check to see if $game_system.last_save is greater then 0, if so load the file

    • Get the filename by doing this "filename = "Save#{$game_system.last_save}.rxdata"



This will make it so Quick.rxdata isn't even saved. Less code, no need for that module to write and delete the save data. And its much more efficient over all since you're not saving data twice when you save. A bit redundant.

karldaylo

Thanks, and yes it is my first script :) well im not bit familliar with "varible" till this noon (my timezone)
and i just put things together up (the scene which has option menu in it is actually a copy of scene_end, i modify it so its usable to gameover scene :P ) and im not yet much fammiliar with ruby scripting,

and thats the reason why i made new class scene gameovers, the whole thing is actually just a put up together peices and modify it so it produce what i want it to do,...
but hey, im learning thanks to you :D now im able to make it better
(but there is onething bugging me, is this method of yours work even the game were closed after saving? is this part of the script will be it what state it was befor the game were closed?)

sorry for the bad english :)
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

G_G

May 08, 2011, 05:27:13 am #6 Last Edit: May 08, 2011, 05:29:54 am by Gagmon
The variable "last_save" that you added in Game_System gets saved with the Save file. So when you load a saved game, it'll load the last save file that saved game recorded. I could post my version of it real fast to show you how it works, maybe you could learn off of it.

EDIT:
This small code here, keeps track of the last save file that was saved to. Pretty small, nice and efficient. This does not have the game over yet and it does not have the loading of the save.
class Game_System
 attr_accessor :last_save
 alias gg_init_quick_restart_lat initialize
 def initialize
   @last_save = 0
   return gg_init_quick_restart_lat
 end
end
class Scene_Save
 alias gg_save_last_save_lat on_decision
 def on_decision(filename)
   $game_system.last_save = @file_index
   gg_save_last_save_lat
 end
end

karldaylo

RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

G_G

May 08, 2011, 05:37:23 am #8 Last Edit: May 08, 2011, 05:40:34 am by Gagmon
Heres my version of the script. It basically gives you an idea of how to setup a configuration, how to use it, how to alias old methods and call them for later. I didn't comment any of the code. I could if you want me to.
# Quick Restart
module Restart
 QUICK_RESTART_TEXT   = "Quick Restart"
 TO_TITLE_TEXT        = "Return to Title"
 EXIT_GAME_TEXT       = "Quit Game"
end
class Game_System
 attr_accessor :last_save
 alias gg_init_quick_restart_lat initialize
 def initialize
   @last_save = 0
   return gg_init_quick_restart_lat
 end
end
class Scene_Save
 alias gg_save_last_save_lat on_decision
 def on_decision(filename)
   $game_system.last_save = @file_index + 1
   gg_save_last_save_lat(filename)
 end
end
class Scene_Gameover
 def main
   @sprite = Sprite.new
   @sprite.bitmap = RPG::Cache.gameover($data_system.gameover_name)
   $game_system.bgm_play(nil)
   $game_system.bgs_play(nil)
   $game_system.me_play($data_system.gameover_me)
   choices = [Restart::QUICK_RESTART_TEXT, Restart::TO_TITLE_TEXT,
     Restart::EXIT_GAME_TEXT]
   @command_window = Window_Command.new(200, choices)
   @command_window.x = 320 - @command_window.width / 2
   @command_window.y = 240 - @command_window.height / 2
   if $game_system.last_save < 1
     @command_window.disable_item(0)
   end
   Graphics.transition(120)
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @sprite.bitmap.dispose
   @sprite.dispose
   @command_window.dispose
   Graphics.transition(40)
   Graphics.freeze
   if $BTEST
     $scene = nil
   end
 end
 def update
   @command_window.update
   if Input.trigger?(Input::C)
     case @command_window.index
     when 0
       if $game_system.last_save < 1
         $game_system.se_play($data_system.buzzer_se)
         return
       end
       $game_system.se_play($data_system.decision_se)
       do_quick_restart
     when 1
       $game_system.se_play($data_system.decision_se)
       $scene = Scene_Title.new
     when 2
       $game_system.se_play($data_system.decision_se)
       $scene = nil
     end
   end
 end
 def do_quick_restart
   file = File.open("Save#{$game_system.last_save}.rxdata", "rb")
   load = Scene_Load.new
   load.read_save_data(file)
   file.close
   $game_system.bgm_play($game_system.playing_bgm)
   $game_system.bgs_play($game_system.playing_bgs)
   $game_map.update
   $scene = Scene_Map.new
 end
end

karldaylo

May 08, 2011, 05:59:10 am #9 Last Edit: May 08, 2011, 06:05:41 am by karldaylo
thanks,... im updating my script.. thankyou for the help sir gg

EDITED: but there are problem that didnt show up on my previous script... when you die at new game, the game wont quick restart(if you didnt save at the new game,)

BUT, i could fix that befor making the hero gone to the dangerous wild world wothout saving :D

thanks again mr gg
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

G_G

Well in my script version, I simply disabled the Quick Restart command if a New Game hasn't saved yet.

karldaylo

ahahah :^_^': ididnt see that part... re-re edit the script  :P
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

G_G

Nice job, my only problem is this.
@continue_enabled = false
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        @continue_enabled = true
      end
    end
    # If continue is enabled, move cursor to "Load/Restart"
    # If disabled, display "Restart/Continue" text in gray
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(0)
      @command_window.disable_item(1)
    end


Basically now if you start a new game and you have a save file, it'll let you click Quick Restart. Then you'll just get an error.
Under this
@continue_enabled = false
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        @continue_enabled = true
      end
    end

Add
@restart_enabled = true
if $game_system.last_save < 1
  @restart_enabled = false
end


Then change this

    # If continue is enabled, move cursor to "Load/Restart"
    # If disabled, display "Restart/Continue" text in gray
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(0)
      @command_window.disable_item(1)
    end

To this.

    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
if @restart_enabled == false
  @command_window.disable_item(0)
end


Then change this
unless @continue_enabled
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end

to this
unless @restart_enabled
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end


*moves to database*

karldaylo

 :^_^': hahah basics....

i forget to change everything else after adding new statement :P sorry

*updated*
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

G_G

Looks good, I tested it, works what its for. Nice job for your first script.

Blizzard

*slaps G_G for moving topic permaturely*

The Key Term does not exist and because of that, this script does not show up in the database index.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

karldaylo

 :^_^': not his fault, my bad... i thought i dun have to include the other part of that term, ill fix it :)
RESPECT LIST:Blizzard, Game_guy, Foreverzer0, Winkio, Nathmatt

Blizzard

Yeah, but he should have notified you before or after he moved it. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Quote from: Gagmon on May 08, 2011, 06:51:00 pm
My bad >.< Moderators make mistakes too >.<


I swear to god it was there. O__O

ForeverZer0

Congratulations on your first script!
That is a very proud moment for every beginning scripter,

* Levels +
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.