• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Advanced Quicksave for Essentials (Savestate Try)

95
Posts
9
Years
  • Current Version: 0.1

    5fei9mpr.png
    zpf4smzp.png

    This is my try to "recreate" savestates like the behave on emulators (such as Dolphin, DeSmuME ... )

    What does the script do?
    You can save quickly without accessing the annoying save menu. In addition to that you can have up to 10 savefiles now (one regular+9 extra savefiles).

    How can I save/load a stage?
    save: SHIFT + 1-9
    load: 1-9


    How to get this script:

    2.create a new script section above Main and paste this code in it:

    Make sure to go to Thread Tools-->Show Printable version
    Code:
    #===============================================================================
    # * Emulator Savestate Script for Pokémon Essentials v0.1
    #
    # - Save a Savestate with the Button's SHIFT + 1-9.
    # - Load a Savestate with the Button's 1-9.
    #
    #  Have any bugs/questions/suggestions?
    #  - Contact me! ( Skype: imatrix.wt ;Deviantart: shiney570 ;PokeCom: shiney570)
    # 
    # Whenever you use don't forget to give credits. Also credit FL because he 
    # helped me a lot with things I didn't know!
    #===============================================================================
    SAVESTATES                              = true
    ALLOW_SAVESTATES_ONLY_IN_DEBUG_MODE     = true
    
    #===============================================================================
    # * Updating the Inputs.
    #===============================================================================
    class Scene_Map
      def main
        createSpritesets
        Graphics.transition
        loop do
          Graphics.update
          Input.update
          update
          if SAVESTATES
            update_savestates
          end
          if ($saveStateFrameCount && SAVESTATES )
            $saveStateFrameCount+=1
            if $saveStateFrameCount>=80
              $saveStateBitmap.bitmap.clear
              $saveStateFrameCount=nil
            end
          end
          if $scene != self
            break
          end
        end
        Graphics.freeze
        disposeSpritesets
        if $game_temp.to_title
          Graphics.transition
          Graphics.freeze
        end
      end
    end
    #===============================================================================
    # * Method for Updating Savestates
    #===============================================================================
    def update_savestates
        if $DEBUG || (!$DEBUG && (!ALLOW_SAVESTATES_ONLY_IN_DEBUG_MODE))
          sub=30
          for i in 1..9
            if Input.press?(sub+i)
              if !$saveStateBitmap
                $saveStateBitmap=BitmapSprite.new(DEFAULTSCREENWIDTH,100)
                $saveStateBitmap.z=99999999
                $saveStateBitmap.bitmap.font.name="Arial"
                $saveStateBitmap.bitmap.font.size=25
              end
              if Input.press?(Input::SHIFT)
                pbSaveStage("#{i}")
              else
                pbLoadStage("#{i}")
              end
            end
          end
        end
      end
    #==================================================================================
    # * Save Stages.
    #=================================================================================
    def pbSaveStage(slot)
      # Creates Savestate folder if it doesn't exists yet.
      if !(safeExists?("Data/Savestates"))
        Dir.mkdir("Data/Savestates")
      end
      @savefile="Data/Savestates/savestate#{slot}.rxdata"
      # Saving Stage.
      File.open((@savefile),"wb") {|f|
      Marshal.dump($Trainer,f)
      Marshal.dump(Graphics.frame_count,f)
      if $data_system.respond_to?("magic_number")
        $game_system.magic_number = $data_system.magic_number
      else
        $game_system.magic_number = $data_system.version_id
      end
      Marshal.dump($game_system,f)
      Marshal.dump($PokemonSystem,f)
      Marshal.dump($game_map.map_id,f)
      Marshal.dump($game_switches,f)
      Marshal.dump($game_variables,f)
      Marshal.dump($game_self_switches,f)
      Marshal.dump($game_screen,f)
      Marshal.dump($MapFactory,f)
      Marshal.dump($game_player,f)
      Marshal.dump($PokemonGlobal,f)
      Marshal.dump($PokemonMap,f)
      Marshal.dump($PokemonBag,f)
      Marshal.dump($PokemonStorage,f)
      }
      $saveStage=slot
      Graphics.frame_reset
      printSavestateMessage("Saved State to Slot #{slot}.")
    end
    #==================================================================================
    # * Load Stages.
    #=================================================================================
    def pbLoadStage(slot)
      @savefile="Data/Savestates/savestate#{slot}.rxdata"
      if !(safeExists?(@savefile))
        printSavestateMessage("Savestate from Slot #{slot} was not found.")
        return
      end
      File.open(@savefile){|f|
      Marshal.load(f) # Trainer already loaded
      Graphics.frame_count = Marshal.load(f)
      $game_system        = Marshal.load(f)
      Marshal.load(f) # PokemonSystem already loaded
      Marshal.load(f) # Current map id no longer needed
      $game_switches      = Marshal.load(f)
      $game_variables      = Marshal.load(f)
      $game_self_switches  = Marshal.load(f)
      $game_screen        = Marshal.load(f)
      $MapFactory          = Marshal.load(f)
      $game_map            = $MapFactory.map
      $game_player        = Marshal.load(f)
      $PokemonGlobal      = Marshal.load(f)
      metadata            = Marshal.load(f)
      $ItemData            = readItemList("Data/items.dat")
      $PokemonBag          = Marshal.load(f)
      $PokemonStorage      = Marshal.load(f)
      magicNumberMatches=false
      $PokemonMap=metadata
      if $data_system.respond_to?("magic_number")
        magicNumberMatches=($game_system.magic_number==$data_system.magic_number)
      else
        magicNumberMatches=($game_system.magic_number==$data_system.version_id)
      end
      if !magicNumberMatches || $PokemonGlobal.safesave
        if pbMapInterpreterRunning?
          pbMapInterpreter.setup(nil,0)
        end
        begin
          $MapFactory.setup($game_map.map_id) # calls setMapChanged
        rescue Errno::ENOENT
        if $DEBUG
          printSavestateMessage("Map #{$game_map.map_id} was not found.")
          map=pbWarpToMap()
          if map
            $MapFactory.setup(map[0])
            $game_player.moveto(map[1],map[2])
          else
            $game_map=nil
            $scene=nil
            return
          end
        else
          printSavestateMessage("The map was not found. The game cannot continue.")
          end
        end
        $game_player.center($game_player.x, $game_player.y)
        else
          $MapFactory.setMapChanged($game_map.map_id)
        end
      }
      if !$game_map.events # Map wasn't set up
        printSavestateMessage("The map is corrupt. The game cannot continue.")
        return
      end
      $loadStage=slot
      $PokemonEncounters=PokemonEncounters.new
      $PokemonEncounters.setup($game_map.map_id)
      pbAutoplayOnSave
      $game_map.update 
      $PokemonMap.updateMap  
      $scene = Scene_Map.new 
      printSavestateMessage("Loaded State from Slot #{slot}.")
    end
    #===============================================================================
    # * Printing Message.
    #===============================================================================
    def printSavestateMessage(message)
      $saveStateBitmap.bitmap.clear
      textos=[]
      textos.push([message,5,5,false,Color.new(254,254,76),Color.new(35,35,35)])
      pbDrawTextPositions($saveStateBitmap.bitmap,textos)
      $saveStateFrameCount=0
    end
    
    #===============================================================================
    # * defineing inputs 1-9.
    #===============================================================================
    module Input    
      NUMBER0 = 30 
      NUMBER1 = 31
      NUMBER2 = 32
      NUMBER3 = 33
      NUMBER4 = 34
      NUMBER5 = 35
      NUMBER6 = 36
      NUMBER7 = 37
      NUMBER8 = 38
      NUMBER9 = 39
      class << self
        alias old_self_button_to_key_shiney_123 :buttonToKey
      end
      
      def self.buttonToKey(button)
        case button
        when Input::NUMBER0
          return [0x30] # 0
        when Input::NUMBER1
          return [0x31] # 1
        when Input::NUMBER2
          return [0x32] # 2
        when Input::NUMBER3
          return [0x33] # 3
        when Input::NUMBER4
          return [0x34] # 4
        when Input::NUMBER5
          return [0x35] # 5
        when Input::NUMBER6
          return [0x36] # 6
        when Input::NUMBER7
          return [0x37] # 7
        when Input::NUMBER8
          return [0x38] # 8
        when Input::NUMBER9
          return [0x39] # 9
        end 
        self.old_self_button_to_key_shiney_123(button)
      end
    end

    Where will the savefiles be saved?
    You can find them in the Data/Savestates folder. Your "normal" Savefile will still be located as the same Spot as before.

    Will you update the script?
    I give my best to try to add spots where you can save too.

    Where can I save in this version?
    - On the Map

    Are there any settings in the Script?
    SAVESTATES: When true you are able to savestate when false this script is disabled.
    [I]ALLOW_SAVESTATES_ONLY_IN_DEBUG_MODE: When true you are only able to savestate in the Debug mode. When false you are able to savestate anywhere.[/I]

    Where can I contact you?
    Skype: imatrix.wt ;Deviantart: shiney570 ;PokeCom: shiney570


    Thanks FL for helping me! Give credits to him too when using!
     
    Last edited:

    Wootius

    Glah
    300
    Posts
    11
    Years
    • Seen May 31, 2022
    Oh crap. With my turbo script RMXP will be just like an emulator now!
     

    Wootius

    Glah
    300
    Posts
    11
    Years
    • Seen May 31, 2022
    Bug. Loading a save with dependent event causes the dependent event to wig out and desync from you. :(
     
    1
    Posts
    8
    Years
    • Seen Feb 19, 2020
    How can I change which button I've to press and how many save-slots I've got?
     

    Soccersam

    Hilbert is Badass
    179
    Posts
    7
    Years
    • Seen Feb 26, 2024
    My dependencies get messed up when I load my states! Is it not fixed yet?
     

    IndieLynne

    IndieLynne
    2
    Posts
    4
    Years
  • My dependents spasm when I load my states! My following pokemon shouldn't go flying off the screen when my player takes a step in any direction! Please help!
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Maybe you need to add the dependent events to the saving and loading functions? Hopefully that's as simple as adding two lines of code, one to the saving, one to the loading, once you work out what the dependent event structure is called (probably starts with a $)
     
    Back
    Top