Author Topic: Wordlocks [Betrayal at Krondor]  (Read 2185 times)

0 Members and 1 Guest are viewing this topic.
modern algebra Male
*
Rep: +336/-113
Online Online
Level 79 (49%)
Wordlocks [Betrayal at Krondor]
« on: January 18, 2010, 02:25:59 PM »

  • 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

    Screenshots


    Remarkable similarity to Betrayal at Krondor. Copyrighted? Almost definitely!


    Success!

    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: February 11, 2010, 04:33:48 PM by Modern Algebra »


    djunlogical Male
    **
    Rep: +1/-1
    Offline Offline
    Level 52 (83%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #1 on: January 18, 2010, 05:20:46 PM »

  • 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.
    Hepaticade Male
    **
    Rep: +0/-0
    Offline Offline
    Level 52 (20%)
    A Good name for a Game?
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #2 on: January 18, 2010, 05:44:17 PM »

  • 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.
    modern algebra Male
    *
    Rep: +336/-113
    Online Online
    Level 79 (49%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #3 on: January 18, 2010, 06:28:19 PM »

  • That's strange. I just downloaded it and tried it myself and everything worked fine.

    Did you modify anything in the demo?


    Hepaticade Male
    **
    Rep: +0/-0
    Offline Offline
    Level 52 (20%)
    A Good name for a Game?
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #4 on: January 18, 2010, 07:38:13 PM »

  • No, I just downloaded it and went directly to Game.exe
    DarkCodeZero
    ***
    Rep: +1/-0
    Offline Offline
    Level 55 (91%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #5 on: January 18, 2010, 07:47:29 PM »

  • Demo worked fine for me.  Awesome script by the way.  Will definitely use this.
    CompanionWulf
    **
    Rep: +0/-0
    Offline Offline
    Level 52 (14%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #6 on: January 19, 2010, 10:37:50 AM »

  • 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 Project: Ars Magica 1: Genesis
    modern algebra Male
    *
    Rep: +336/-113
    Online Online
    Level 79 (49%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #7 on: January 19, 2010, 10:41:28 AM »

  • 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.


    Hepaticade Male
    **
    Rep: +0/-0
    Offline Offline
    Level 52 (20%)
    A Good name for a Game?
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #8 on: January 19, 2010, 12:58:11 PM »

  • I got it to work after I installed the script on my own.
    DarkCodeZero
    ***
    Rep: +1/-0
    Offline Offline
    Level 55 (91%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #9 on: January 19, 2010, 05:35:34 PM »

  • 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?
    modern algebra Male
    *
    Rep: +336/-113
    Online Online
    Level 79 (49%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #10 on: January 19, 2010, 06:14:13 PM »

  • 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, 06:21:12 PM by modern algebra »


    DarkCodeZero
    ***
    Rep: +1/-0
    Offline Offline
    Level 55 (91%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #11 on: January 19, 2010, 06:20:59 PM »

  • Wow, thanks.  Works great.
    modern algebra Male
    *
    Rep: +336/-113
    Online Online
    Level 79 (49%)
    Re: Wordlocks [Betrayal at Krondor]
    « Reply #12 on: January 31, 2010, 08:54:56 AM »

  • 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.


     

    hi

    RMRK.net Theme Super Ultra Mega Beta

    Follow RMRK on Twitter Ask RMRK Questions on Formspring Get RMRK Updates via Windows Live

    Page created in 0.312 seconds with 19 queries.