Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Lock Picking System

Status
Not open for further replies.
Lock Picking System
Version: 1.6


Introduction

This script does almost exactly what you can do with a lock pick in The Elder Scroll III: Morrowind.

Features
  • Easy to use
  • Lock picking menu
  • Lock picking messages
  • Lock picking level
  • Edit Exp curve with a .rxdata file
  • Exp Curve Generator
  • Can be limited to certain actors
  • Can be limited to certain classes
  • Can use current actor's level as its lock picking level
  • Target's lock can break
Screenshots

I'm not as cruel as Trickster:p
http://img122.imageshack.us/img122/9322/lockpickkz5.th.jpg[/IMG]

Demo

Version 1.0

Script

Code:
#==============================================================================
# ** Lock Pick System
#------------------------------------------------------------------------------
#  Author: Dargor
#  Requested by: Isopaha
#  Version 1.6
#  25/06/2007
#==============================================================================
# * Instructions
#------------------------------------------------------------------------------
# - Setup an event and use the call script command: 
#      scene = Scene_LockPick.new(event_id, lock_level, max_try)
#   max_try: maximum number of trys before the lock is broken.
#            When set to -1, the lock can't be broken
#------------------------------------------------------------------------------
# * Note
#------------------------------------------------------------------------------
# - Thanks to Isopaha for requesting the script! And don't forget to 
#   give me credits!
#==============================================================================
module Lockpicking
  Actors = [1,2]
  Classes = [1,2,3]
  Use_Actors_Level = [2]
  Exp_Curve_File = "Data/Lockpick_Exp_Curve.rxdata"
  #--------------------------------------------------------------------------
  # * Generate Experience Curve
  #--------------------------------------------------------------------------
  def self.generate_exp_curve(base_exp = 2)
    file = File.new(Exp_Curve_File, "w")
    code = IO.readlines(Exp_Curve_File)
    for i in 0...100
      last_exp = 1 if last_exp.nil?
      formula = base_exp + last_exp + rand(3)
      exp = [[formula, last_exp+rand(2)].max, 9999].min
      code[i] = "Level #{i+1} = #{exp}\n"
      last_exp = exp
    end
    file.write(code)
  end
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
#  Refer to "$game_temp" for the instance of this class.
#==============================================================================

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :lockpick_success
  attr_accessor :lockpick_actor
  attr_accessor :lockpick_target_level
  attr_accessor :lockpick_levelup_flag
  attr_accessor :lockpick_use
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_lock_temp_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    dargor_lock_temp_initialize
    @lockpick_success = false
    @lockpick_actor = nil
    @lockpick_target_level = 1
    @lockpick_levelup_flag = []
    @lockpick_use = 20
  end
  #--------------------------------------------------------------------------
  # * Repair Lock Pick (#use)
  #--------------------------------------------------------------------------
  def repair_lockpick(value=20)
    @lockpick_use = value
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles data surrounding the system. Backround music, etc.
#  is managed here as well. Refer to "$game_system" for the instance of 
#  this class.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :lockpick_id
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_lock_system_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    dargor_lock_system_initialize
    @lockpick_id = 33
  end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :lockpicking_level
  attr_accessor :lockpicking_level_max
  attr_accessor :lockpicking_exp
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_lock_actor_setup setup
  #--------------------------------------------------------------------------
  # * Setup
  #     actor_id : actor ID
  #--------------------------------------------------------------------------
  def setup(actor_id)
    dargor_lock_actor_setup(actor_id)
    @lockpicking_level = 1
    @lockpicking_level_max = 100
    @lockpicking_exp = read_exp
  end
  def can_lockpick?
    return (Lockpicking::Actors.include?(id) and 
      Lockpicking::Classes.include?(@class_id))
  end
  #--------------------------------------------------------------------------
  # * Lock Pick (Lock picking process)
  #--------------------------------------------------------------------------
  def lockpick
    # Store the target lock level into lock_level
    lock_level = $game_temp.lockpick_target_level
    # Succes rate formula (depends on the lock picking level type)
    if Lockpicking::Use_Actors_Level.include?(@id)
      success_rate = (@level*100)/lock_level
      @lockpicking_level = @level
    else
      success_rate = (@lockpicking_level*100)/lock_level
    end
    # If lock pick use is 0, unequip it (Used when lock pick is a RPG::Weapon)
    if $game_temp.lockpick_use == 0
      #$game_temp.lockpick_actor.equip(0, 0)
      #$game_party.lose_weapon($game_system.lockpick_id, 1)
      return
    else
      $game_temp.lockpick_use -= 1
    end
    # Success Randomization
    if rand(100) <= success_rate
      # Skip exp/level step if using actor's level instead of 
      # lock picking level
      unless Lockpicking::Use_Actors_Level.include?(@id)
        last_level = @lockpicking_level
        @lockpicking_exp = 0 if @lockpicking_exp.nil?
        @lockpicking_exp += 1
        check_lockpicking_level 
        # Check for lock picking level up
        if last_level < @lockpicking_level
          $game_temp.lockpick_levelup_flag[@actor_id] = true
        else
          $game_temp.lockpick_levelup_flag[@actor_id] = false
        end
      end
      # Success
      $game_temp.lockpick_success = true
      return
    else
      # Failure
      $game_temp.lockpick_success = false
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Read Current Lock Picking Exp
  #--------------------------------------------------------------------------
  def read_exp
    return 0 if @lockpicking_level == @lockpicking_level_max
    Lockpicking.generate_exp_curve unless FileTest.exist?(Lockpicking::Exp_Curve_File)
    file = File.open(Lockpicking::Exp_Curve_File)
    until file.eof?
      data = file.readline
      line = data.dup
      if data.include?("Level #{@lockpicking_level}")
        now_exp = line.split(' = ')
        exp = now_exp[1].to_i
        return exp
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Read Lock Picking Exp Needed For Next Level
  #--------------------------------------------------------------------------
  def exp_needed
    return if @lockpicking_level == @lockpicking_level_max
    unless FileTest.exist?(Lockpicking::Exp_Curve_File)
      Lockpicking.generate_exp_curve
    end
    next_level = @lockpicking_level+1
    file = File.open(Lockpicking::Exp_Curve_File)
    until file.eof?
      data = file.readline
      line = data.dup
      if data.include?("Level #{next_level}")
        now_exp = line.split(' = ')
        exp = now_exp[1].to_i
        return exp
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Check Lockpicking Level
  #--------------------------------------------------------------------------
  def check_lockpicking_level
    if @lockpicking_exp >= exp_needed
      @lockpicking_level += 1
    end
    return @lockpicking_level
  end
end

#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page 
#  switching via condition determinants, and running parallel process events.
#  It's used within the Game_Map class.
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :broken       # broken
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias lockpick_event_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(map_id, event)
    @broken = false
    lockpick_event_initialize(map_id, event)
  end
  #--------------------------------------------------------------------------
  # * Broken?
  #--------------------------------------------------------------------------
  def broken?
    return @broken
  end
end

#==============================================================================
# ** Window_LockLevel
#------------------------------------------------------------------------------
#  This window displays lock picking variables (User level, Target level, #use).
#==============================================================================

class Window_LockLevel < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(16,16,240,128)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 160
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    if $game_temp.lockpick_actor.nil?
      return
    end
    # Draw User Lock Picking Level
    self.contents.font.color = system_color
    self.contents.draw_text(0,0,200,32,'Lock Picking Level:')
    self.contents.font.color = normal_color
    if Lockpicking::Use_Actors_Level.include?($game_temp.lockpick_actor.id)
      lockpicking_level = $game_temp.lockpick_actor.level.to_s
      self.contents.draw_text(0,0,200,32,lockpicking_level,2)
    else
      lockpicking_level = $game_temp.lockpick_actor.lockpicking_level.to_s
      self.contents.draw_text(0,0,200,32,lockpicking_level,2)
    end
    # Draw Target Lock Level
    self.contents.font.color = system_color
    self.contents.draw_text(0,32,160,32,'Target Lock Level:')
    self.contents.font.color = normal_color
    lock_level = $game_temp.lockpick_target_level.to_s
    self.contents.draw_text(0,32,200,32,lock_level,2)
    # Draw Lock Pick #use
    self.contents.font.color = system_color
    self.contents.draw_text(0,64,160,32,'Use:')
    self.contents.font.color = normal_color
    use = $game_temp.lockpick_use.to_s
    self.contents.draw_text(0,64,200,32,use,2)
  end
end

#==============================================================================
# ** Scene_LockPick
#------------------------------------------------------------------------------
#  This class performs lock picking screen processing.
#==============================================================================

class Scene_LockPick
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(event, level, max_try=-1)
    @event = $game_map.events[event]
    $game_temp.lockpick_target_level = level
    @max_try = max_try
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @step = 0
    @spriteset = Spriteset_Map.new
    @lockpick_level = Window_LockLevel.new
    @lockpick_message = Window_Help.new
    @lockpick_message.visible = false
    @lockpick_message.y = 416
    @lockpick_message.back_opacity = 160
    @lockpick_message.pause = true
    @commands = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      @commands << actor.name if actor.can_lockpick?
    end
    @lockpick_commands = Window_Command.new(160,@commands)
    @lockpick_commands.x = 16
    @lockpick_commands.y = @lockpick_level.y + @lockpick_level.height
    @lockpick_commands.back_opacity = 160
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Refresh map
    $game_map.refresh
    # Prepare for transition
    Graphics.freeze
    @spriteset.dispose
    # Dispose of windows
    @lockpick_commands.dispose
    @lockpick_level.dispose
    @lockpick_message.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    $game_party.refresh
    @lockpick_commands.update
    @lockpick_message.update
    @lockpick_level.refresh
    $game_temp.lockpick_actor = $game_party.actors[@lockpick_commands.index]
    unless @lockpick_message.visible
      equipped_weapon = $game_temp.lockpick_actor.weapon_id 
      if Input.trigger?(Input::C) #and equipped_weapon == $game_system.lockpick_id
        $game_system.se_play($data_system.decision_se)
        $game_temp.lockpick_actor.lockpick
        unless @max_try == -1 and not @event.broken
          @max_try -= 1
          @lockpick_message.visible = true
          if @max_try == 0
            @lockpick_message.set_text('Lock broken.',1)
            @event.broken = true
            @step = 3
            return
          end
        end
        if $game_temp.lockpick_use == 0
          @lockpick_message.set_text('Lock pick used up!',1)
          @step = 3
          return
        end
        if $game_temp.lockpick_success
          @lockpick_message.set_text('Lock pick success!',1)
          key = [$game_map.map_id, @event.id, "A"]
          $game_self_switches[key] = true
          $game_map.need_refresh = true
          if $game_temp.lockpick_levelup_flag[$game_temp.lockpick_actor.id]
            @step = 1
          else
            @step = 2
          end
        else
          @lockpick_message.set_text('Lock pick failed.',1)
          @step = 3
        end
        return
      #elsif Input.trigger?(Input::C) and equipped_weapon != $game_system.lockpick_id
       # name = $game_temp.lockpick_actor.name
       # @lockpick_message.set_text("#{name} doesn't have a lock pick!",1)
       # @step = 3
      elsif Input.trigger?(Input::B)
        $game_temp.lockpick_target_level = nil
        $game_temp.lockpick_actor = nil
        $scene = Scene_Map.new
        return
      end
    else
      actor_id = $game_temp.lockpick_actor.id
      if Input.trigger?(Input::C)
        #$game_system.se_play($data_system.decision_se)
        case @step
        when 1
          name = $game_temp.lockpick_actor.name
          new_level = $game_temp.lockpick_actor.lockpicking_level
          @lockpick_message.set_text("#{name}'s lock picking raised to level #{new_level}!",1)
          $game_temp.lockpick_levelup_flag[actor_id] == false
          @step = 2
        when 2
          $scene = Scene_Map.new
          return
        when 3
          @step = 0
          @lockpick_message.visible = false
        end
      end
    end
  end
end

Instructions

Everything is explained in the script comments.
Note that the script ALWAYS activates the target's local switch A.

FAQ

None.

Compatibility

It's supposed to be compatible with everything!

Credits and Thanks

Thanks to Isopaha for requesting the script.
Moriarty for helping me with the experience curve and sharing some ideas.
Don't forget to give me credits!

Author's Notes

Enjoy!
 
Nice been watching this from the Request and been looking forward to trying it out. Good Work.

EDIT: Sweet and simple.
Few suggestions/Ideas

Be able to choose what class/actor is able to have the lockpick skill
Lockpicks be like ammo, 1 try per use
Something interactive, instead of button mashing
Locks that break if u do not get them in X amout of trys

all i have now. Great work still.
 
Isopaha;197204 said:
Yes, but the text jump to under if i chance number!

Try and make a space so that you can get all of the "lockpicking level" on one line.

If it doesn't work then.. *shrugs*
 
I see that there's still some bugs. I'll update the scriptwith your suggestions. But for now I'll concentrate myself on school. Only 2 weeks left! :D

Now I have 4 scripts to update:
Lockpicking Script
Console Script
Title Map & Intro Script
Auto-Scroll Text
 
I have a question. I would like to know if it would be possible to use this script, but only for one character(My thief) And to use their thief level as the lockpicking level.
 
I see, yeah that's a good idea. You should be able to limit this ability to the classes you want. Or to a specific character. That's not to hard of a addon.
 
it says

NAMERROR occured while running script

undefined local variable or method ' event_id' for # <interpreter:0x1446d08>


PLZ HELP!!
 
Can someone PLEASE update the leveling up part... ouch. From level 1 to level 20 and 20 to 50.

It's horrendous...

Thanks,
Moriarty
 
Let me a few days, I'm working on rewriting and updating a lot of my scripts. This one is in my priorities.

EDIT:
If you have any suggestions regarding the level up formula, feel free to share. ;)
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top