[XP] F12 Pause with image script

F12 Pause with image script Version: 1.1
By: Zeriab

Description

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

Image

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.

Image

Script

  1. #==============================================================================
  2. # ** Pausing with F12
  3. #------------------------------------------------------------------------------
  4. # Zeriab
  5. # Version 1.1
  6. # 2009-05-25 (Year-Month-Day)
  7. #------------------------------------------------------------------------------
  8. # * Version History :
  9. #
  10. #    Version 1.0 -------------------------------------------------- (2009-05-22)
  11. #    - First release
  12. #
  13. #    Version 1.1 -------------------------------------------------- (2009-05-25)
  14. #    - The pause image now appears immediately when F12 is pressed.
  15. #    - Transitions are cut short rather than restarted when F12 is pressed.
  16. #------------------------------------------------------------------------------
  17. # * Description :
  18. #
  19. #    This script changes the functionality of pressing F12 during the game
  20. #    from resetting the game to (un)pausing the game. A picture is displayed
  21. #    while the game is paused. (Having a picture is optional)
  22. #------------------------------------------------------------------------------
  23. # * License :
  24. #
  25. #    Copyright (C) 2009   Zeriab
  26. #
  27. #    This program is free software: you can redistribute it and/or modify
  28. #    it under the terms of the GNU Lesser Public License as published by
  29. #    the Free Software Foundation, either version 3 of the License, or
  30. #    (at your option) any later version.
  31. #
  32. #    This program is distributed in the hope that it will be useful,
  33. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
  35. #    GNU Lesser Public License for more details.
  36. #
  37. #    For the full license see <http://www.gnu.org/licenses/>
  38. #    The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
  39. #    The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
  40. #------------------------------------------------------------------------------
  41. # * Compatibility :
  42. #
  43. #    Is most likely not compatible with other F12 prevention scripts.
  44. #------------------------------------------------------------------------------
  45. # * Instructions :
  46. #
  47. #    Place this script anywhere above main.
  48. #    The image file 'pause' present in Graphics/Pictures is used.
  49. #    Note: No picture is shown if there is no 'pause' in Graphics/Pictures.
  50. #==============================================================================
  51.  
  52. #=============================================================================
  53. # ** Reset class (because it won't be defined until F12 is pressed otherwise)
  54. #=============================================================================
  55. class Reset < Exception
  56.  
  57. end
  58. #=============================================================================
  59. # ** Module Graphics
  60. #=============================================================================
  61. module Graphics
  62.   class << self
  63.      #-------------------------------------------------------------------------
  64.      # * Aliases Graphics.update and Graphics.transition
  65.      #-------------------------------------------------------------------------
  66.      unless self.method_defined?(:zeriab_f12_pause_update)
  67.         alias_method(:zeriab_f12_pause_update, :update)
  68.         alias_method(:zeriab_f12_pause_transition, :transition)
  69.      end
  70.      #-------------------------------------------------------------------------
  71.      # Change the update method so F12 toggles pause
  72.      #-------------------------------------------------------------------------
  73.      def update(*args)
  74.         # Try to update normally
  75.         begin
  76.            zeriab_f12_pause_update(*args)
  77.            return
  78.         rescue Reset
  79.            # Do nothing
  80.         end
  81.         # F12 has been pressed
  82.         done = false
  83.         # Store frame count
  84.         frame_count = Graphics.frame_count
  85.         # Show pause image
  86.         @sprite = Sprite.new
  87.         @sprite.z = 9999
  88.         begin
  89.            @sprite.bitmap = RPG::Cache.picture('pause')
  90.         rescue
  91.            @sprite.bitmap = Bitmap.new(32,32)
  92.         end
  93.         # Keep trying to do the update
  94.         while !done
  95.            begin
  96.               zeriab_f12_pause_update(*args)
  97.               done = true
  98.            rescue Reset
  99.               # Do Nothing
  100.            end
  101.         end
  102.         # F12 has been released, update until it is pressed again
  103.         while done
  104.            begin
  105.               zeriab_f12_pause_update(*args)
  106.            rescue Reset
  107.               done = false
  108.            end
  109.         end
  110.         # F12 has been pressed, keep trying to update
  111.         while !done
  112.            begin
  113.               zeriab_f12_pause_update(*args)
  114.               done = true
  115.            rescue Reset
  116.               # Do nothing
  117.            end
  118.         end
  119.         # F12 has been released, dispose pause image
  120.         @sprite.dispose
  121.         # Set proper frame count
  122.         Graphics.frame_count = frame_count
  123.      end
  124.      #-------------------------------------------------------------------------
  125.      # Changes the transition so it is cut short if F12 is pressed
  126.      #-------------------------------------------------------------------------
  127.      def transition(*args)
  128.         done = false
  129.         # Keep trying to do the transition
  130.         while !done
  131.            begin
  132.               zeriab_f12_pause_transition(*args)
  133.               done = true
  134.            rescue Reset
  135.               # Set transition length to 0 frames.
  136.               args[0] = 0
  137.            end
  138.         end
  139.      end
  140.   end
  141. end
Expand to see the code.


Credit

Credits goes to Zeriab for writing the script and making the Paused picture.

Known Compatibility Issues

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

Author's Notes
Thanks goes to sixdd for suggesting pause toggling and showing a pause image.
Thanks goes to Kiriashi for inspiration on cutting the transitions short.
You can use the pause image and modify it any way you like. You don't have to provide credits or anything.
If F12 is pressed during a transition the transition is cut short.
Note that it does NOT work on VX.

Terms and Conditions
LGPL Spoiler
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
Wow Zeriab, this'll be very useful to me. Thank you.
I am glad you like it ^_^
Remember that you can always ask if you have any problems or want to know something about the script.

*hugs*
In case you want to have a pause button which is not F12 I have made this script:
  1. #=============================================================================
  2. # ** Module Input
  3. #=============================================================================
  4. module Input
  5.   class << self
  6.     #-------------------------------------------------------------------------
  7.     # * Aliases Graphics.update and Graphics.transition
  8.     #-------------------------------------------------------------------------
  9.     unless self.method_defined?(:zeriab_pause_update)
  10.       alias_method(:zeriab_pause_update, :update)
  11.     end
  12.     def update(*args)
  13.       zeriab_pause_update(*args)
  14.       return unless trigger?(F6)
  15.       # Store frame count
  16.       frame_count = Graphics.frame_count
  17.       # Show pause image
  18.       @sprite = Sprite.new
  19.       @sprite.z = 9999
  20.       begin
  21.         @sprite.bitmap = RPG::Cache.picture('pause')
  22.       rescue
  23.         @sprite.bitmap = Bitmap.new(32,32)
  24.       end
  25.       # Update once so the trigger doesn't count.
  26.       zeriab_pause_update(*args)
  27.       # Update until trigger
  28.       while !trigger?(F6)
  29.         zeriab_pause_update(*args)
  30.         Graphics.update
  31.       end
  32.       # Dispose pause image
  33.       @sprite.dispose
  34.       # Set proper frame count
  35.       Graphics.frame_count = frame_count
  36.     end
  37.   end
  38. end
Expand to see the code.


This will work for the buttons specified in help file.
Quote:
DOWN 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 use 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*
I have updated the script to a new version:
  • I change the terms of use to LGPL
  • The pause image appears immediately when pressing F12
  • Transitions are cut short when pressing F12

As for the script which uses other buttons here is a version with script header:
  1. #==============================================================================
  2. # ** Pause with image
  3. #------------------------------------------------------------------------------
  4. # Zeriab
  5. # Version 1.0
  6. # 2009-05-23 (Year-Month-Day)
  7. #------------------------------------------------------------------------------
  8. # * Description :
  9. #
  10. #   This script changes the functionality of pressing F12 during the game
  11. #   from resetting the game to (un)pausing the game. A picture is displayed
  12. #   while the game is paused. (Having a picture is optional)
  13. #------------------------------------------------------------------------------
  14. # * License :
  15. #
  16. #   Copyright (C) 2009  Zeriab
  17. #
  18. #   This program is free software: you can redistribute it and/or modify
  19. #   it under the terms of the GNU Lesser Public License as published by
  20. #   the Free Software Foundation, either version 3 of the License, or
  21. #   (at your option) any later version.
  22. #
  23. #   This program is distributed in the hope that it will be useful,
  24. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. #   GNU Lesser Public License for more details.
  27. #
  28. #   For the full license see <http://www.gnu.org/licenses/>
  29. #   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
  30. #   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
  31. #------------------------------------------------------------------------------
  32. # * Compatibility :
  33. #
  34. #   Is most likely not compatible with other pause scripts.
  35. #------------------------------------------------------------------------------
  36. # * Instructions :
  37. #
  38. #   Place this script anywhere above main.
  39. #   The image file 'pause' present in Graphics/Pictures is used.
  40. #   Note: No picture is shown if there is no 'pause' in Graphics/Pictures.
  41. #==============================================================================
  42.  
  43. #=============================================================================
  44. # ** Module Input
  45. #=============================================================================
  46. module Input
  47.   class << self
  48.     PAUSE_BUTTON = F6
  49.     #-------------------------------------------------------------------------
  50.     # * Aliases Graphics.update and Graphics.transition
  51.     #-------------------------------------------------------------------------
  52.     unless self.method_defined?(:zeriab_pause_update)
  53.       alias_method(:zeriab_pause_update, :update)
  54.     end
  55.     def update(*args)
  56.       zeriab_pause_update(*args)
  57.       return unless trigger?(PAUSE_BUTTON)
  58.       # Store frame count
  59.       frame_count = Graphics.frame_count
  60.       # Show pause image
  61.       @sprite = Sprite.new
  62.       @sprite.z = 9999
  63.       begin
  64.         @sprite.bitmap = RPG::Cache.picture('pause')
  65.       rescue
  66.         @sprite.bitmap = Bitmap.new(32,32)
  67.       end
  68.       # Update once so the trigger doesn't count.
  69.       zeriab_pause_update(*args)
  70.       # Update until trigger
  71.       while !trigger?(PAUSE_BUTTON)
  72.         zeriab_pause_update(*args)
  73.         Graphics.update
  74.       end
  75.       # Dispose pause image
  76.       @sprite.dispose
  77.       # Set proper frame count
  78.       Graphics.frame_count = frame_count
  79.     end
  80.   end
  81. end
Expand to see the code.


*hugs*
As always, you've found the most interesting ways to interfere with the ways that Enterbrain put together RMXP. Great work here.
Why thank you rey ^^
In terms of pause script functionality it really is bare bone, but I welcome anyone who would want to build on to this script.

*hugs*
Great just wat i was looking for.. Thanks it works perfect :thumb:
I guess if I think about it, an interesting addition would be to pause the audio at the same time.
:thumb: Nice!
Every game should be able to be paused for those easily distracted players. :tongue:
Pausing the audio is definitely an interesting idea.
I do not believe that pausing the audio is supported by default.

@LegacyX & SP27: Thanks for the nice comments :3

*hugs*
Oh yeah, pausing the audio would help alot, that way cutscenes arn't affected, or anything.
W31WGamer wrote:
Oh yeah, pausing the audio would help alot, that way cutscenes arn't affected, or anything.

Now that you mention it, yeah you're right...

I've also got to give a little feed back, if I may.
You see you're able to pause on the title screen and save/load screens... To me that seems a little weird. In the menu I can see it through the fingers but on the title screen is a typical... "HUH!?" thing you know? :tongue:

Nice script anyways though, please don't get me wrong. :grin:
In the older gaming systems, couldn't you pause anytime? If you could stop the audio that way, it would be perfect.
W31WGamer wrote:
In the older gaming systems, couldn't you pause anytime? If you could stop the audio that way, it would be perfect.


Far as I remember you could not pause on the title screen in FF9. :o:

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