RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Wordlocks [Betrayal at Krondor]

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Wordlocks
Version: 1.0
Author: modern algebra
Date: January 18, 2010

Version History


  • <Version 1.0> 01.18.2010 - Original Release

Description


This script allows you to create chests or doors that are locked by riddles, and that will only open if the player gets the correct answer to it. You can put it in an event - the correct answer will turn on a self-switch in the event, and thus you can have any number of goodies hidden inside, controlled entirely by eventing. It is based on the Moredhel Wordlocks from Betrayal at Krondor and is very similar.

Features

  • Allows you to create locks that can only be opened if the player gets the answer to the riddle
  • Makes for a really fun minigame
  • Very easy to set up! You use a comment, so there's no fumbling trying to fit long sentences into a script call and it's all handled inside the event so no complicated database setting up in the editor.
  • Turns on a self-switch when completed, so you control what happens after completely with events.
  • The best part of Betrayal at Krondor :P That's a lie. All of Betrayal at Krondor is the best part of Betrayal at Krondor

Instructions

For instructions, please see the header of the script.

Script


The Paragraph Formatter with Special Codes Paragrapher are recommended and included with the demo. It is not, however, required.

I would recommend downloading the demo anyway, so you can see how the chest events are set up.

Code: [Select]
#==============================================================================
#    Wordlocks
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: January 18, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to create chests or doors that are locked by
#   riddles, and that will only open if the player gets the correct answer to
#   it. You can put it in an event - the correct answer will turn on a self-
#   switch in the event, and thus you can have any number of goodies hidden
#   inside, controlled entirely by eventing. It is based on the Moredhel
#   Wordlocks from Betrayal at Krondor and is very similar.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place this script into its own slot in the Script Editor (F11) below the
#   default scripts and above Main. The Paragraph Formatter and Special Codes
#   Formatter is RECOMMENDED (though not required).
#
#    Then, go down to the EDITABLE REGION at line 102 and configure those things
#   to your liking; detailed instructions on what each option does is located
#   in the comments directly above each one. Keep in mind the code for changing
#   those values in game.
#
#    Now, to set up a new chest, you need to do two things. Wherever it is that
#   you want the chest to open in the course of the event, you need to put this
#   code in a call script event command:
#      call_wordlock
#
#   Directly below that call script, you MUST place a comment, which is where
#  you specify what the riddle, answer, and possible letters. To do so, you
#  must write in all of the following in the comment:
#
#    RIDDLE: This is the riddle itself. You need to put it within a bbcode-like
#      format: [RIDDLE]text[/RIDDLE]. If you are using the paragraph formatter,
#      you can write it as an unbroken string like this:
#        [riddle]This is the riddle and it can be longer[/riddle]
#
#      If you are not using the paragraph formatter, you need to break it into
#      lines with [L][/L] yourself like the following:
#        [RIDDLE][L]This is Line 1[/l][l]This is line 2[/L]etc...[/riddle]
#
#    ANSWER: This is where you put the exact answer to the question, again in
#      the BBCode like format with [ANSWER]text[/ANSWER]. All of the text must
#      be letters A-Z, nothing else.
#
#    KEY: This is the "Answer Key" - it's really just an array that says what
#      the potential choices for each letter of the answer are. It's a little
#      hard to describe so I'll go straight into the example. To set it up,
#      you have to use [KEY]<ABCD>, <ABCD>, ..., <ABCD>[/key]. For each letter of
#      the answer, you must have one <>, and inside that, the ABCD are the
#      potential answers to it. If you do not include the correct letter, the
#      script will do so automatically.
#
#  EXAMPLE::
#  @>Script: call_wordlock
#  @>Comment:[riddle][l]He gets short when he gets old.[/l][l]He
#   :       :goes out when it gets cold.[/l][/riddle]
#   :       :[answer]CANDLE[/answer]
#   :       :[key]<ACQR>, <DJAU>, <NXID>, <PEID>, <LWFC>, <YNME>
#   :       :[/key]
#
#  This is assuming that a paragraph formatter is not being used, so the above
# has the riddle split into two lines. It will show up as:
#      He gets short when he gets old.
#      He goes out when it gets cold.
#
#  The Answer would have as options:
#      A  D  N  P  L  Y
#      C  J  X  E  W  N
#      Q  A  I  I  F  M
#      R  U  D  D  C  E
#
#  The chest would open when the player spelled out:
#      C  A  N  D  L  E
#
#  When the player gets the correct answer, it turns on the A self-switch of
# the event that called the chest. It's up to you what to do from there!
#==============================================================================

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new constants - WL_CHEST_BG; WL_LETTER_BG; WL_FONTNAME; WL_FONTCOLOR;
#      WL_ANSWER_RECT; WL_RIDDLE_RECT; WL_CHEST_OPEN; WL_LETTER_SE;
#      WL_UNLOCK_SE; WL_UNLOCK_WAIT_FRAMES; WL_SELF_SWITCH;
#      WL_PARAGRAPH_FORMATTER; WL_PARAGRAPH_ARTIST
#    new public instance variables - wl_chest_bg, wl_letter_bg, wl_font_name,
#      wl_font_color, wl_chest_open, wl_answer_rect, wl_riddle_rect,
#      wl_letter_se, wl_inlock_se
#    aliased method - initialize
#==============================================================================

class Game_System
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  # * CONSTANTS
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  #  EDITABLE REGION
  #````````````````````````````````````````````````````````````````````````````
  # The name of the background graphic for the scene. It can be changed
  #  in-game with the code:
  #    $game_system.wl_chest_bg = ""
  WL_CHEST_LOCKED = "Chest"
  # The name of the graphic to replace WL_CHEST_LOCKED once the chest has been
  #  opened. It can be changed in-game with the code:
  #    $game_system.wl_chest_open = ""
  WL_CHEST_OPEN = "Chest Open"
  # The name of the graphic to serve as the frame for each letter of the
  #  answer. Depending on your windowskin, the cursor may not be big enough to
  #  show over the frame. In that case, I would suggest you make the image
  #  slightly transparent so that you can tell which letter the cursor is over.
  #  It can be changed in-game with the code:
  #    $game_system.wl_letter_bg = ""
  WL_LETTER_BG = "LetterFrame"
  # The name of the font to be used in this scene. It can be either a string or
  #  a prioritized array of the form:
  #    ["fontname_1", "fontname_2", ..., "fontname_n"]
  #  where, if fontname_1 is installed, it would be used, otherwise fontname_2
  # and so on until fontname_n. It can be changed in-game with the code:
  #    $game_system.wl_font_name = []
  WL_FONTNAME = ["Narkisim", "Verdana", "Arial", "Times New Roman"]
  # THe colour of the font to be used. This can either be an index
  #  corresponding to the windowskin palette, or it can be an array:
  #    [red, green, blue, alpha]
  #  Where all are between 0-255. alpha is the opacity, and if not included
  # defaults to 255. It can be changed in-game with the code:
  #    $game_system.wl_font_color = []
  WL_FONTCOLOR = 15
  # This is where, on the picture, the letter boxes should appear. It will
  #  centre within these boundaries, and can be either an array or a Rect:
  #     [x, y, width, height]
  #     Rect.new (x, y, width, height)
  #
  #  It can be changed in-game with the code:
  #    $game_system.wl_answer_rect = []
  WL_ANSWER_RECT = [128, 192, 288, 32]
  # This is where, on the picture, the riddle text should appear. It will
  #  centre within these boundaries unless you are using the paragraph
  #  formatter. It can be set up either as an array or a Rect:
  #     [x, y, width, height]
  #     Rect.new (x, y, width, height)
  #
  #  It can be changed in-game with the code:
  #    $game_system.wl_riddle_rect = []
  WL_RIDDLE_RECT = [96, 240, 352, 128]
  # The SE to be played upon changing letter. It is in the format:
  #    ["SE name", volume, pitch]
  # It can be changed in game by the code:
  #    $game_system.wl_letter_se = ["SE name", volume, pitch]
  WL_LETTER_SE = ["Cursor"]
  # The SE to be played upon getting the correct answer. It is in the format:
  #    ["SE name", volume, pitch]
  # It can be changed in game by the code:
  #    $game_system.wl_unlock_se = ["SE name", volume, pitch]
  WL_UNLOCK_SE = ["Open3", 100, 100]
  # The number of frames to wait before exiting the scene after getting the
  #  correct answer. 1 second = 60 frames
  WL_UNLOCK_WAIT_FRAMES = 60
  # The Self-Switch to be turned on upon a correct answer. This is to tell the
  #  event that the box has been opened.
  WL_SELF_SWITCH = "A"
  # IF using the paragraph formatter (which is not required), you can specify
  #  which formatter and artist class you'd like to use. The SpecialCodes
  #  formatters it is defaulted to are special formatters that recognize a
  #  number of message codes such as \c[x] and \v[x], etc... If you wish to
  #  use the regular formatters, remove _SpecialCodes from each
  WL_PARAGRAPH_FORMATTER = Paragrapher::Formatter_SpecialCodes
  WL_PARAGRAPH_ARTIST = Paragrapher::Artist_SpecialCodes
  #````````````````````````````````````````````````````````````````````````````
  #  END EDITABLE REGION
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :wl_chest_bg    # Name of System graphic for Chest
  attr_accessor :wl_chest_open  # Name of system graphic for unlocked chest
  attr_accessor :wl_letter_bg   # Name of System graphic for letter background
  attr_accessor :wl_font_name   # Name of font used for Riddle Chest
  attr_accessor :wl_font_color  # Color of font used for Riddle Chest
  attr_accessor :wl_answer_rect # Rect for the Answer
  attr_accessor :wl_riddle_rect # Rect for riddle size
  attr_accessor :wl_letter_se   # The SE played when changing letters.
  attr_accessor :wl_unlock_se   # The SE played when unlocking
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_rdlchst_init_grphc_3wq1 initialize
  def initialize (*args)
    ma_rdlchst_init_grphc_3wq1 (*args)
    @wl_chest_bg = WL_CHEST_LOCKED
    @wl_chest_open = WL_CHEST_OPEN
    @wl_letter_bg = WL_LETTER_BG
    @wl_font_name = WL_FONTNAME
    # Put color in array if windowskin color
    if WL_FONTCOLOR.is_a? (Integer)
      x, y = 64 + (WL_FONTCOLOR % 8) * 8,  96 + (WL_FONTCOLOR / 8) * 8
      color = Cache.system ("Window").get_pixel(x, y)
      @wl_font_color = [color.red, color.green, color.blue, color.alpha]
    else
      @wl_font_color = WL_FONTCOLOR
    end
    @wl_answer_rect = WL_ANSWER_RECT.is_a? (Array) ? Rect.new (*WL_ANSWER_RECT) : WL_ANSWER_RECT
    @wl_riddle_rect = WL_RIDDLE_RECT.is_a? (Array) ? Rect.new (*WL_RIDDLE_RECT) : WL_RIDDLE_RECT
    @wl_letter_se = WL_LETTER_SE
    @wl_unlock_se = WL_UNLOCK_SE
  end
end

#==============================================================================
# ** Game Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - call_wordlock
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Call Riddle Chest
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def call_wordlock
    # Retrieve comments
    i = @index + 1
    return if @list.size <= i
    comment = ""
    while [108, 408].include? (@list[i].code)
      comment += @list[i].parameters[0]
      i += 1
      break if @list.size <= i
    end
    comment[/\[RIDDLE\](.+?)\[\/RIDDLE\]/i]
    riddle = $1.to_s
    r2 = riddle.dup
    riddle_a = []
    while r2.slice! (/\[L\](.+?)\[\/L\]/i) != nil
      riddle_a.push ($1.to_s)
    end
    riddle = riddle_a if !riddle_a.empty?
    comment[/\[ANSWER\](.+?)\[\/ANSWER\]/i]
    answer = $1.to_s.upcase
    comment[/\[KEY\](.+?)\[\/KEY\]/i]
    key_s = $1.to_s
    key_a = []
    while key_s.slice! (/<(\w+?)>/i) != nil
      chain = $1.to_s.upcase
      letters = chain.scan (/./)
      key_a.push (letters)
    end
    $scene = Scene_RiddleChest.new (@event_id, riddle, answer, key_a)
  end
end

#==============================================================================
# ** Sprite_Riddle
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  This sprite shows the riddle
#==============================================================================

class Sprite_Riddle < Sprite_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initializaiton
  #    letters : the array of letter this can show
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def initialize (riddle)
    super ()
    self.x, self.y = $game_system.wl_riddle_rect.x, $game_system.wl_riddle_rect.y
    self.z += 20
    self.bitmap = Bitmap.new ($game_system.wl_riddle_rect.width, $game_system.wl_riddle_rect.height)
    self.bitmap.font.name = $game_system.wl_font_name
    self.bitmap.font.color = Color.new (*$game_system.wl_font_color)
    refresh (riddle)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Refresh
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def refresh (riddle)
    self.bitmap.clear
    wlh = Window_Base::WLH
    if riddle.is_a? (Array)
      y = (self.bitmap.height - riddle.size*wlh) / 2
      for line in riddle
        self.bitmap.draw_text (0, y, self.bitmap.width, wlh, line, 1)
        y += wlh
      end
    else
      if self.bitmap.methods.include? ("draw_paragraph")
        self.bitmap.paragraph_formatter = Game_System::WL_PARAGRAPH_FORMATTER
        self.bitmap.paragraph_artist = Game_System::WL_PARAGRAPH_ARTIST
        self.bitmap.draw_paragraph (0, 0, self.bitmap.width, self.bitmap.height, riddle)
      else
        self.bitmap.draw_text (0, (self.bitmap.height - wlh) / 2, self.bitmap.width, wlh, riddle, 1)
      end
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Dispose
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def dispose (*args)
    self.bitmap.dispose
    super (*args)
  end
end

#==============================================================================
# ** Window_RiddleAnswer
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  This window displays the letters for the answer
#==============================================================================

class Window_RiddleAnswer < Window_Selectable
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def initialize (letters, answer_key)
    @letters, @answer_key = letters, answer_key
    rect = $game_system.wl_answer_rect
    super (rect.x - 16, rect.y - 16, rect.width + 32, rect.height + 32)
    self.z += 20
    self.opacity = 0
    self.contents.font.name = $game_system.wl_font_name
    self.contents.font.color = Color.new (*$game_system.wl_font_color)
    @item_max = @column_max = answer_key.size
    bmp = Cache.system ($game_system.wl_letter_bg)
    x_room = rect.width - (@answer_key.size*bmp.width)
    @spacing = [(x_room / (@answer_key.size - 1)), 6].min
    @start_x = (x_room - (@spacing*(@answer_key.size - 1))) / 2
    @contents_y = (contents.height - bmp.height) / 2
    @indices = []
    for i in 0...@letters.size do @indices[i] = 0 end
    refresh
    self.index = 0
    self.active = true
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Refresh
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Item Rect
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def item_rect (index)
    bmp = Cache.system ($game_system.wl_letter_bg)
    x = @start_x + index*(bmp.width + @spacing)
    return Rect.new (x - 1, @contents_y - 1, bmp.width + 2, bmp.height + 2)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Draw Item
  #    index : the letter frame to draw
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def draw_item (index)
    rect = item_rect (index)
    contents.clear_rect (rect)
    bmp = Cache.system ($game_system.wl_letter_bg)
    contents.blt (rect.x + 1, @contents_y, bmp, bmp.rect)
    contents.draw_text (rect, @letters[index][@indices[index]], 1)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def update
    super
    if Input.trigger? (Input::UP)
      Sound.play_cursor
      @indices[@index] = (@indices[@index] - 1) % @letters[@index].size
      draw_item (@index)
    elsif Input.trigger? (Input::DOWN)
      Sound.play_cursor
      @indices[@index] = (@indices[@index] + 1) % @letters[@index].size
      draw_item (@index)
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Correct?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def correct?
    return @indices == @answer_key
  end
end

#==============================================================================
# ** Scene_RiddleChest
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  This scene handles processing for opening a riddle chest
#==============================================================================

class Scene_RiddleChest < Scene_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def initialize (event_id, riddle, answer, letters = [])
    @event_id = event_id
    @riddle = riddle
    @answer_key = []
    # If the letters are messed up, fix:
    if letters.size != answer.size
      @letters = []
      for i in 0...answer.size
        @letters[i] = []
        all_letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N',
                       'O','P','Q','R','S','T','U','V','W','X','Y','Z']
        all_letters.delete (answer[i, 1])
        k = rand (4)
        @answer_key.push (k)
        for j in 0...4
          if j == k
            @letters[i][j] = answer[i, 1]
          else
            @letters[i][j] = all_letters[rand (all_letters.size)]
            all_letters.delete (@letters[i][j])
          end
        end
      end
    else
      @letters = letters
      # Make sure correct letter included
      @letters.each_index { |id| @letters[id] |= [answer[id, 1]] }
      # Get Answer Key
      for i in 0...answer.size
        for j in 0...@letters[i].size
          if @letters[i][j] == answer[i, 1]
            @answer_key[i] = j
            break
          end
        end
      end
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Start processing
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def start
    super
    # Create Background Sprite
    @bg_sprite = Sprite_Base.new
    @bg_sprite.bitmap = Cache.system ($game_system.wl_chest_bg)
    # Create Letter Sprites
    @answer_window = Window_RiddleAnswer.new (@letters, @answer_key)
    # Create Riddle Sprite
    @riddle_sprite = Sprite_Riddle.new (@riddle)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Termination Processing
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def terminate
    super
    @bg_sprite.dispose
    @answer_window.dispose
    @riddle_sprite.dispose
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def update
    super
    if Input.trigger? (Input::B) # If ESC pressed
      Sound.play_cancel
      $scene = Scene_Map.new
    else
      @answer_window.update
      if @answer_window.correct?
        RPG::SE.new (*$game_system.wl_unlock_se).play
        @bg_sprite.bitmap = Cache.system ($game_system.wl_chest_open)
        # Wait a little
        for i in 0...Game_System::WL_UNLOCK_WAIT_FRAMES
          Graphics.update
        end
        # Set the Self-Switch
        $game_self_switches[[$game_map.map_id, @event_id, Game_System::WL_SELF_SWITCH]] = true
        $scene = Scene_Map.new
      end
    end
  end
end

Addons

Spoiler for Fade to Open Graphic:
This addon makes it so that the closed graphic fades into the unlocked graphic, rather than abruptly changing.

Code: [Select]
#==============================================================================
#    Fade to Open Graphic
#      (Addon to Wordlocks 1.0)
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: January 19, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This addon to the Wordlock script makes it so that the change from the
#   locked graphic to the unlocked graphic is less sudden by fading into it.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place this script in its own slot below the Wordlock script but still
#   above Main. That's all there is to it.
#==============================================================================

#==============================================================================
# ** Scene_RiddleChest
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    overwritten method - update
#==============================================================================

class Scene_RiddleChest
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def update
    super
    if Input.trigger? (Input::B) # If ESC pressed
      Sound.play_cancel
      $scene = Scene_Map.new
    else
      @answer_window.update
      if @answer_window.correct?
        RPG::SE.new (*$game_system.wl_unlock_se).play
        fade_bg = Sprite_Base.new
        fade_bg.bitmap = @bg_sprite.bitmap
        fade_bg.z = @bg_sprite.z + 10
        @bg_sprite.bitmap = Cache.system ($game_system.wl_chest_open)
        fade_increment = 255 / ([Game_System::WL_UNLOCK_WAIT_FRAMES / 2, 40].min)
        # Wait a little
        for i in 0...Game_System::WL_UNLOCK_WAIT_FRAMES
          fade_bg.opacity -= fade_increment unless fade_bg.opacity <= 0
          Graphics.update
        end
        fade_bg.dispose
        # Set the Self-Switch
        $game_self_switches[[$game_map.map_id, @event_id, Game_System::WL_SELF_SWITCH]] = true
        $scene = Scene_Map.new
      end
    end
  end
end

Credit


  • modern algebra

Thanks

  • Betrayal at Krondor
  • Deity, for the idea of using comments to set up complicated call scripts

Support


Please post in this topic at rmrk.net for bug reporting or if you have suggestions. Please do not PM me; I'll ignore you and think poorly of you. You'll be the douchebag who PMed me instead of asked in the topic. Once you're him/her, you will never be redeemed.

Demo


Download Demo

Note that the graphics included are from Betrayal at Krondor and likely you do not have license to use them in your game. Please do your best to create or find graphics that you are allowed to use.

Graphics

grafikal has kindly created some excellent graphics for use with this script! Download them here.
For these, I recommend that you change the position settings a little bit The following appeared to look good for me:
Code: [Select]
  WL_ANSWER_RECT = [128, 96, 320, 32]
  WL_RIDDLE_RECT = [160, 200, 256, 192]
I would also recommend using the Fade to Open addon and changing the font color to something other than black. You may use them in your game, but you need to credit grafikal.


Author's Notes


I love Betrayal at Krondor. You should too!

Also, I would really like someone to make default graphics for this script. The Betrayal at Krondor ones are great, but it's probably copyright infringement so people aren't allowed to use them.


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
« Last Edit: November 15, 2014, 04:40:27 AM by modern algebra »

**
Rep:
Level 82
hey, WOW nice script, hope some graphic artists come along and see this, would make a killer attachment to an asassin game or even something like fallout.

**
Rep: +0/-0Level 82
A Good name for a Game?
That's really awesome. It would suck if your not good at Riddles (Like me).

I couldn't get the Demo to work, It open up the window and then closes it again.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
That's strange. I just downloaded it and tried it myself and everything worked fine.

Did you modify anything in the demo?

**
Rep: +0/-0Level 82
A Good name for a Game?
No, I just downloaded it and went directly to Game.exe

****
Rep:
Level 84
3...2...1...
Demo worked fine for me.  Awesome script by the way.  Will definitely use this.

**
Rep:
Level 82
Now this is cool! I'm a big fan of Raymond Feist in the first place, and BAK is no exception. Excellent job!  ;D
Current Projects:
* Ars Mechanicum 1: Genesis (RMVX)
* The Gladiator Project (RMXP)

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Thanks, and yeah; I used to love Raymond E. Feist novels, and Betrayal at Krondor is my favourite game of all time.

@Hepaticide: I don't know what to say. It seems it's working for other people. Can you try uploading your version of the demo (attach it to your post) - I'll take a look.

**
Rep: +0/-0Level 82
A Good name for a Game?
I got it to work after I installed the script on my own.

****
Rep:
Level 84
3...2...1...
So it's got the two pictures with the chest locked and the chest unlocked.  When you enter the riddle right, it changes pictures.  Can I make it so that it will fade into the other picture so it isn't so sudden?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Sure. Put this in its own slot below the Wordlock script:

Code: [Select]
#==============================================================================
#    Fade to Open Graphic
#      (Addon to Wordlocks 1.0)
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: January 19, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This addon to the Wordlock script makes it so that the change from the
#   locked graphic to the unlocked graphic is less sudden by fading into it.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place this script in its own slot below the Wordlock script but still
#   above Main. That's all there is to it.
#==============================================================================

#==============================================================================
# ** Scene_RiddleChest
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    overwritten method - update
#==============================================================================

class Scene_RiddleChest
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def update
    super
    if Input.trigger? (Input::B) # If ESC pressed
      Sound.play_cancel
      $scene = Scene_Map.new
    else
      @answer_window.update
      if @answer_window.correct?
        RPG::SE.new (*$game_system.wl_unlock_se).play
        fade_bg = Sprite_Base.new
        fade_bg.bitmap = @bg_sprite.bitmap
        fade_bg.z = @bg_sprite.z + 10
        @bg_sprite.bitmap = Cache.system ($game_system.wl_chest_open)
        fade_increment = 255 / ([Game_System::WL_UNLOCK_WAIT_FRAMES / 2, 40].min)
        # Wait a little
        for i in 0...Game_System::WL_UNLOCK_WAIT_FRAMES
          fade_bg.opacity -= fade_increment unless fade_bg.opacity <= 0
          Graphics.update
        end
        fade_bg.dispose
        # Set the Self-Switch
        $game_self_switches[[$game_map.map_id, @event_id, Game_System::WL_SELF_SWITCH]] = true
        $scene = Scene_Map.new
      end
    end
  end
end
« Last Edit: January 19, 2010, 11:21:12 PM by modern algebra »

****
Rep:
Level 84
3...2...1...
Wow, thanks.  Works great.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
grafikal has kindly created some excellent graphics for use with this script! Download them here.

For these, I recommend that you change the position settings a little bit The following appeared to look good for me:
Code: [Select]
  WL_ANSWER_RECT = [128, 96, 320, 32]
  WL_RIDDLE_RECT = [160, 200, 256, 192]
I would also recommend using the Fade to Open addon and changing the font color to something other than black. You may use them in your game, but you need to credit grafikal.

***
Rep:
Level 69
RMRK Junior
I C+P right from the demo into my game to see if it would work..  getting an error

Script'Cache' line 75: Type Error Occurred
cannot convert nil into string


Can someone help?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
And the demo does work?

You'd certainly need graphics for it, but if that were all it was it should give a different error. I can't imagine why that particular error would occur unless you set one of the graphic constants to nil. Anyway, upload the project in which the error occurs (or recreate the error in a separate project if you don't feel comfortable sharing your main project) and I will take a look. You can upload it either as an attachment to your post or on an uploading site like sendspace.

***
Rep:
Level 69
RMRK Junior
Well, I didn't want to show anyone the game until I was completely satisfied with it.. however, upon making a new map and a new game file the Wordlock worked, the only thing I can say is possibly switches or variables are on? Is it possible to send it to just you through PM?  I don't mind if you play through it too and give me some feedback, but I don't want others seeing it just yet..

****
Rep:
Level 69
When in doubt, copy over your exact game into another (don't change it from [file]-copy because it will F it up)and rip it out your game. Start fresh and just add it again, if it messes up again then freak out :O

***
Rep:
Level 69
RMRK Junior
 :P

I already did that. And it still doesnt work.  Which is silly, because it works if I play a new game..  I made a rar file of the game for you, Modern Algebra, Save File 1 puts you right in front of the chest im using.  The world map is taken out of the game, but maybe you can work from there..  I really appreciate your help.  The file is like 600 MBs, Is there anyway to compress it?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Oh, you're using an old save file (a save file from before you installed the script)? The script wasn't written to work with old save files and that is why it isn't working here - the script initializes all of that stuff when you start a new game, so those variables aren't initialized in your old save file.

If you want to keep the old save file, you can do this:

In the map wherever your save file is, make a new parallel process event without a trigger. In it, you need to make two script calls. The first should be (exactly):

Code: [Select]
s = $game_system
s.wl_chest_bg = Game_System::WL_CHEST_BG
s.wl_chest_open = Game_System::WL_CHEST_OPEN
s.wl_letter_bg = Game_System::WL_LETTER_BG
s.wl_font_name = Game_System::WL_FONT_NAME
s.wl_font_color = Game_System::WL_FONT_COLOR
s.wl_answer_rect =
  Game_System::WL_ANSWER_RECT
s.wl_riddle_rect =
  Game_System::WL_RIDDLE_RECT
s.wl_letter_se = Game_System::WL_LETTER_SE

The second should be:

Code: [Select]
s = $game_system
s.wl_unlock_se = Game_System::WL_UNLOCK_SE

After that, you should turn on a self-switch and make the second page of the event blank and conditional on that self-switch.

Once you have done that, the wordlocks should now work. Save your game, exit and delete that event from your game.

***
Rep:
Level 69
RMRK Junior
Thank you very much, I'll try it later.  Does that mean that I will have to do this common event call everytime I want to put a wordlock treasure chest in the game?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
No - you only need to do it the once for each of your old save files. Once they are initialized, you don't need to do it again.

***
Rep:
Level 69
RMRK Junior
I'm still new at this, I'm not exactly sure where script line goes, and basically what I did was this and it's 100% not working = instant crash.

This is what my event looks like, I didn't put any Script into the editor.

 I used the button named script and typed:


@>Script: s = $game_system
s.wl_chest_bg = Game_System::WL_CHEST_BG
s.wl_chest_open = Game_System::WL_CHEST_OPEN
s.wl_letter_bg = Game_System::WL_LETTER_BG
s.wl_font_name = Game_System::WL_FONT_NAME
s.wl_font_color = Game_System::WL_FONT_COLOR
s.wl_answer_rect =
  Game_System::WL_ANSWER_RECT
s.wl_riddle_rect = 
  Game_System::WL_RIDDLE_RECT
s.wl_letter_se = Game_System::WL_LETTER_SE:

@>Script:  s=$game_system
:           :  s.wl_unlock_se = Game_System::WL_UNLOCK_SE
@>Control Self Switch: A =ON


Then the event with Switch A=On is nothing.  Sorry, that I ask so many questions..


***
Rep:
Level 69
RMRK Junior
The error I'm getting:

NameError occurred while running script.

uninitialized constant Game_System::WL_CHEST_BG

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Alright. Sorry, I didn't think that the constant names would be different from the instance variable names. It should be this instead:

@>Script: s = $game_system
s.wl_chest_bg = Game_System::WL_CHEST_LOCKED
s.wl_chest_open = Game_System::WL_CHEST_OPEN
s.wl_letter_bg = Game_System::WL_LETTER_BG
s.wl_font_name = Game_System::WL_FONTNAME
s.wl_font_color = Game_System::WL_FONTCOLOR
s.wl_answer_rect =
  Game_System::WL_ANSWER_RECT
s.wl_riddle_rect = 
  Game_System::WL_RIDDLE_RECT
s.wl_letter_se = Game_System::WL_LETTER_SE
@>Script:  s=$game_system
:           :  s.wl_unlock_se = Game_System::WL_UNLOCK_SE
@>Control Self Switch: A =ON

If you get any more errors like that, just check the constants at the beginning of the script and make sure they match up with the constants you use in the above event.

***
Rep:
Level 69
RMRK Junior
Ok, I put the new script in and now:

The game no longer crashes when I enter the room, however, when I go to use the chest:

Script 'Wordlocks' line 320: NoMethodError occurred.

undefined method 'x' for [128,192,288,32]:Array


>,<  I'm sorry for being such a pain.  I need to learn this language soon..