[XP] F12 Pause with image script

Started by Zeriab, May 22, 2009, 05:08:26 am

Previous topic - Next topic

Zeriab

May 22, 2009, 05:08:26 am Last Edit: May 25, 2009, 10:03:40 am by Zeriab
F12 Pause with image script
Authors: Zeriab
Version: 1.1
Type: Pause system, F12 reset prevention
Key Term: Misc System



Introduction

This script changes the functionality of the F12 button so it toggles pause on and off instead of resetting the game.
It displays an image while paused.



Screenshots




Script

Spoiler: ShowHide
#==============================================================================
# ** Pausing with F12
#------------------------------------------------------------------------------
# Zeriab
# Version 1.1
# 2009-05-25 (Year-Month-Day)
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1.0 -------------------------------------------------- (2009-05-22)
#   - First release
#
#   Version 1.1 -------------------------------------------------- (2009-05-25)
#   - The pause image now appears immediately when F12 is pressed.
#   - Transitions are cut short rather than restarted when F12 is pressed.
#------------------------------------------------------------------------------
# * Description :
#
#   This script changes the functionality of pressing F12 during the game
#   from resetting the game to (un)pausing the game. A picture is displayed
#   while the game is paused. (Having a picture is optional)
#------------------------------------------------------------------------------
# * License :
#
#   Copyright (C) 2009  Zeriab
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Lesser Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Lesser Public License for more details.
#
#   For the full license see <http://www.gnu.org/licenses/>
#   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
#   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
#------------------------------------------------------------------------------
# * Compatibility :
#
#   Is most likely not compatible with other F12 prevention scripts.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place this script anywhere above main.
#   The image file 'pause' present in Graphics/Pictures is used.
#   Note: No picture is shown if there is no 'pause' in Graphics/Pictures.
#==============================================================================

#=============================================================================
# ** Reset class (because it won't be defined until F12 is pressed otherwise)
#=============================================================================
class Reset < Exception
 
end
#=============================================================================
# ** Module Graphics
#=============================================================================
module Graphics
  class << self
    #-------------------------------------------------------------------------
    # * Aliases Graphics.update and Graphics.transition
    #-------------------------------------------------------------------------
    unless self.method_defined?(:zeriab_f12_pause_update)
      alias_method(:zeriab_f12_pause_update, :update)
      alias_method(:zeriab_f12_pause_transition, :transition)
    end
    #-------------------------------------------------------------------------
    # Change the update method so F12 toggles pause
    #-------------------------------------------------------------------------
    def update(*args)
      # Try to update normally
      begin
        zeriab_f12_pause_update(*args)
        return
      rescue Reset
        # Do nothing
      end
      # F12 has been pressed
      done = false
      # Store frame count
      frame_count = Graphics.frame_count
      # Show pause image
      @sprite = Sprite.new
      @sprite.z = 9999
      begin
        @sprite.bitmap = RPG::Cache.picture('pause')
      rescue
        @sprite.bitmap = Bitmap.new(32,32)
      end
      # Keep trying to do the update
      while !done
        begin
          zeriab_f12_pause_update(*args)
          done = true
        rescue Reset
          # Do Nothing
        end
      end
      # F12 has been released, update until it is pressed again
      while done
        begin
          zeriab_f12_pause_update(*args)
        rescue Reset
          done = false
        end
      end
      # F12 has been pressed, keep trying to update
      while !done
        begin
          zeriab_f12_pause_update(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
      # F12 has been released, dispose pause image
      @sprite.dispose
      # Set proper frame count
      Graphics.frame_count = frame_count
    end
    #-------------------------------------------------------------------------
    # Changes the transition so it is cut short if F12 is pressed
    #-------------------------------------------------------------------------
    def transition(*args)
      done = false
      # Keep trying to do the transition
      while !done
        begin
          zeriab_f12_pause_transition(*args)
          done = true
        rescue Reset
          # Set transition length to 0 frames.
          args[0] = 0
        end
      end
    end
  end
end



Instructions

Copy+paste the script into the script editor. (Unsure? See this tutorial)
Import picture named pause to Graphics/Pictures. You can use the example picture below for trying it out.




Compatibility

Will most likely not work together with other scripts changing the functionality of the F12 button.


Credits and Thanks

Credits goes to Zeriab for writing the script and making the Paused picture.
Thanks to sixdd for suggesting pause toggling and showing a pause image.
Thanks goes to Kiriashi for inspiration on cutting the transitions short.



Author's Notes

If F12 is pressed during a transition the transition is cut short.
You can use the pause image and modify it any way you like. You don't have to provide credits or anything.
Note that it does NOT work on VX.

License: ShowHide
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser Public License for more details.

For the full license see <http://www.gnu.org/licenses/>;
The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt

Blizzard

May 22, 2009, 05:17:08 am #1 Last Edit: May 22, 2009, 05:18:35 am by Blizzard
So I am not allowed to credit your for using your override of F12? ._.
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.

Zeriab

You are perfectly allowed to credit me ^_^
Just don't put the it on the features list.

On another note I believe this script is unconvertible to VX

legacyblade

Is this compatible with all scripts? It sounds like it should be, but I'm just asking.

Zeriab

Probably not other F12 prevention scripts. Other than that it should compatible. There is a higher chance of it being compatible than with most other scripts.

*hugs*

legacyblade

So theoretically, would it be possible to have a very LONG evented cutscene, and pause mid-scene?

Starrodkirby86

Why don't you try, Legacy? Darkness Rebirth is totally crying out for a test run with this.

(Obligatory question that should be asked)
What if I don't want to use F12 as a Pause? How would I change that key to something else...such as erm, Pause/Break or F4?

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Kagutsuchi

Quintessence is in desperate need of this script imo :P Thought you must also be able to save and turn off the game in the middle of the cutscene and continue from there later :P

legacyblade

Quote from: Kagutsuchi on May 22, 2009, 06:45:00 pm
Quintessence is in desperate need of this script imo :P Thought you must also be able to save and turn off the game in the middle of the cutscene and continue from there later :P


That is the game I was wondering for. I'd love that feature in quintessence.
Quote from: Curly Brace (SRK86) on May 22, 2009, 06:28:48 pm
Why don't you try, Legacy? Darkness Rebirth is totally crying out for a test run with this.

(Obligatory question that should be asked)
What if I don't want to use F12 as a Pause? How would I change that key to something else...such as erm, Pause/Break or F4?


If my RMXP comp was up and running, I would have.

Zeriab

Yes, you can pause in cut scenes regardless of their length. The only place you won't be able to pause is during transitions from map to map. (You can still hold F12 down, but it's only paused while you hold the button down during transitions.
As for saving the game while paused the answer is no. You won't be able to do that with this script although you are free to modify this script for this purpose if you like.

@Curly Brace:
When F12 is pressed Graphics.update throw an exception. I am handling this exception to give the toggle pause feel.
Since only F12 makes Graphics.update throw the Reset exception it cannot be easily changed to use other key-presses.
If you want to use other keys to pause I would suggest messing around with the Input module rather than the Graphics module:

#=============================================================================
# ** Module Input
#=============================================================================
module Input
  class << self
    #-------------------------------------------------------------------------
    # * Aliases Graphics.update and Graphics.transition
    #-------------------------------------------------------------------------
    unless self.method_defined?(:zeriab_pause_update)
      alias_method(:zeriab_pause_update, :update)
    end
    def update(*args)
      zeriab_pause_update(*args)
      return unless trigger?(F6)
      # Store frame count
      frame_count = Graphics.frame_count
      # Show pause image
      @sprite = Sprite.new
      @sprite.z = 9999
      begin
        @sprite.bitmap = RPG::Cache.picture('pause')
      rescue
        @sprite.bitmap = Bitmap.new(32,32)
      end
      # Update once so the trigger doesn't count.
      zeriab_pause_update(*args)
      # Update until trigger
      while !trigger?(F6)
        zeriab_pause_update(*args)
        Graphics.update
      end
      # Dispose pause image
      @sprite.dispose
      # Set proper frame count
      Graphics.frame_count = frame_count
    end
  end
end


This will work for the buttons specified in help file.
QuoteDOWN LEFT RIGHT UP
Numbers corresponding to the directions down, left, right, and up.

A B C X Y Z L R
Numbers corresponding to the various controller buttons.

SHIFT CTRL ALT
Numbers directly corresponding to the keyboard's SHIFT, CTRL, and ALT keys.

F5 F6 F7 F8 F9
Numbers corresponding to the keyboard's function keys. The other function keys are reserved by the system and cannot be obtained.


If you want to user other keys I would suggest finding an input script to your liking and modifying this script to accommodate to the input script you choose.

*hugs*
- Zeriab

Zeriab

I have updated the script so the pause image appear immediately and transitions are cut short when pressing F12.
I have changed the Terms of Use to LGPL.

Here's the pause script if you want other inputs where I added a PAUSE_BUTTON constant so it's easier to see where to change should you want a different button.
#==============================================================================
# ** Pause with image
#------------------------------------------------------------------------------
# Zeriab
# Version 1.0
# 2009-05-23 (Year-Month-Day)
#------------------------------------------------------------------------------
# * Description :
#
#   This script changes the functionality of pressing F12 during the game
#   from resetting the game to (un)pausing the game. A picture is displayed
#   while the game is paused. (Having a picture is optional)
#------------------------------------------------------------------------------
# * License :
#
#   Copyright (C) 2009  Zeriab
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Lesser Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Lesser Public License for more details.
#
#   For the full license see <http://www.gnu.org/licenses/>
#   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
#   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
#------------------------------------------------------------------------------
# * Compatibility :
#
#   Is most likely not compatible with other pause scripts.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place this script anywhere above main.
#   The image file 'pause' present in Graphics/Pictures is used.
#   Note: No picture is shown if there is no 'pause' in Graphics/Pictures.
#==============================================================================

#=============================================================================
# ** Module Input
#=============================================================================
module Input
  class << self
    PAUSE_BUTTON = F6
    #-------------------------------------------------------------------------
    # * Aliases Graphics.update and Graphics.transition
    #-------------------------------------------------------------------------
    unless self.method_defined?(:zeriab_pause_update)
      alias_method(:zeriab_pause_update, :update)
    end
    def update(*args)
      zeriab_pause_update(*args)
      return unless trigger?(PAUSE_BUTTON)
      # Store frame count
      frame_count = Graphics.frame_count
      # Show pause image
      @sprite = Sprite.new
      @sprite.z = 9999
      begin
        @sprite.bitmap = RPG::Cache.picture('pause')
      rescue
        @sprite.bitmap = Bitmap.new(32,32)
      end
      # Update once so the trigger doesn't count.
      zeriab_pause_update(*args)
      # Update until trigger
      while !trigger?(PAUSE_BUTTON)
        zeriab_pause_update(*args)
        Graphics.update
      end
      # Dispose pause image
      @sprite.dispose
      # Set proper frame count
      Graphics.frame_count = frame_count
    end
  end
end


*hugs*
- Zeriab

Calintz

Haha, dude ...
This is the shit, Lol.

I love the more simple scripts that add features that EVERY game should have in them.

Fantasist

You never seem to amaze me Zeriab :up:
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Reno-s--Joker

Is it just me or is this freaking amazing.

I'm a fan. Seriously. Have I mentioned that before?

Zeriab

I am glad you like it and your nice words warm my heart <3

If you use Cowlol's FMOD Ex Audio Module Rewrite then you can use this code to pause both background music and background sounds. Note that it will not pause Music Effects and Sound Effects.
#==============================================================================
# ** Pausing with F12 which uses the FMOD Ex Audio Module to pause the background music and sound
#------------------------------------------------------------------------------
# Zeriab
# Version 1.1b
# 2009-06-01 (Year-Month-Day)
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1.0 -------------------------------------------------- (2009-05-22)
#   - First release
#
#   Version 1.1 -------------------------------------------------- (2009-05-25)
#   - The pause image now appears immediately when F12 is pressed.
#   - Transitions are cut short rather than restarted when F12 is pressed.
#
#   Version 1.1b ------------------------------------------------- (2009-06-01)
#   - The FMOD Audio module is used to pause the background music and sound
#------------------------------------------------------------------------------
# * Description :
#
#   This script changes the functionality of pressing F12 during the game
#   from resetting the game to (un)pausing the game. A picture is displayed
#   while the game is paused. (Having a picture is optional)
#------------------------------------------------------------------------------
# * License :
#
#   Copyright (C) 2009  Zeriab
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Lesser Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Lesser Public License for more details.
#
#   For the full license see <http://www.gnu.org/licenses/>
#   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
#   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
#------------------------------------------------------------------------------
# * Compatibility :
#
#   Is most likely not compatible with other F12 prevention scripts.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place this script anywhere above main.
#   The image file 'pause' present in Graphics/Pictures is used.
#   Note: No picture is shown if there is no 'pause' in Graphics/Pictures.
#==============================================================================

#=============================================================================
# ** Reset class (because it won't be defined until F12 is pressed otherwise)
#=============================================================================
class Reset < Exception

end
#=============================================================================
# ** Module Graphics
#=============================================================================
module Graphics
  class << self
    #-------------------------------------------------------------------------
    # * Aliases Graphics.update and Graphics.transition
    #-------------------------------------------------------------------------
    unless self.method_defined?(:zeriab_f12_pause_update)
      alias_method(:zeriab_f12_pause_update, :update)
      alias_method(:zeriab_f12_pause_transition, :transition)
    end
    #-------------------------------------------------------------------------
    # Change the update method so F12 toggles pause
    #-------------------------------------------------------------------------
    def update(*args)
      # Try to update normally
      begin
        zeriab_f12_pause_update(*args)
        return
      rescue Reset
        # Do nothing
      end
      # F12 has been pressed
      $game_system.bgm_memorize
      $game_system.bgm_stop
      $game_system.bgs_memorize
      $game_system.bgs_stop
      done = false
      # Store frame count
      frame_count = Graphics.frame_count
      # Show pause image
      @sprite = Sprite.new
      @sprite.z = 9999
      begin
        @sprite.bitmap = RPG::Cache.picture('pause')
      rescue
        @sprite.bitmap = Bitmap.new(32,32)
      end
      # Keep trying to do the update
      while !done
        begin
          zeriab_f12_pause_update(*args)
          done = true
        rescue Reset
          # Do Nothing
        end
      end
      # F12 has been released, update until it is pressed again
      while done
        begin
          zeriab_f12_pause_update(*args)
        rescue Reset
          done = false
        end
      end
      # F12 has been pressed, keep trying to update
      while !done
        begin
          zeriab_f12_pause_update(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
      # F12 has been released, dispose pause image
      @sprite.dispose
      $game_system.bgm_restore
      $game_system.bgs_restore
      # Set proper frame count
      Graphics.frame_count = frame_count
    end
    #-------------------------------------------------------------------------
    # Changes the transition so it is cut short if F12 is pressed
    #-------------------------------------------------------------------------
    def transition(*args)
      done = false
      # Keep trying to do the transition
      while !done
        begin
          zeriab_f12_pause_transition(*args)
          done = true
        rescue Reset
          # Set transition length to 0 frames.
          args[0] = 0
        end
      end
    end
  end
end


*hugs*
- Zeriab

Calintz


Hellfire Dragon

Quote from: Fantasist on May 28, 2009, 11:30:04 am
You never seem to amaze me Zeriab :up:

Really? Spelling mistake?

Awesome script Zeriab :)

Calintz

I really like this one Zeriab ...

BTW:
Do you just create scripts for us, or do you have a project??

Zeriab

I prefer the version which pauses the Audio despite it requiring a third party script ^_^

I script a bit for a project, but mainly I just make modular scripts :3

Calintz

Good deal, well we are all glad to have your assistance.