Jump to content
Sign in to follow this  
Intocabille

Primitive lockpick (and perhaps combos generally)

Recommended Posts

Hi, I am aware that there are several lockpick systems already, however I put something together as well. Maybe someone will find it usefull, especially since it should be rather easy to alter. And it doesn't work just as lockipck, I guess.
 
Cons:
Not really any immersive graphical interface, really.
 
Pros:
Can be used for more than just a simple lockpicking.
Few options to set to get more than one way how it works
Should have rather high compatability.
 
Install:
It should work with just pasting into scripts under Material and above Main
 
Usage:
The script is called as show_lockpick("code") where code is string, saying which code is needed and the function returns true or false depending on how it is set up. The code consists of letters "R", "L", "D" and "U" for right, left, down and up directions, eg "DDUL" will require the user to press those four direction keys in that direction to get true returned.
When called it will display a window (the size of the window deprends on the size of the code) and the user then presses the direction keys to create the combination, or press the key mapped to B (usually ESC key) to quit the input sequence with false value being returned.
 
Options:
You can set numbers for 4 icons that are used for each direction.
You can decide if icons or letters are displayed as user presses the direction keys.
You can decide if user is allowed to continue with input after wrong key press (eg continuing after UUD for code that us UULRURL) or if false value is returned right after first wrong key press.
You can decide what (if any) sound effect is to be played on correct and on wrong key input. (this in combination with allowing to continue will make it easier for the player, as they get to guess all keys and are hinted with the sound if it was right or not)
 

 

ICON_UP = 1    # no. of icon
ICON_DOWN = 2  # no. of icon
ICON_LEFT = 3  # no. of icon
ICON_RIGHT = 4 # no. of icon      
# The sounds = ["name", volume, pitch], if name is "", no sound is played
SE_OK = ["Audio\\SE\\Key.ogg",100,150] # sound to play after right entry
SE_KO = ["Audio\\SE\\Key.ogg",100,50]  # sound to play after wrong entry
CONTINUE = true # true = continue after wrong entry, false = stop immediately
LETTERS = false  # true = display letters, false = display icons

def show_lockpick(code)
  spacing = LETTERS ? 10 : 24 # Spacing for letters : icons (customization)
  adjust  = LETTERS ? 30 : 30  # Padding for letters : icons (customization)
  text = ""
  icons = ""
  result = false
  play = false
  pos_x = (Graphics.width-(code.length*spacing+adjust))/2
  pos_y = (Graphics.height - 60)/2
  window = Window_Base.new(pos_x, pos_y, (code.length*spacing)+adjust, 60)
  window.show.activate
  loop do
    Graphics.update
    Input.update
    if Input.trigger?(:UP)
      text += "U"
      icons += "\\i[" + ICON_UP.to_s + "]"
      play = true
    elsif Input.trigger?(:DOWN)
      text += "D"
      icons += "\\i[" +ICON_DOWN.to_s + "]"
      play = true
    elsif Input.trigger?(:LEFT)
      text += "L"
      icons += "\\i[" +ICON_LEFT.to_s + "]"
      play = true
    elsif Input.trigger?(:RIGHT)
      text += "R"
      icons += "\\i[" +ICON_RIGHT.to_s + "]"
      play = true
    elsif Input.trigger?(:
      Audio.se_play(SE_KO[0], SE_KO[1], SE_KO[2]) if (SE_KO[0]!="")
      break
    end
    window.draw_text_ex(0,5,icons) if !LETTERS
    window.draw_text_ex(0,5,text) if LETTERS
    if (text.length > 0 && text[text.length-1] != code[text.length-1])
      Audio.se_play(SE_KO[0], SE_KO[1], SE_KO[2]) if play && (SE_KO[0]!="")
      play = false
      break if !CONTINUE
    elsif (text.length > 0) && (text[text.length-1] == code[text.length-1])
      Audio.se_play(SE_OK[0], SE_OK[1], SE_OK[2]) if play && (SE_OK[0]!="")
      play = false
    end
    if text == code 
      result = true
      break
    end
    break if text.size == code.size
  end
  stop_everything(30)
  window.dispose
  return result
end

# method that will stop everything from happening for set abount of frames
def stop_everything(frames)
  frames.times { Graphics.update; Input.update}
end

 

 

Thanks:

@TheoAllen for solving a tiny bit with the loop goes BIG thanks.

@pencilcase27 for ideas for the second version of the script (see EDIT part for sleeker code)
 
Note:
The way I use it is that I create a chest and put there a condition that calls this script and if successful, then the chest is open
Also note that as it is the most likely icons used (1,2,3,4) are those of poison, death, blind and silence. :-)
 
Idea:
With @TheoAllen's help in solving a bit, you can now call it from the damage formula like this

show_lockpick(code)?damage_if_true:damage_if_false

Enabling you to create those oh so "loved" combo skills where it will ask the player to input the code and if right, damage_if_true is dealt, otherwise it deals damage_if_false to the target.
 
Idea2:
I guess further update would be to be able to pass the numbers of icons wanted in the call, that way each combo input could have it's own icons, probably useful for mixing items or skills?
 
EDIT:
With help of (and thanks to) @pencilcase27 there is a newer and moresleeker and shorter code, that also makes the sound definition prettier

 

 

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ICON_UP    = 1           # no. of icon UP                                      #
ICON_DOWN  = 2           # no. of icon DOWN                                    #
ICON_LEFT  = 3           # no. of icon LEFT                                    #
ICON_RIGHT = 4           # no. of icon RIGHT                                   #
CONTINUE   = false       # continue after wrong entry? (true/false)            #
LETTERS    = false       # show letters (true) or icons (false)                #
WAIT_TIME  = 30          # frames the game waits after end (60 frames = 1 sec) #
SE_OK = ["Key",100,150]  # sound after right entry ["name", volume, pitch]     #
SE_KO = ["Key",100, 50]  # sound after wrong entry ["name", volume, pitch]     #
                         # for no sound pleyed use ["", 0, 0]                  #
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

def show_lockpick(code)
  spacing = LETTERS ? 10 : 24 # Spacing for letters : icons (customization)
  adjust  = LETTERS ? 30 : 30 # Padding for letters : icons (customization)
  text, icons = "", ""
  pos_x = (Graphics.width-(code.length*spacing+adjust))/2
  pos_y = (Graphics.height - 60)/2
  window = Window_Base.new(pos_x, pos_y, (code.length*spacing)+adjust, 60)
  window.show.activate
  loop do
    Graphics.update
    Input.update
    if Input.trigger?(:UP)
      text += "U" and icons += "\\i[" + ICON_UP.to_s + "]"
      text[-1] == code[text.size-1] ? RPG::SE.new(*SE_OK).play : RPG::SE.new(*SE_KO).play
    elsif Input.trigger?(:DOWN)
      text += "D" and icons += "\\i[" +ICON_DOWN.to_s + "]"
      text[-1] == code[text.size-1] ? RPG::SE.new(*SE_OK).play : RPG::SE.new(*SE_KO).play
    elsif Input.trigger?(:LEFT)
      text += "L" and icons += "\\i[" +ICON_LEFT.to_s + "]"
      text[-1] == code[text.size-1] ? RPG::SE.new(*SE_OK).play : RPG::SE.new(*SE_KO).play
    elsif Input.trigger?(:RIGHT)
      text += "R" and icons += "\\i[" +ICON_RIGHT.to_s + "]"
      text[-1] == code[text.size-1] ? RPG::SE.new(*SE_OK).play : RPG::SE.new(*SE_KO).play
    elsif Input.trigger?(:
      RPG::SE.new(*SE_KO).play
      break
    end
    LETTERS ? window.draw_text_ex(0,5,text) : window.draw_text_ex(0,5,icons)
    break if (text.length > 0 && text[-1] != code[text.length-1]) && !CONTINUE
    break if text.size == code.size
  end
  WAIT_TIME.times { Graphics.update; Input.update}
  window.dispose
  return text == code
end

 

 

Usage is till the same

Edited by Intocabille

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted