Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Zeriab on April 20, 2008, 05:27:05 pm

Title: Snippet that prevents F12 from restarting the game
Post by: Zeriab on April 20, 2008, 05:27:05 pm
Here is a rather useful snippet I just cooked up.
This prevents the F12 key from resetting the game.
For some reason pressing the F12 key now seems to speed up the game in many cases and in other pauses the game.

#=============================================================================
# ** 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_removal_update)
      alias_method(:zeriab_f12_removal_update, :update)
      alias_method(:zeriab_f12_removal_transition, :transition)
    end
    def update(*args)
      begin
        zeriab_f12_removal_update(*args)
      rescue Reset
        # Do nothing
      end
    end
    def transition(*args)
      done = false
      # Keep trying to do the transition
      while !done
        begin
          zeriab_f12_removal_transition(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
    end
  end
end


For an extreme example of the speed up issue I mentioned here is a picture:
(http://img89.imageshack.us/img89/438/speedboostlx8.png)

I don't know whether it actually went with 410 FPS or if something broke.
Title: Re: Snippet that prevents F12 from restarting the game
Post by: shdwlink1993 on April 20, 2008, 06:32:06 pm
Hey! This is pretty neat! Here's what happens on my game (in case you wanted to know what happens on different projects):

Battle was speed up through the roof! :D
Message text would not begin appearing until you hit the OK button, when it came all-at-once.
As long as the button was held down, no scene changes or teleports could occur (try tapping F12 with this while it tries changing maps. It looks really funny.)
In the map scene (sometimes) animations would appear, but they wouldn't actually animate. It would just show the first frame and stop. Curious.

But yea. Pretty neat! ;D Now all we need is a way to stop F1 and F2...
Title: Re: Snippet that prevents F12 from restarting the game
Post by: Zeriab on April 21, 2008, 03:32:11 am
I'm glad you like it ^_^
The effects of pressing F12 can indeed be curious at times XD

Here is another version where the game should simply pause while F12 is pressed. (hopefully)
#=============================================================================
# ** 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_removal_update)
      alias_method(:zeriab_f12_removal_update, :update)
      alias_method(:zeriab_f12_removal_transition, :transition)
    end
    def update(*args)
      done = false
      # Keep trying to do the update
      while !done
        begin
          zeriab_f12_removal_update(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
    end
    def transition(*args)
      done = false
      # Keep trying to do the transition
      while !done
        begin
          zeriab_f12_removal_transition(*args)
          done = true
        rescue Reset
          # Do nothing
        end
      end
    end
  end
end


Why do you need a way to stop F2?
It like F9 only does something during test play. (When you play the game from the editor)

As for F1 you could simulate an additional F1 press when it is discovered. The dialog would probably blink up.
Why would you want to remove that dialog though? It's options the player can change, like if they have a slow computer they can deselect smooth mode
Title: Re: Snippet that prevents F12 from restarting the game
Post by: Fantasist on April 21, 2008, 03:55:02 am
In the map, it only pauses the game, nice one Zeriab :)

Though, I'd like to see a complete disable. I wouldn't disable it if I were to make a game, I'd use your other fix. I prefer to give the player the option to do things like exit (Alt+F4) and Restart at his own will. I WOULD want to disable Alt+Enter.
Title: Re: Snippet that prevents F12 from restarting the game
Post by: Blizzard on April 21, 2008, 05:51:34 am
Hm, if it speeds up the game to really 410 fps... Maybe I will try it anyway. :3
Title: Re: Snippet that prevents F12 from restarting the game
Post by: MayorAnime on August 30, 2009, 06:21:26 am
I just stumbled across this and tried out the later version, the one that pauses the game when you hold down F12.

Greatest - Screenshot - Setup - Ever.

Thanks, Zeriab!
Title: Re: Snippet that prevents F12 from restarting the game
Post by: Zeriab on September 01, 2009, 03:50:12 pm
I am glad you like it :3
Just ask if you ever have any problems with it.