Lockpicking Minigame

The old post with this script vanished into the ether sometime in the last two years, so here it is again.

Lockpicking Minigame Version: 1.0.0, for RMXP
By: Eilei

Introduction

The lockpicking minigame is a little script I slapped together a long time ago to teach myself Ruby. The game has a number of tumblers you need to get into place, and on the harder locks moving one tumbler can move another too. Successful completion of the minigame sets a switch of your choice to ON, so it's pretty easy to interact with from events.

Features

  • Varying difficulties for different levels of play
  • Completely random boards, so no two games are ever the same*
  • Can interact with either global switches or event self-switches

Screenshots

Minigame on "Average" difficulty:
Image

Demo

http://www.mediafire.com/download.php?wymtzng1jmz

Script

script Spoiler
  1. #==============================================================================
  2. # ** Lockpick Minigame
  3. #------------------------------------------------------------------------------
  4. # Your Name   : Eilei
  5. # Version     : 1.0.0
  6. # Date        : September 9, 2007
  7. # SDK Version : Version 2.3, Part I
  8. #==============================================================================
  9.  
  10. =begin                    Installation Instructions
  11.  
  12. 0.) Get SDK if you don't have it; Part I is required for this script.
  13.  
  14. 1.) Copy this script and paste it into your script list, just above Main.
  15.  
  16.                           Editing Instructions
  17.  
  18. 1.) Change the main background by swapping out
  19.       Graphics/Pictures/lockpick_background.png
  20.     for whatever you want.  Change the audio file at
  21.       Audio/BGM/lockpick_music.mp3
  22.     Change the color of the tumblers by messing with
  23.       Graphics/Pictures/lockpick_pins.png,
  24.     but I don't recommend changing the sizes of the pins.  Finally, change the
  25.     minigame lock background colors by editing both
  26.       Graphics/Pictures/lockpick_cylinder.png
  27.     and
  28.       Graphics/Pictures/lockpick_pin_background.png
  29.  
  30. 2.) This script isn't otherwise very customizeable at the moment.  Feel free
  31.     to tinker with the number of tumblers per difficulty and such.
  32.    
  33.                           Usage
  34.                          
  35. 1.) See the two chests for the two ways to use this script; one method puts
  36.     the lockpicking result in a specified event's self switches, the other
  37.     puts it in a specified global switch.
  38.  
  39.                           Legal Notices
  40.                          
  41.     This script is Copyright © 2007 C. Schrupp.
  42.  
  43.     This script is free software; you can redistribute it and/or modify
  44.     it under the terms of the GNU General Public License as published by
  45.     the Free Software Foundation; either version 3 of the License, or
  46.     (at your option) any later version.
  47.  
  48.     This script is distributed in the hope that it will be useful,
  49.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  50.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  51.     GNU General Public License for more details.
  52.  
  53.     A copy of the GNU General Public License is in gpl.txt in the main
  54.     directory.  If not, see <http://www.gnu.org/licenses/>.
  55. =end
  56.  
  57. #--------------------------------------------------------------------------
  58. # * Begin SDK Log
  59. #--------------------------------------------------------------------------
  60. SDK.log( 'Lockpicking Minigame', 'Eilei', '1.0', '2007-09-08')
  61.  
  62. #--------------------------------------------------------------------------
  63. # * Begin Requirements Check
  64. #--------------------------------------------------------------------------
  65. SDK.check_requirements( 2.3, [1] )
  66.  
  67. #--------------------------------------------------------------------------
  68. # * Begin SDK Enable Test
  69. #--------------------------------------------------------------------------
  70. if SDK.enabled?( 'Lockpicking Minigame' )
  71.  
  72. #----------------------------------------------------------------------------
  73. # Begin Game_Temp Edit
  74. #----------------------------------------------------------------------------
  75. class Game_Temp
  76.   attr_accessor :lock_difficulty   # difficulty for the next lock to be picked
  77. end
  78. #----------------------------------------------------------------------------
  79. # End Game_Temp Edit
  80. #----------------------------------------------------------------------------
  81.  
  82. #==============================================================================
  83. # ** Scene_LockpickMinigame
  84. #------------------------------------------------------------------------------
  85. #  Scene_LockpickMinigame is the scene to call when you want to run the
  86. #  lockpicking minigame
  87. #
  88. #  NOTE: Scene_LockpickMinigame.set_result MUST be called before $scene is
  89. #  set, or the minigame will not work.
  90. #==============================================================================
  91. class Scene_LockpickMinigame < SDK::Scene_Base
  92.  
  93.   #---------------------------------------------------------------------------+
  94.   # Scene Constants                                                           |
  95.   #---------------------------------------------------------------------------+
  96.   LOCK_VERY_EASY  = 0
  97.   LOCK_EASY       = 1
  98.   LOCK_AVERAGE    = 2
  99.   LOCK_DIFFICULT  = 3
  100.   LOCK_INSANE     = 4
  101.  
  102.   # The number of tumblers for each difficulty should be prime to maximize the
  103.   # probability that the puzzle will be solveable.
  104.   LOCK_TUMBLERS = {
  105.     LOCK_VERY_EASY => 2,
  106.     LOCK_EASY      => 3,
  107.     LOCK_AVERAGE   => 5,
  108.     LOCK_DIFFICULT => 7,
  109.     LOCK_INSANE    => 11
  110.   }
  111.  
  112.   LOCK_AUDIO_UNLOCK = RPG::AudioFile.new( 'lock_open' )
  113.  
  114.   # Internal constants
  115.   CYLINDER_WIDTH  = 288
  116.  
  117.   #--------------------------------------------------------------------------
  118.   # * Main Processing : Variable Initialization
  119.   #--------------------------------------------------------------------------
  120.   def main_variable
  121.  
  122.     # Check that the default value is ok
  123.     if not LOCK_TUMBLERS.keys.include?( $game_temp.lock_difficulty )
  124.       $game_temp.lock_difficulty = LOCK_VERY_EASY
  125.     end
  126.  
  127.     # Initialize the tumbler pins
  128.     @pins = Array.new( LOCK_TUMBLERS[ $game_temp.lock_difficulty ] )
  129.    
  130.     # Initialize the current lock modifier
  131.     # (guarantees @lock_number will be prime)
  132.     n = rand( 40 ) + 1
  133.     @lock_number = n**2 + n + 41
  134.  
  135.   end
  136.  
  137.   #--------------------------------------------------------------------------
  138.   # * Main Processing : Sprite Initialization
  139.   #--------------------------------------------------------------------------
  140.   def main_sprite
  141.     # Initialize viewports
  142.     @viewport_background = Viewport.new( 0, 0, 640, 480)
  143.     @viewport_background.z = -500
  144.     @viewport_lock = Viewport.new( ( 640 - CYLINDER_WIDTH ) / 2, 90,
  145.       CYLINDER_WIDTH, 300 )
  146.     @viewport_lock.z = -200
  147.    
  148.     # display background image
  149.     @background_sprite = Sprite.new( @viewport_background )
  150.     @background_sprite.bitmap = RPG::Cache.picture( 'lockpick_background' )
  151.    
  152.     # display lock cylinder
  153.     @cylinder_sprite = Sprite.new( @viewport_lock )
  154.     @cylinder_sprite.bitmap = RPG::Cache.picture( 'lockpick_cylinder' )
  155.    
  156.     # display tumbler springs and pins
  157.     for i in [email hidden]
  158.       @pins[ i ] = Tumbler.new( @viewport_lock )
  159.       @pins[ i ].x = CYLINDER_WIDTH * ( i + 1 ) / ( @pins.size + 1 )
  160.       @pins[ i ].y = 0
  161.     end
  162.    
  163.     # display lockpick
  164.     @lockpick_sprite = Lockpick.new
  165.     @lockpick_sprite.tumblers = @pins.size
  166.   end
  167.  
  168.   #--------------------------------------------------------------------------
  169.   # * Main Processing : Window Initialization
  170.   #--------------------------------------------------------------------------
  171.   def main_window
  172.     @help_window = Window_Help.new
  173.     @help_window.set_text(
  174.       'Line up the tumbler pins with the cylinder to pick the lock.' )
  175.     @help_window.back_opacity = 160
  176.   end
  177.  
  178.   #--------------------------------------------------------------------------
  179.   # * Main Processing : Audio Initialization
  180.   #--------------------------------------------------------------------------
  181.   def main_audio
  182.     $game_system.bgm_play( RPG::AudioFile.new( 'lockpick_music', 80 ))
  183.   end
  184.  
  185.   #--------------------------------------------------------------------------
  186.   # * Frame Update
  187.   #--------------------------------------------------------------------------
  188.   def update
  189.     # game cancelled
  190.     if Input.trigger?( Input::B )
  191.       $scene = Scene_Map.new
  192.     end
  193.    
  194.     # Don't allow other input if animating
  195.     if @lockpick_sprite.move?
  196.       return
  197.     end
  198.     for i in [email hidden]
  199.       if @pins[ i ].move?
  200.         return
  201.       end
  202.     end
  203.    
  204.     # move the lockpick left or right
  205.     if Input.trigger?( Input::RIGHT )
  206.       @lockpick_sprite.move_right
  207.       if not @lockpick_sprite.move?
  208.         $game_system.se_play( $data_system.buzzer_se )
  209.       end
  210.     end
  211.     if Input.trigger?( Input::LEFT )
  212.       @lockpick_sprite.move_left
  213.       if not @lockpick_sprite.move?
  214.         $game_system.se_play( $data_system.buzzer_se )
  215.       end
  216.     end
  217.    
  218.     # knock a tumbler up - cascades
  219.     if Input.trigger?( Input::UP )
  220.       @pins[ @lockpick_sprite.position ].raise
  221.       if @pins[ @lockpick_sprite.position ].move?
  222.         $game_system.se_play( Tumbler::TUMBLER_AUDIO_UP )
  223.         @lockpick_sprite.tap_up
  224.         if @lockpick_sprite.position > 0 # first pin guaranteed no cascades
  225.           @pins[ ( @lock_number * @lockpick_sprite.position ) %
  226.             @pins.size ].raise
  227.         end
  228.         if $game_temp.lock_difficulty == LOCK_INSANE
  229.           @pins[ ( @lock_number + @lockpick_sprite.position ) %
  230.             @pins.size ].lower
  231.         end
  232.       else
  233.         $game_system.se_play($data_system.buzzer_se)
  234.       end
  235.     end
  236.    
  237.     # knock a tumbler down - cascades
  238.     if Input.trigger?( Input::DOWN )
  239.       @pins[ @lockpick_sprite.position ].lower
  240.       if @pins[ @lockpick_sprite.position ].move?
  241.         $game_system.se_play( Tumbler::TUMBLER_AUDIO_DOWN )
  242.         @lockpick_sprite.tap_down
  243.         if @lockpick_sprite.position > 0 # first pin guaranteed no cascades
  244.           @pins[ ( @lock_number * @lockpick_sprite.position ) %
  245.             @pins.size ].lower
  246.         end
  247.         if $game_temp.lock_difficulty == LOCK_INSANE
  248.           @pins[ ( @lock_number + @lockpick_sprite.position ) %
  249.             @pins.size ].raise
  250.         end
  251.       else
  252.         $game_system.se_play( $data_system.buzzer_se )
  253.       end
  254.     end
  255.  
  256.     # game finished, maybe
  257.     if Input.trigger?( Input::C )
  258.       unlockable = true
  259.       for i in [email hidden]
  260.         if not @pins[ i ].open?
  261.           unlockable = false
  262.           break
  263.         end
  264.       end
  265.       if unlockable
  266.        
  267.         $game_system.se_play( LOCK_AUDIO_UNLOCK )
  268.         $scene = Scene_Map.new
  269.        
  270.         # change the specified result switch
  271.         if @result_switch == 'X'
  272.           # not a self-switch
  273.           $game_switches[ @result_id ] = true
  274.         else
  275.           $game_self_switches[ [ $game_map.map_id, @result_id,
  276.             @result_switch ] ] = true
  277.         end
  278.         $game_map.need_refresh = true
  279.       else
  280.         $game_system.se_play( $data_system.buzzer_se )
  281.       end
  282.     end
  283.  
  284.   end
  285.  
  286.   #--------------------------------------------------------------------------
  287.   # * Main Processing : Ending
  288.   #--------------------------------------------------------------------------
  289.   def main_end
  290.     Audio.bgm_fade( 2000 )
  291.   end
  292.  
  293.   #--------------------------------------------------------------------------
  294.   # * set_result specifies which game switch is to be changed to true on a
  295.   # successful lockpick.
  296.   # id = event id for a self-switch, or switch id for a global switch
  297.   # self_switch = 'A', etc. for a self-switch.
  298.   # LEAVE self_switch BLANK TO SPECIFY A GLOBAL SWITCH
  299.   #--------------------------------------------------------------------------
  300.   def set_result( id, self_switch = 'X' )
  301.     @result_id = id
  302.     @result_switch = self_switch
  303.   end
  304.  
  305. end # class Scene_LockpickMinigame
  306.  
  307. #==============================================================================
  308. # ** Tumbler
  309. #------------------------------------------------------------------------------
  310. #  Tumbler represents one of the lock's tumblers
  311. #==============================================================================
  312. class Tumbler < Sprite
  313.   #---------------------------------------------------------------------------+
  314.   # Tumbler Constants                                                         |
  315.   #---------------------------------------------------------------------------+
  316.   # Maximum vertical size (in potential openings) of a tumbler
  317.   TUMBLER_POSITIONS = 6
  318.  
  319.   # Bitmap sources for the pictures
  320.   TUMBLER_PIN_BITMAP    = RPG::Cache.picture( 'lockpick_pins' )
  321.   TUMBLER_SPRING_BITMAP = [
  322.     RPG::Cache.picture( 'lockpick_spring1' ),
  323.     RPG::Cache.picture( 'lockpick_spring2' ),
  324.     RPG::Cache.picture( 'lockpick_spring3' ),
  325.     RPG::Cache.picture( 'lockpick_spring4' ),
  326.     RPG::Cache.picture( 'lockpick_spring5' ),
  327.     RPG::Cache.picture( 'lockpick_spring6' )
  328.   ]
  329.   TUMBLER_BACKGROUND_BITMAP = RPG::Cache.picture( 'lockpick_pin_background' )
  330.  
  331.   # Source rectangles inside the tumbler pin bitmap
  332.   TUMBLER_DRIVER_TOP    = Rect.new(  0,  0, 20,  2 )
  333.   TUMBLER_DRIVER_MIDDLE = Rect.new(  0,  2, 20, 27 )
  334.   TUMBLER_DRIVER_BOTTOM = Rect.new(  0, 29, 20,  3 )
  335.   TUMBLER_KEY_TOP       = Rect.new( 20,  0, 20,  3 )
  336.   TUMBLER_KEY_MIDDLE    = Rect.new( 20,  3, 20, 17 )
  337.   TUMBLER_KEY_BOTTOM    = Rect.new( 20, 20, 20, 12 )
  338.  
  339.   # Audio for ratcheting
  340.   TUMBLER_AUDIO_UP   = RPG::AudioFile.new( 'tumbler', 100, 105 )
  341.   TUMBLER_AUDIO_DOWN = RPG::AudioFile.new( 'tumbler', 100,  95 )
  342.  
  343.   # Rate at which the tumbler pins move up and down
  344.   TUMBLER_MOVE_SPEED = 2  # this should be a factor of 20 (ie, 1, 2, 4, 5 )
  345.  
  346.   #---------------------------------------------------------------------------+
  347.   # Tumbler Methods                                                           |
  348.   #---------------------------------------------------------------------------+
  349.   def initialize( *arg )
  350.     super *arg
  351.     @opening = rand( TUMBLER_POSITIONS )
  352.     while @level.nil? or @level + @opening == TUMBLER_POSITIONS - 1
  353.       @level = rand( TUMBLER_POSITIONS )
  354.     end
  355.     self.bitmap = Bitmap.new( 22, 262 )
  356.     self.bitmap.blt( 0, 0, TUMBLER_BACKGROUND_BITMAP,
  357.       TUMBLER_BACKGROUND_BITMAP.rect )
  358.     @current = ( @level + 1 ) * 20 - TUMBLER_MOVE_SPEED
  359.   end
  360.  
  361.   #--------------------------------------------------------------------------
  362.   # * raise moves the tumbler up a number of clicks
  363.   # distance = maximum distance raised
  364.   #--------------------------------------------------------------------------
  365.   def raise( distance = 1 )
  366.     @level -= distance
  367.     if @level >= TUMBLER_POSITIONS
  368.       @level = TUMBLER_POSITIONS - 1
  369.     elsif @level < 0
  370.       @level = 0
  371.     end
  372.   end
  373.  
  374.   #--------------------------------------------------------------------------
  375.   # * lower moves the tumbler down a number of clicks
  376.   # distance = maximum distance lowered
  377.   #--------------------------------------------------------------------------
  378.   def lower( distance = 1 )
  379.     @level += distance
  380.     if @level >= TUMBLER_POSITIONS
  381.       @level = TUMBLER_POSITIONS - 1
  382.     elsif @level < 0
  383.       @level = 0
  384.     end
  385.   end
  386.  
  387.   #--------------------------------------------------------------------------
  388.   # * open? determines if the current level is the same as the opening
  389.   # between the driver and key pins
  390.   #--------------------------------------------------------------------------
  391.   def open?
  392.     return @level + @opening == TUMBLER_POSITIONS - 1
  393.   end
  394.  
  395.   #--------------------------------------------------------------------------
  396.   # * move? determines if the pin is currently moving
  397.   #--------------------------------------------------------------------------
  398.   def move?
  399.     return @current != ( @level + 1 ) * 20
  400.   end
  401.  
  402.   #--------------------------------------------------------------------------
  403.   # * update updates the current display of the tumbler, ratcheting it up
  404.   # or down depending on its current position vs. desired
  405.   #--------------------------------------------------------------------------
  406.   def update
  407.    
  408.     super
  409.    
  410.     # See if we need to update position
  411.     if not move?
  412.       return
  413.     elsif @current - ( @level + 1 ) * 20 > 0
  414.       @current -= TUMBLER_MOVE_SPEED # move up
  415.     else
  416.       @current += TUMBLER_MOVE_SPEED # move down
  417.     end
  418.    
  419.     # Fill in the background
  420.     self.bitmap.fill_rect( Rect.new( 1, 1, 20, 260 ),
  421.       Color.new( 255, 255, 255 ) )
  422.    
  423.     # Draw the spring
  424.     spring_level = ( ( @current + 10 ) / 20 ) - 1
  425.     self.bitmap.stretch_blt( Rect.new( 1, 1, 20, @current + 1 ),
  426.       TUMBLER_SPRING_BITMAP[ spring_level ],
  427.       TUMBLER_SPRING_BITMAP[ spring_level ].rect )
  428.      
  429.     # Draw the driver pin
  430.     self.bitmap.blt( 1, @current + 1, TUMBLER_PIN_BITMAP,
  431.       TUMBLER_DRIVER_TOP )
  432.     self.bitmap.stretch_blt( Rect.new( 1, @current + 3, 20,
  433.       ( @opening + 1 ) * 20 - 5 ), TUMBLER_PIN_BITMAP,
  434.       TUMBLER_DRIVER_MIDDLE )
  435.     self.bitmap.blt( 1, ( @opening + 1 ) * 20 + @current - 2,
  436.       TUMBLER_PIN_BITMAP, TUMBLER_DRIVER_BOTTOM )
  437.    
  438.     # Draw the key pin
  439.     self.bitmap.blt( 1, ( @opening + 1 ) * 20 + @current + 1,
  440.       TUMBLER_PIN_BITMAP, TUMBLER_KEY_TOP )
  441.     self.bitmap.stretch_blt( Rect.new( 1, ( @opening + 1 ) * 20 + @current + 4,
  442.       20, ( TUMBLER_POSITIONS - @opening ) * 20 - 15 ), TUMBLER_PIN_BITMAP,
  443.       TUMBLER_KEY_MIDDLE )
  444.     self.bitmap.blt( 1, ( TUMBLER_POSITIONS + 1 ) * 20 + @current - 11,
  445.       TUMBLER_PIN_BITMAP, TUMBLER_KEY_BOTTOM )
  446.    
  447.   end
  448.  
  449.  
  450.   def set_result_switch( event_id, switch_id )
  451.   end
  452.  
  453. end # class Tumbler
  454.  
  455. #==============================================================================
  456. # ** Lockpick
  457. #------------------------------------------------------------------------------
  458. #  Lockpick represents the game's lockpick
  459. #==============================================================================
  460. class Lockpick < Sprite
  461.  
  462.   attr_accessor :tumblers
  463.   attr_accessor :position
  464.  
  465.   #---------------------------------------------------------------------------+
  466.   # Lockpick Constants                                                         |
  467.   #---------------------------------------------------------------------------+
  468.   LOCKPICK_X_OFFSET = ( 640 - Scene_LockpickMinigame::CYLINDER_WIDTH ) / 2 - 482
  469.   LOCKPICK_MOVEMENT_SPEED = 8  # This can be any integer; higher is faster
  470.  
  471.   #--------------------------------------------------------------------------
  472.   # * initialize sets the starting lockpick x coordinate
  473.   #--------------------------------------------------------------------------
  474.   def initialize( *arg )
  475.     super *arg
  476.    
  477.     self.bitmap = RPG::Cache.picture( 'lockpick_lockpick' )
  478.     self.x = LOCKPICK_X_OFFSET
  479.     self.y = 355
  480.    
  481.     @position = 0
  482.     @current = 0
  483.     @tumblers = 1
  484.     @tap_count = 0
  485.   end
  486.  
  487.   #--------------------------------------------------------------------------
  488.   # * move_right moves the lockpick right one tumbler
  489.   #--------------------------------------------------------------------------
  490.   def move_right
  491.     if @tap_count != 0
  492.       return
  493.     end
  494.     if @position >= @tumblers - 1
  495.       @position = @tumblers - 1
  496.     else
  497.       @position += 1
  498.     end
  499.   end
  500.  
  501.   #--------------------------------------------------------------------------
  502.   # * move_left moves the lockpick left one tumbler
  503.   #--------------------------------------------------------------------------
  504.   def move_left
  505.     if @tap_count != 0
  506.       return
  507.     end
  508.     if @position <= 0
  509.       @position = 0
  510.     else
  511.       @position -= 1
  512.     end
  513.   end
  514.  
  515.   #--------------------------------------------------------------------------
  516.   # * tap_up moves the lockpick in an upwards tapping motion
  517.   #--------------------------------------------------------------------------
  518.   def tap_up
  519.     @tap_count = 8
  520.   end
  521.  
  522.   #--------------------------------------------------------------------------
  523.   # * tap_down moves the lockpick in a downwards tapping motion
  524.   #--------------------------------------------------------------------------
  525.   def tap_down
  526.     @tap_count = -6
  527.   end
  528.  
  529.   #--------------------------------------------------------------------------
  530.   # * move? determines if the lockpick needs to move
  531.   #--------------------------------------------------------------------------
  532.   def move?
  533.     current_x = Scene_LockpickMinigame::CYLINDER_WIDTH * ( @position + 1 ) /
  534.       ( @tumblers + 1 )
  535.     return ( @current != current_x or @tap_count != 0 )
  536.   end
  537.  
  538.   #--------------------------------------------------------------------------
  539.   # * initialize sets the starting lockpick x coordinate
  540.   #--------------------------------------------------------------------------
  541.   def update
  542.     super
  543.    
  544.     # See if we're animated up or down
  545.     if @tap_count != 0 # down
  546.       if @tap_count < 0
  547.         self.x = @current + LOCKPICK_X_OFFSET
  548.         self.y = 354 - @tap_count
  549.         @tap_count += 1
  550.       else # up
  551.         self.x = @current + LOCKPICK_X_OFFSET - @tap_count
  552.         self.y = 356 - @tap_count
  553.         @tap_count -= 1
  554.       end
  555.       return
  556.     end
  557.  
  558.     # See if we need to update position
  559.     if not move?
  560.       return
  561.     elsif Scene_LockpickMinigame::CYLINDER_WIDTH * ( @position + 1 ) /
  562.         ( @tumblers + 1 ) > @current
  563.       @current += LOCKPICK_MOVEMENT_SPEED
  564.     else
  565.       @current -= LOCKPICK_MOVEMENT_SPEED
  566.     end
  567.    
  568.     # if we're close, just set it to the right value
  569.     if ( @current - Scene_LockpickMinigame::CYLINDER_WIDTH * ( position + 1 ) /
  570.         ( @tumblers + 1 ) ).abs <=
  571.         LOCKPICK_MOVEMENT_SPEED / 2
  572.       @current = Scene_LockpickMinigame::CYLINDER_WIDTH * ( @position + 1 ) /
  573.         ( @tumblers + 1 )
  574.     end
  575.  
  576.     self.x = @current + LOCKPICK_X_OFFSET
  577.     self.y = 355
  578.   end
  579.  
  580. end # class Lockpick
  581.  
  582. end # if SDK.enabled?
Expand to see the code.


Instructions (using the Demo as a base)

Editing
  1. Change the main background by swapping out Graphics/Pictures/lockpick_background.png for whatever you want.
  2. Change the audio file at Audio/BGM/lockpick_music.mp3
  3. Change the color of the tumblers by messing withGraphics/Pictures/lockpick_pins.png, but I don't recommend changing the sizes of the pins.
  4. Finally, change the minigame lock background colors by editing both Graphics/Pictures/lockpick_cylinder.png and Graphics/Pictures/lockpick_pin_background.png
  5. This script isn't otherwise very customizeable at the moment. Feel free to tinker with the number of tumblers per difficulty and such.

Usage

See the two chests for the two ways to use this script; one method puts the lockpicking result in a specified event's self switches, the other puts it in a specified global switch.

FAQ

None yet...

Compatibility

SDK 2.3 compatible

Author's Notes

I don't know what I have to do to make this SDK 2.4 compatible, but I will probably do so sometime in the near future.

Feel free to make any comments or suggestions.

Terms and Conditions

This script is released under GPL 3. Please list my name in the credits if you use this!

* There is a non-zero probability that two games may actually be the same.
I am surprised this hasn't got any feedback considering I've seen probably 100 topics requesting just this. I can say I cannot actually offer any advice on your coding at all. It's perfect! Formatting, style, structure are perfect. Ok, maybe the only thing I would do different is making a lock picking module, placing all constants within that module, and making your class classes of your module, but that is all a personal preference for organization and in no way improves your code.

Fantastic code all around and really fun to play. Great script. :thumb:

PS: This will be compatible with any SDK version as long as it includes the SDK::Scene_Base class, as it appears it is the only aspect of the SDK this script relies on.
Thank you for your kind words. The script was pretty well-received the first time around; I think that there just isn't much call for RMXP scripts these days.
While I agree with Seph that it's definately one of the better scripts on .org, I wouldn't really say it's perfect... most is personal preference as well, but since that doesn't count, here's something I think would be generally seen as redundancy:
  1. LOCK_VERY_EASY  = 0
  2. LOCK_EASY       = 1
  3. LOCK_AVERAGE    = 2
  4. LOCK_DIFFICULT  = 3
  5. LOCK_INSANE     = 4
Expand to see the code.
Overall, you have a lot of constants in there that I don't think need to be necessarily defined... shouldn't be much of a performance issue though.
But yeah, that is some nice coding you have there - especially if you "slapped it together" ;)

As for the XP script needs... it seems to me that RMXP is still the wider-spread maker out there, so that might not be the issue. Personally though, if I'd be looking for a lockpicking script and couldn't script it myself, I wouldn't take this one... just too non-realistic (who sees the lock in a cut-open perspective when picking? ^^).

Keep up the good work!

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