Advertisement
Zeriab

[RGSS] F12 Pause Script

Mar 28th, 2015
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.63 KB | None | 0 0
  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 software is provided 'as-is', without any express or implied warranty.
  28. #    In no event will the authors be held liable for any damages arising from
  29. #    the use of this software.
  30. #    Permission is granted to anyone to use this software for any purpose,
  31. #    including commercial applications, and to alter it and redistribute it
  32. #    freely, subject to the following restrictions:
  33. #        1. The origin of this software must not be misrepresented; you must not
  34. #           claim that you wrote the original software. If you use this software
  35. #           in a product, an acknowledgment in the product documentation would
  36. #           be appreciated but is not required.
  37. #        2. Altered source versions must be plainly marked as such, and must not
  38. #           be misrepresented as being the original software.
  39. #        3. This notice may not be removed or altered from any source distribution.
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement