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.
Dargor;228710 said:
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. ;)

Well....
No, not really... I have no idea what the formula actually is... I'm no RGSS scripter...
I do PHP, but not RGSS... lol

If you could point out which part is for leveling up, I'd be willing to TRY an think of a better way to do it... But, like I said... I'm no RGSS scripter.

-Moriarty
 
I finally got a good leveling up formula.
It's confusing as heck, but whatever...

Find:
Code:
  # I know the leveling "formula" is horrible
  def check_lockpicking_level
    case @lockpicking_exp
    when 0...19
      return 1
    when 20...39
      return 20
    when 40...59
      return 50
    when 60...79
      return 75
    when 80...100
      return 100
    else
      return 1
    end
  end

Replace With:
Code:
  # Updated Formula by Belak51
  def check_lockpicking_level
    if @lockpicking_exp == nil
      return 1
    else
      loopNum = 1
      while loopNum <= 100
        exp_lvl = (loopNum*(loopNum-1))*10..((loopNum*(loopNum+1))*10)-1
        exp_lvl.each { |x| return loopNum if @lockpicking_exp == x}
        loopNum = loopNum + 1
      end
    end
  end

It took me ages to do, but I finally got it working... I hate Ruby... I'm used to PHP... :p
So, here's the answer to your ;)

Cheers :thumb: ,
Moriarty AKA Belak51

EDIT:
Sorry for the DP
 
SCRIPT UPDATED!
See first post for more informations.


@Moriarty

That's an interesting way to do it. I tried it and it worked fine. But I came up with an other way, using .rxdata file. The new version of the script automatically generates a .rxdata file in which it reads the experience curve.

Thanks for the help!;)
 
Yeah. No problem... I like my way better, though... lol.
I think I'll stick with my way...

But still, seeing as I didn't know anything about RGSS other than how to put them into a game when I wrote it, I 'd say I did kinda good... lol.

-Moriarty

EDIT: Never mind... you added a new function (sigh). Looks like I'll update anyway...
EDIT 2: This is weird... It only shows the first 2 characters... does this script work with SDK, or could that be what's causing it...?
Also, when I try to pick the lock, I get an error...
"Script 'LockPick' line 166: NoMethodError occurred.
undefined method `+' for nil:NilClass"
EDIT 3: I guess the problem isn't SDK... the EXP curve doesn't generate... when I open the game the first time, I get
"Script 'LockPick' line 38: NoMethodError occurred.
undefined method `echo' for Lockpicking:Module"
It also generates an empty Lockpick_Exp_Curve.rxdata
EDIT 4: All fixed. Thanks for your help.
 
I did a minor change.
You now have to call the scene using
Code:
$scene = Scene_LockPick.new(event_id, lock _level, max_try)
instead of
Code:
$scene = Scene_LockPick.new($game_map.events[event_id], lock _level, max_try)

Thanks Moriarty;)
 
Well, if anyone's interested, you can use my EXP curve...

Code:
#==============================================================================
# ** Lock Pick System
#------------------------------------------------------------------------------
#  Author: Dargor
#  Edits: Belak51
#  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]
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 = check_lockpicking_level
    @lockpicking_level_max = 100
    @lockpicking_exp = 0
  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 += 20
        @lockpicking_level = 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
  # Change lockpicking level
  # Updated by Belak51
  def check_lockpicking_level
    if @lockpicking_exp == nil
      return 1
    else
      loopNum = 1
      while loopNum <= 100
        exp_lvl = (loopNum*(loopNum-1))*10..((loopNum*(loopNum+1))*10)-1
        exp_lvl.each { |x| return loopNum if @lockpicking_exp == x}
        loopNum = loopNum + 1
      end
    end
  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

Cheers!

-Belak51:thumb:
 

vrdi

Member

Y'know, I have somehting that functions better than this and all i need is a few events and some variables!
 
I have an error with both Moriarity's and Dargor's Script:
When I use an Event (event = $game_map.events[1]
$scene = Scene_LockPick.new(event, 2, -1)
It well show an error saying:
Script 'LockPick System' line 343: NoMethodError occured.
undefined method 'broken' for nil:NilClass
 
Sorry, I don't support this script anymore, and besides that, it's been more than a year since the last post.
Don't necropost.

Thank you.
-Dargor
 
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