Advertisement
roninator2

Neon Black - Lockpicking v1.2.1

Nov 18th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.10 KB | None | 0 0
  1. ##----------------------------------------------------------------------------##
  2. ## Lockpicking Script v1.2.1
  3. ## Created by Neon Black
  4. ## Modded by Roninator2 - correcting a bug and adding broken locks
  5. ## For both commercial and non-commercial use as long as credit is given to
  6. ## Neon Black and any additional authors.  Licensed under Creative Commons
  7. ## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
  8. ##----------------------------------------------------------------------------##
  9.                                                                               ##
  10. ##----------------------------------------------------------------------------##
  11. ##    Revision Info:
  12. ## V1.2.1 - 30.4.2020 Fixed bug and added message for broken lock
  13. ## V1.2 - 29.4.2020 Added durability for locks and fixed bug for locks
  14. ## v1.1 - 3.3.2013
  15. ##  Cleanup and debug for official Ace release
  16. ## v1.0 - 9.11.2012
  17. ##  Converted from VX script
  18. ##----------------------------------------------------------------------------##
  19.                                                                               ##
  20. $imported ||= {}                                                              ##
  21. $imported["CP_LOCKPICK"] = 1.1                                                ##
  22.                                                                               ##
  23. ##----------------------------------------------------------------------------##
  24. ##     VXA Notes:
  25. ## This is the VXA version of my lockpicking script ported from VX.  There were
  26. ## a few modifications made to allow it to run properly, however the script
  27. ## remains mostly unchanged.
  28. ##
  29. ##     Instructions:
  30. ## Place this script in the "Materials" section of the scripts above main.
  31. ## This script is NOT plug and play and requires additional graphics and
  32. ## several setting changes to work properly.  Please be sure you have imported
  33. ## the required graphics before continuing.
  34. ##
  35. ## To use, place a script call in an event and use the following script call:
  36. ##
  37. ##   Lockpick.start(x[, y])
  38. ## Define "x" as a numeric value that represents the difficulty of the lock
  39. ## where lower numbers are easier to pick.  It is recommended to only use
  40. ## values ranging form 2-8 because 1 seems to be too easy and 9 seems to be too
  41. ## hard.  The "y" argument is a little more complex but is completely optional.
  42. ## "y" is simply the variable that holds the "lock durability".  If "y" is
  43. ## defined, breaking a pick will break the lock instead.  The durability of the
  44. ## lock will be stored in variable "y" so that the player cannot leave the lock
  45. ## and return with full durability.  If the variable contains a value of "0"
  46. ## when lockpicking starts, the variable will be changed to the default
  47. ## durability for picks.  A variable with the value -1 is considered a broken
  48. ## lock.  Note that even with a gold lockpick or with lockpick breaking
  49. ## disabled, locks can still be broken.  To make a lock "unbreakable", set the
  50. ## variable to a value lower than -100 as -1 to -99 are used to check breaking
  51. ##
  52. ## When a lock is picked, one of three different numbers will be returned in
  53. ## pre-determined variable.  The numbers are as follows.
  54. ##   1 - Returned if the player picks the lock.
  55. ##   2 - Returned if the player cancels lockpicking.
  56. ##   3 - Returned if the player breaks all their picks or has none.
  57. ##   4 - Returned Lock Broke
  58. ## The player must have at least one of a pre-determined item in order to pick
  59. ## a lock.  The item is determined in the config section.
  60. ##----------------------------------------------------------------------------##
  61.                                                                               ##
  62. module CP       # Do not touch                                                ##
  63. module LOCKPICK #  these lines.                                               ##
  64.                                                                               ##
  65. ##----------------------------------------------------------------------------##
  66. ##    Config:
  67. ## The config options are below.  You can set these depending on the flavour of
  68. ## your game.  Each option is explained in a bit more detail above it.
  69. ##
  70. ##------
  71. # The main game settings are below.  These include mose of the sound effects and
  72. # variable settings in the script.
  73. module SETTINGS
  74.  
  75. # The ID number of picks in the database.  The player must have a least 1
  76. # lockpick in their inventory before they can pick locks.
  77. PICK_ITEM = 16
  78.  
  79. # These are the golden lockpick settings.  A golden lockpick will not break and
  80. # is used by default if it is in the inventory.  It can be diabled if you do not
  81. # want to use it.
  82. USE_G_PICK = false
  83. G_PICK_ITEM = 17
  84.  
  85. # The variable that returns the result of lockpicking success.
  86. VARIABLE = 10
  87.  
  88. # The sound effect, volume, and pitch played when starting to pick a lock.
  89. LOCK_SOUND = "Switch2"
  90. LOCK_VOLUME = 60
  91. LOCK_PITCH = 110
  92.  
  93. # The sound effect, volume, and pitch played when unlocking a lock.
  94. UNLOCK_SOUND = "Key"
  95. UNLOCK_VOLUME = 80
  96. UNLOCK_PITCH = 100
  97.  
  98. # The sound effect, volume, and pitch played when breaking a pick.
  99. BREAK_SOUND = "Sword2"
  100. BREAK_VOLUME = 60
  101. BREAK_PITCH = 130
  102.  
  103. # Determines the switch for breaking picks and the durability lockpicks have.
  104. # Higher values in durability will take longer to break.  If the switch is
  105. # turned on, picks can be broken.  If "BREAK_PICKS" is set to true, the switch
  106. # is turned on by default.
  107. BREAK_PICK_SWITCH = 10
  108. BREAK_PICKS = true
  109. LOCK_DURABILITY = 120
  110. PICK_DURABILITY = 90
  111. BROKEN = "This lock is broken"
  112.  
  113. # A dialog box can be drawn in the bottom left corner with the remaining picks
  114. # in your possession.  Setting this to false will not show that box.  You may
  115. # also set the text to be shown in the box.
  116. SHOW_REMAINING = true
  117. ITEM_NAME = "Lockpicks:"
  118.  
  119. end
  120. ##------
  121. # The settings for the graphics are below.  Use these to specify the graphics
  122. # used and the X and Y offsets from the middle of the screen.  Note that all
  123. # graphics must exist in the "pictures" folder.
  124. module LOCK
  125.  
  126. # Settings for the lock graphic.
  127. X_OFFSET = 0
  128. Y_OFFSET = 0
  129. GRAPHIC = "Lock"
  130.  
  131. end
  132. module PICK
  133.  
  134. # Settings for the pick graphic.
  135. X_OFFSET = 0
  136. Y_OFFSET = 30
  137. GRAPHIC = "Pick"
  138.  
  139. end
  140. module KEY
  141.  
  142. # Settings for the "key" graphic.
  143. X_OFFSET = 0
  144. Y_OFFSET = -20
  145. GRAPHIC = "Key"
  146.  
  147. end
  148. ##----------------------------------------------------------------------------##
  149.                                                                               ##
  150.                                                                               ##
  151. ##----------------------------------------------------------------------------##
  152. ## The following lines are the actual core code of the script.  While you are
  153. ## certainly invited to look, modifying it may result in undesirable results.
  154. ## Modify at your own risk!
  155. ###----------------------------------------------------------------------------
  156.  
  157.  
  158. end
  159. end
  160.  
  161. class Window_Picks < Window_Base
  162.   def initialize
  163.     super(0, Graphics.height - fitting_height(1), 160, fitting_height(1))
  164.     refresh
  165.   end
  166.  
  167.   def draw_picks(value, x, y, width)
  168.     pick_name = CP::LOCKPICK::SETTINGS::ITEM_NAME
  169.     cx = contents.text_size(pick_name).width
  170.     self.contents.font.color = normal_color
  171.     self.contents.draw_text(x+cx+2, y, width-cx-2, 24, value)
  172.     self.contents.font.color = system_color
  173.     self.contents.draw_text(x, y, width, 24, pick_name)
  174.   end
  175.  
  176.   def refresh
  177.     self.contents.clear
  178.     itemnum = CP::LOCKPICK::SETTINGS::PICK_ITEM
  179.     draw_picks($game_party.item_number($data_items[itemnum]), 4, 0,
  180.                contents.width - 8)
  181.   end
  182. end
  183.  
  184. class Lockpick < Scene_MenuBase
  185.   def self.start(diffi, door_var = nil)
  186.     SceneManager.call(Lockpick)
  187.     SceneManager.scene.prepare(diffi, door_var)
  188.     Fiber.yield
  189.   end
  190.  
  191.   def prepare(diffi, door_var)
  192.     @diffi = diffi
  193.     @door = $game_variables[door_var] unless door_var.nil?
  194.     @doorvar = door_var
  195.     @door = CP::LOCKPICK::SETTINGS::LOCK_DURABILITY if @door == nil
  196.     if @door == -1
  197.       lock_broke
  198.     end
  199.     @key_rotation = 0
  200.     @pick_rotation = 90
  201.     @zone = rand(90) * 2
  202.     @wobble = 0
  203.     @durability = CP::LOCKPICK::SETTINGS::PICK_DURABILITY
  204.     @did_turn = false
  205.     picksnum = CP::LOCKPICK::SETTINGS::PICK_ITEM
  206.     gpicknum = CP::LOCKPICK::SETTINGS::G_PICK_ITEM
  207.     usegp = CP::LOCKPICK::SETTINGS::USE_G_PICK
  208.     @haspicks = true if $game_party.has_item?($data_items[picksnum])
  209.     @haspicks = true if $game_party.has_item?($data_items[gpicknum]) and usegp
  210.     @haspicks = false if @door == -1
  211.   end
  212.  
  213.   def start ## Start scene.  Draws items on screen.
  214.     super
  215.     @picks_window = Window_Picks.new if CP::LOCKPICK::SETTINGS::SHOW_REMAINING
  216.     @picks_window.z = 4 if @picks_window
  217.     create_lock
  218.     create_key
  219.     create_pick if @haspicks
  220.     key_math
  221.   end
  222.  
  223.   def terminate
  224.     super
  225.     @lock_sprite.dispose
  226.     @key_sprite.dispose
  227.     @pick_sprite.dispose if @pick_sprite
  228.   end
  229.  
  230.   def update
  231.     super
  232.     update_pick_command
  233.     update_key_position
  234.     update_pick_position if @haspicks
  235.   end
  236.  
  237.   def create_lock
  238.     @lock_sprite = Sprite.new
  239.     @lock_sprite.bitmap = Cache.picture(CP::LOCKPICK::LOCK::GRAPHIC)
  240.     @lock_sprite.ox = @lock_sprite.width/2
  241.     @lock_sprite.oy = @lock_sprite.height/2
  242.     @lock_sprite.x = Graphics.width/2 + CP::LOCKPICK::LOCK::X_OFFSET
  243.     @lock_sprite.y = Graphics.height/2 + CP::LOCKPICK::LOCK::Y_OFFSET
  244.     @lock_sprite.z = 1
  245.   end
  246.  
  247.   def create_key
  248.     @key_sprite = Sprite.new
  249.     @key_sprite.bitmap = Cache.picture(CP::LOCKPICK::KEY::GRAPHIC)
  250.     @key_sprite.ox = @key_sprite.width/2
  251.     @key_sprite.oy = @key_sprite.height/2
  252.     @key_sprite.x = Graphics.width/2 + CP::LOCKPICK::KEY::X_OFFSET
  253.     @key_sprite.y = Graphics.height/2 + CP::LOCKPICK::KEY::Y_OFFSET
  254.     @key_sprite.z = 3
  255.     @k_rotate = @key_rotation
  256.     @key_sprite.angle = @k_rotate * -1
  257.   end
  258.  
  259.   def update_key_position
  260.     return if @key_rotation == @k_rotate
  261.     @k_rotate = @key_rotation
  262.     @key_sprite.angle = @k_rotate * -1
  263.   end
  264.  
  265.   def create_pick
  266.     @pick_sprite = Sprite.new
  267.     @pick_sprite.bitmap = Cache.picture(CP::LOCKPICK::PICK::GRAPHIC)
  268.     @pick_sprite.ox = @pick_sprite.width/2
  269.     @pick_sprite.oy = @pick_sprite.width/2
  270.     @pick_sprite.x = Graphics.width/2 + CP::LOCKPICK::PICK::X_OFFSET
  271.     @pick_sprite.y = Graphics.height/2 + CP::LOCKPICK::PICK::Y_OFFSET
  272.     @pick_sprite.z = 2
  273.     @p_rotate = @pick_rotation
  274.     @pick_sprite.angle = @p_rotate - 90
  275.   end
  276.  
  277.   def update_pick_position
  278.     return if @pick_rotation == @p_rotate and @wobble == @shake
  279.     @p_rotate = @pick_rotation
  280.     @shake = @wobble
  281.     @pick_sprite.angle = @p_rotate - 90 + @shake
  282.   end
  283.  
  284.   def wait(dur)
  285.     for i in 0...dur
  286.       update_basic
  287.     end
  288.   end
  289.  
  290.   def lock_picked
  291.     variable = CP::LOCKPICK::SETTINGS::VARIABLE
  292.     $game_variables[@doorvar] = @door unless @doorvar == nil
  293.     $game_variables[variable] = 1
  294.     update_key_position
  295.     wait(20)
  296.     picking_end
  297.   end
  298.  
  299.   def lock_stopped
  300.     Sound.play_cancel
  301.     variable = CP::LOCKPICK::SETTINGS::VARIABLE
  302.     $game_variables[@doorvar] = @door unless @doorvar == nil
  303.     $game_variables[variable] = 2
  304.     picking_end
  305.   end
  306.  
  307.   def no_picks
  308.     variable = CP::LOCKPICK::SETTINGS::VARIABLE
  309.     $game_variables[@doorvar] = @door unless @doorvar == nil
  310.     $game_variables[variable] = 3
  311.     picking_end
  312.   end
  313.  
  314.   def lock_broke
  315.     variable = CP::LOCKPICK::SETTINGS::VARIABLE
  316.     $game_variables[@doorvar] = @door unless @doorvar == nil
  317.     $game_variables[variable] = 4
  318.     $game_message.add(CP::LOCKPICK::SETTINGS::BROKEN) if @door == -1
  319.     picking_end
  320.   end
  321.  
  322.   def picking_end
  323.     SceneManager.return
  324.   end
  325.  
  326.   def update_pick_command
  327.     if Input.trigger?(:B) ##----- Cancel
  328.       lock_stopped
  329.     elsif Input.trigger?(:C) ##----- Key turning input
  330.       @did_turn = true
  331.       if @haspicks == true && @door == -1
  332.         lock_broke
  333.       elsif @haspicks == true
  334.         lsnd = CP::LOCKPICK::SETTINGS::LOCK_SOUND
  335.         lvol = CP::LOCKPICK::SETTINGS::LOCK_VOLUME
  336.         lpit = CP::LOCKPICK::SETTINGS::LOCK_PITCH
  337.         Audio.se_play("Audio/SE/" + lsnd, lvol, lpit)
  338.       else
  339.         no_picks
  340.       end
  341.     elsif Input.press?(:C) and @did_turn
  342.       unless @key_rotation > @max_turn - 2
  343.         @key_rotation += 2
  344.       else
  345.         pick_dura
  346.       end
  347.       if @key_rotation == 90
  348.         lsnd = CP::LOCKPICK::SETTINGS::UNLOCK_SOUND
  349.         lvol = CP::LOCKPICK::SETTINGS::UNLOCK_VOLUME
  350.         lpit = CP::LOCKPICK::SETTINGS::UNLOCK_PITCH
  351.         Audio.se_play("Audio/SE/" + lsnd, lvol, lpit)
  352.         lock_picked
  353.       end
  354.     else ##----- Lockpick movement below
  355.       @wobble = 0 unless @wobble == 0
  356.       @key_rotation -= 2 unless @key_rotation == 0
  357.       @key_rotation = 0 if @key_rotation < 0
  358.       if Input.press?(:RIGHT)
  359.         @pick_rotation += 2 unless @pick_rotation == 180
  360.         key_math
  361.       elsif Input.press?(:LEFT)
  362.         @pick_rotation -= 2 unless @pick_rotation == 0
  363.         key_math
  364.       end
  365.     end
  366.   end
  367.  
  368.   def key_math
  369.     if ((@zone-4)..(@zone+4)) === @pick_rotation
  370.       @max_turn = 90
  371.     else
  372.       check_spot = @pick_rotation - @zone
  373.       check_spot *= -1 if check_spot < 0
  374.       check_spot -= 4
  375.       check_spot *= @diffi
  376.       @max_turn = 90 - check_spot
  377.       @max_turn = 0 if @max_turn < 0
  378.     end
  379.   end
  380.  
  381.   def pick_dura  ## Checks the pick's durability with each step.
  382.     @wobble = rand(5) - 2
  383.     if @door != nil
  384.       @durability -= @diffi
  385.       snap_pick if @durability < 1 and @durability > -100
  386.     elsif $game_switches[CP::LOCKPICK::SETTINGS::BREAK_PICK_SWITCH]
  387.       gpicknum = CP::LOCKPICK::SETTINGS::G_PICK_ITEM
  388.       usegp = CP::LOCKPICK::SETTINGS::USE_G_PICK
  389.       unless $game_party.has_item?($data_items[gpicknum]) and usegp
  390.         @durability -= @diffi
  391.         snap_pick if @durability < 1
  392.       end
  393.     end
  394.   end
  395.  
  396.   def snap_pick  ## Snaps the pick if durability is 0 or lower.
  397.     lsnd = CP::LOCKPICK::SETTINGS::BREAK_SOUND
  398.     lvol = CP::LOCKPICK::SETTINGS::BREAK_VOLUME
  399.     lpit = CP::LOCKPICK::SETTINGS::BREAK_PITCH
  400.     Audio.se_play("Audio/SE/" + lsnd, lvol, lpit)
  401.     for i in 0...5
  402.       @pick_sprite.y += 3
  403.       update_basic
  404.     end
  405.     wait(10)
  406.     if @door != nil && @haspicks == true
  407.       @door -= @diffi * 3
  408.       @door = -1 if @door < 1
  409.       $game_variables[@doorvar] = -1 if @door == -1 unless @doorvar == nil
  410.       if @door == -1
  411.         lock_broke
  412.       else
  413.         change_pick
  414.       end
  415.     elsif @door != nil && @haspicks == false
  416.       @door -= @diffi * 3
  417.       @door = -1 if @door < 1
  418.       $game_variables[@doorvar] = -1 if @door == -1 unless @doorvar == nil
  419.       picksnum = CP::LOCKPICK::SETTINGS::PICK_ITEM
  420.       gpicknum = CP::LOCKPICK::SETTINGS::G_PICK_ITEM
  421.       usegp = CP::LOCKPICK::SETTINGS::USE_G_PICK
  422.       return no_picks unless $game_party.has_item?($data_items[picksnum]) ||
  423.       $game_party.has_item?($data_items[gpicknum]) and usegp
  424.     else
  425.       change_pick
  426.     end
  427.   end
  428.  
  429.   def change_pick  ## Removes a pick and prepares to change it.
  430.     itemnum = CP::LOCKPICK::SETTINGS::PICK_ITEM
  431.     $game_party.lose_item($data_items[itemnum], 1)
  432.         $game_variables[12] -= 1
  433.     @picks_window.refresh if CP::LOCKPICK::SETTINGS::SHOW_REMAINING
  434.     if $game_party.has_item?($data_items[itemnum]) and @door != -1
  435.       new_pick
  436.     elsif !$game_party.has_item?($data_items[itemnum])
  437.       no_picks
  438.     end
  439.   end
  440.  
  441.   def new_pick  ## Places a new pick if one is present.
  442.     @key_rotation = 0
  443.     @pick_rotation = 90
  444.     @wobble = 0
  445.     @durability = CP::LOCKPICK::SETTINGS::PICK_DURABILITY
  446.     @pick_sprite.dispose
  447.     create_pick
  448.     update_key_position
  449.     wait(10)
  450.   end
  451. end
  452.  
  453. module DataManager
  454.   class << self
  455.     alias :cp_lockpick_cgo :create_game_objects
  456.   end
  457.  
  458.   def self.create_game_objects
  459.     cp_lockpick_cgo
  460.     onoroff = CP::LOCKPICK::SETTINGS::BREAK_PICKS
  461.     $game_switches[CP::LOCKPICK::SETTINGS::BREAK_PICK_SWITCH] = onoroff
  462.   end
  463. end
  464.  
  465.  
  466. ###--------------------------------------------------------------------------###
  467. #  End of script.                                                              #
  468. ###--------------------------------------------------------------------------###
  469.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement