Typhon01 Quest Log

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by typhon01, Nov 18, 2014.

  1. typhon01

    typhon01 Designer/Coder Member

    Messages:
    20
    Likes Received:
    8
    Location:
    Knee-deep in code...
    First Language:
    English
    Typhon01 Quest Log
    Typhon01
     

     
    Introduction
    This is a quest log script that I wrote to provide a scene that can list any and all active "quests" that the player may have at any given time. What makes my system unique? Read on to find out!
     
    Features

    -  "File and switch" based. All of the information for your quest(s) are contained within a file outside of the engine, and quests are made "active" with the flip of a switch!

    -  Support for an unlimited number of quests, each with an unlimited number of "descriptions".

    -  Minimal coding required: The script has a section where you register your quests in the form of <quest name> => <file>, ... And that's it! All quest details are stored within a file.

    -  Built-in error-messages to assist in debugging! If anything is wrong with your quest, the message boxes will let you know!
     
    Screenshots

    These pictures show the script in action!

    Find the pictures here.
     
    How to Use
    Full instructions are detailed in the script itself, be warned, the instructions are long, but I believe they're fairly straightforward. Install this script in the Materials section, but above Main... just like any other script. Be aware, however, that this script relies on a certain Marshal Load "fix" snippet, which you can find both with my demo, and uploaded here as well. It's a small snippet, and all it does is allow un-serialized files to be read from an encrypted archive. This script will NOT work without it.
     
    Demo
    This demo includes the script, and the marshal load snippet, as well as a pre-designed quest to go along with it. Download it, play it, and if you like it, read the instructions and start creating your own quests! 
     
    (To those who have downloaded the demo, yes. The slime is defeatable. Don't let it win!)
     
    You may find the demo here.
     
    Script
    Don't want the demo? Fine! I'll just post the raw script here then. Likewise, I'll also post the Marshal Load "fix" snippet I was talking about.
     
    My script:
     
    #┌─────────────────────────────────────────────────────────────────────────────#│          #│                         ** TYPHON01 QUEST LOG SCRIPT**#│                                     Ver 1.0#│                                Author: Typhon01#│                A rework of an entirely different quest log script.#╞══════════════════════════════════════════════════════════════════════════════#│                                 READ ME FIRST#╞══════════════════════════════════════════════════════════════════════════════#│#│          The documentation for this script is rather big. The section for#│          instructions themselves are more than 100 lines. For that reason,#│          I intend to use this section to inform you what is worth reading.#│#│          You ought to read the description. It gives you a general idea of#│          what to expect.#│#│          You may read the disclaimer wish. I wrote the disclaimer for comic #│          relief, as I was highly stressed at the time of its writting.#│#│          The Important Notes section does contain information pertinant to#│          the functionality of this script, but really you only need to read#│          through it once.#│#│          Please pay special attention to the instructions. I recommend#│          following along with them, and reading it a second time if needs be.#│          Yes, I realize it's a lot of text, but if you don't learn how to#│          use this script, well then, how will you be able to use it?#│#╞══════════════════════════════════════════════════════════════════════════════#│                                  DESCRIPTION#╞══════════════════════════════════════════════════════════════════════════════#│          #│          This script provides a series of windows to list quests that the #│          player has aquired in the game. The details of these scripts are #│          taken from a text file, stored within the Data directory.#│#│          Quests are "File and Switch" based. For every quest, you should have#│          a text document with all of the quest details outlined within it.#│#│          The switch is used to determine if a given quest is active or not.#│#╞══════════════════════════════════════════════════════════════════════════════#│                                  DISCLAIMER#╞══════════════════════════════════════════════════════════════════════════════#│#│          This script does NOT design the mechanics of the quest for you, nor#│          is it capable of fixing crappy design errors on your part as a#│          developer. The quality of any quest designed using my system relies#│          entirely on the eventing skills of the developer using this system,#│          and neither I nor my Quest Log will take blame for your failure.#│#│          This script ONLY displays information that you, the developer,#│          provide, and it does so only when the switch that you, the #│          developer, set for it is set to the 'ON' position.#│#│          If for some reason this script does not work for you as intended,#│          please know that it is probably NOT due to a bug in the script. If#│          it is a bug in the script, let me know and I will gladly fix it. If#│          it is NOT a bug in the script, and you still expect me to fix it,#│          please uninstall RPG Maker VX Ace, and sit in a corner. Stay there#│          until you've decided that the world doesn't revolve around you. I#│          spent a crapload of time writing documentation for the script, so#│          the least you could do is take the time to read what I wrote just #│          for you so you'd be able to use it to the fullest of its #│          capabilities.#│#│          If you're still sitting in a corner after a year or so, well, you#│          deserve to be there. #│          #│#╞══════════════════════════════════════════════════════════════════════════════#│                               IMPORTANT NOTES#╞══════════════════════════════════════════════════════════════════════════════#│#│          This script REQUIRES the Marshal Loading "fix" that can be found#│          included with my demo. This script will NOT work without it. Go on,#│          try it if you don't believe me. Don't say I didn't warn ya.#│#│          It's also worth noting that this script provides no word-wrapping#│          functionality of its own. Originally, I did have a word-wrapping#│          method defined, but I discovered a general use, multi-purpose#│          word-wrapping script online that was written by KilloZappit. After#│          discovering this, I erased all of my inferior word-wrapping code,#│          and placed text within this script mentioning that it's recomended#│          to use KilloZappit's script with this one. Compatibility has been#│          tested, and links can be found in this script.#│          #╞══════════════════════════════════════════════════════════════════════════════#│                                  INSTRUCTIONS#╞══════════════════════════════════════════════════════════════════════════════#│          #│          This script is "file and switch" based. All of the details that the #│          script needs for your quest should be stored in a text file.#│ #│          Basically, the things the script looks for is as follows:#│#│ #│    - A switch id to determine whether a given quest is currently active or not#│    #│    - An icon id to display alongside the name of your quest within the Quest#│      Log.#│ #│    - One or more quest descriptions to display for your quest.#│#│ #│          And that's all... There are more features planned, but still in #│          process of being implemented.#│ #│ NOTE: You will not get any errors if you do not supply any of the above to#│       the script, but for functionality purposes, you should include the#│       switch id and at least one quest description.#│ #│          Let's get started. Go to your project folder, and open up the 'Data'#│          folder. Create a new folder in there, and call it 'Quests'. This is #│          where you will put all of your text documents that contain the quest#│          information. If you are reading this from my demo, then that folder #│          already exists, and there are some sample quests in there that you #│          can look through. Otherwise, go ahead and open notepad (or any other#│          text editor of your choice), and follow along.#│#│ #│          All text that is neither between a set of description tags nor a set#│          of tags themselves will be ignored by this script. Use this space to #│          store important information, such as things as who gave the quest, #│          everywhere the quest is referenced, and whatever else you may think#│          is relevant and deserves easy access. During developement, you may #│          decide that you no longer like the name of your quest, and you may #│          want to change it. If you do that, it will save a crap load of time #│          to know just exactly where your quest is referenced.#│ #│          I like to put the quest's name and date created at the top, but this#│          is unnecessary. (may be useful if you're in the habit of editing #│          multiple quests at once)#│   #│          If you do not yet know where exactly your quest will have #│          reference(s), then do not worry. The script works perfectly fine #│          without them, and you can always add those important references in #│          as they come up.#│#│#│#│          The first tag I would recommend writing is the Switch ID tag. It #│          looks like this:#│#│ #│  <Quest Switch: [id]>#│ #│#│          Where [id] is the game switch id that you want to dedicate to this #│          quest.#│#│ #│ NOTE: I HIGHLY recommend keeping all of your quests on separate switches#│       from both other quests, and anything else that requires a switch in your#│       project. Quests appear in the quest log depending on whether or not these#│       switches are active, and if you have multiple events (quests, npc's, etc)#│       using the same switch, keeping track of it can cause a migrane.#│#│ #│          Next, I would write the Icon ID tag. You don't need to have one, as #│          it's purely for aesthetic reasons, but I find it adds a classy touch.#│          This tag is similar to the previous:#│#│ #│  <Quest Icon: [id]>#│#│ #│          Again, [id] is the id of the icon you want to use. The id for any #│          icon can easily be found by opening the database, selecting the #│          items tab, and clicking on the icon box. For any icon you select in #│          that window that pops up, its ID will be displayed at the bottom left.#│ #│#│          Finally, you ought to have at least one set of description tags. #│          Description tags are unique from either of the previous tags, in #│          that they come in pairs, and you may have as many of them as you #│          want for any given quest, provided you do them correctly. Further #│          explanation is given below a little ways.#│#│          The default description tag looks like this:#│#│ #│  <Quest Description>#│         [text]#│  </Quest Description>#│#│ #│          Where [text] can be, well, anything. Your limited by how much space #│          you have within the description box, so be mindful not to get too #│          crazy. Any line breaks within the string is stripped out by this #│          script when it's read, so feel free to format that text however you #│          want in order to make your life easier when editing. I would advise #│          adding a space every time you have a line break, so words do not #│          flow together. Here's an example of what I mean:#│        #│          No space before break#│          This is the second line.#│#│          Those sentences would be read as follows:#│          #│          No space before breakThis is the second line.#│#│          To fix that issue, simply add a space every time you use a line break.#│#│          This line has a space at the end #│          and this is the second line.#│#│          Which is interpreted as:#│#│          This line has a space at the end and this is the second line.#│#│          Sorry for the tangent, let's get back on topic.#│ #│          Now, as I mentioned, you may have multiple quest descriptions. The #│          tag above is valid for, and only for, the default description.#│          All other descriptions MUST be numbered in order to work correctly. #│#│          Here is a demonstration:#│ #│#│  <Quest Description 2>#│          [text]#│  </Quest Description 2>#│ #│#│          As you can see, both the initiating tag and the closing tag for the #│          description now have a number in them. This number must be unique #│          from all other description tags in your quest file, but the numbers #│          do not necessarily have to be sequential in the order that the #│          descriptions will appear. Using the script call to update the quest #│          description, you have the option of either doing it sequentially,#│          which is the default method, or you could also call a specific #│          description via the description number found in the tag like above. #│          I prefer to keep things sequential, but do whatever floats your boat.#│ #│          There is no arbitrary limit that I am aware of as to how many #│          descriptions your quest may have, for example, you may have the #│          following:#│#│ #│  <Quest Description 1500>#│          [text]#│  </Quest Description 1500>#│#│ #│          Why you would need or even WANT 1500 descriptions for a single quest#│          in the first place is beyond me, but if you can keep track of them, #│          more power to you.#│ #│          How the script is set up, the quest log will start including your #│          quest in the list it populates at the moment the switch bound to #│          said quest is flipped 'on'. The description that is defined between #│          the first description tag (that is, <Quest Descripton>, NOT #│          <Quest Description 2> or likewise) will be the one that will show on#│          the quest log at that moment. Changing the description used for any #│          given quest is easily done with one of two script calls:#│#│ #│  update_quest_description("<Quest Name>")#│             OR#│  update_quest_description("<Quest Name>", <description id>)#│#│ #│          Where <Quest Name> is the name of the quest to be updated, and #│          <description id> is the description to use (remember the numbers?). #│#│#│  Important: Quest Name MUST be enclosed in quotes. If <description id> is not#│  defined, the script will look for the next description sequentially.#│#│ #│          -If you try to update the description, and the description does not #│           exist at the id provided, a pop-up box will display the error.#│ #│          -If you update descriptions sequentially, and you do so while you're #│           already at the last description of the quest, a pop-up box will #│           display the error.#│ #│          -If you supply a quest name that is not recognized by the script, a #│           pop-up box will display the error. #│ #│          Now that you have your Quest file(s) complete, all you have left #│          before being able to use it in-game is to define it within the #│          editable region below.#│ #│          There is a hash, simply referred to as Quests. To add an entry, #│          follow this format:#│ #│#│  "<Quest Name>" => "<Text File>",#│#│ #│          I believe that's self-explanatory, but just in case, the #│          <Quest Name> is the name of the quest as you want it to appear on #│          the quest log, and <Text File> is the file in which all of the quest#│          information is stored. Both the quest name and the text file MUST be#│          enclosed in quotes. Also, the coma at the end is NOT a typo. Please#│          be sure to include it. To keep things convenient for yourself as a #│          developer, I'd recommend naming both the Quest and the file the same#│          thing, or at least something very similar. They don't have to be, #│          but that seems more intuitive to me than anything else.#│ #│          The hash where you define your quests is in Editable Region 2. Be #│          sure to read through all the options in Editable Region 1 first to #│          customize the script to function how you want.#│#│          One last thing to mention before I let you go crazy:#│          There is a setting below that allows you to choose whether you#│          want all of the quests to be loaded upon game start, or if you want#│          to load them manually. I performed a comprehensive test to determine#│          how much time a typical quest takes to load, and how much space it#│          consumes within the save file, and I've determined that while each#│          quest is not significant, if you have thousands of quests in your#│          game, it's probably better to load them manually when you need them,#│          and then dispose of them when it's complete.#│#│          That gives us two more script calls:#│#│#│  load_quest("<quest name>")#│#│      AND#│#│  dispose_quest("<quest name>")#│#│#│          Where <quest name> is obviously the name of the quest. If you try#│          to load a quest that's already loaded, you will receive a pop-up#│          box informing you so. If you try to dispose of a quest that's#│          already disposed, you will receive a pop up box informing you that#│          the quest could not be found, and list possible reasons as to why.#│#│          Both of these script calls may be used regardless of whether you#│          choose to load every quest at the beginning or not.#│          #╞══════════════════════════════════════════════════════════════════════════════#│                                  SCRIPT CALLS#╞══════════════════════════════════════════════════════════════════════════════#│#│          This section has been added as a covenience for quickly looking up#│          important script call information, since this script does utilize a#│          few of them...#│#│  load_quest("<quest name>")#│        AND#│  dispose_quest("<quest name>")#│#│          Those calls load and dispose of any given quest, respectively. If a#│          quest is already loaded when you try to load it, you get a message.#│          Likewise if you dispose of an already disposed quest. Both calls are#│          only required if you configure the script accordingly, yet retain#│          their functionality if the script is left as-is.#│#│  update_quest_description("<Quest Name>")#│          OR#│  update_quest_description("<Quest Name>", <Description ID>)#│#│          The first call updates the description sequentially (i.e., from#│          description 2 to description 3), while the second call updates#│          the description to display a specific description. Both are obviously#│          useful... Or else I wouldn't have included them! #│#│  SceneManager.call(Quest_Log_Scene)#│#│          This call opens the quest log, without having to open it through the#│          menu. I don't know if that's useful or not, but there it is anyhow.#│#╞══════════════════════════════════════════════════════════════════════════════#│                                     CREDITS#╞══════════════════════════════════════════════════════════════════════════════#│#│          Credits for use of this script should go to Typhon01.#│#│          This script is free for use in all projects, commercial or otherwise.#│#│          Do not claim work as your own.#│#│          If you use KilloZappit's word-wrapping script (HIGHLY recommended),#│          then be sure to include proper credit there as well.#│#│          Someone genius developed the Marshal Loading "fix" that this script#│          relies on, but I've been unable to figure out how it was. I found#│          the script at himeworks, more specifically, here at this page:#│          http://himeworks.com/2014/09/reading-files-in-rpg-maker/#│          The original creator is unknown, as mentioned in that post, but if#│          anyone out there does know who came up with it, please let me know#│          so I can give proper thanks.#│#│          Special thanks to the one who developed the "fix" on which this#│          script relies. It would not be possible without you.#└─────────────────────────────────────────────────────────────────────────────  module Typhon01  module QuestLog    #┌─────────────────────────────────────────────────────────────────────────────┐#│                          ** EDITABLE REGION 1 **                            │#└─────────────────────────────────────────────────────────────────────────────┘     # This setting controls whether the Quest Log scene can be called from the    # menu. True by default. If this is set to false, the quest log can only    # be accessible via script call.    ShowInMenu = true      #These settings set a default icon for quests that don't have icons defined.     #Note: This is purely for looks, having a quest icon does NOT affect the     #functionality of this script.    UseDefaultIcon = true    DefaultIcon    = 238        #     These strings appear in the Window_Help instance, quest_help_window.    QuestLogHelpText1 = "Hover over a quest to view details"    QuestLogHelpText2 = "Press X or ESC to Exit"        # This is the directory in which your quests are stored. Change it how you    # want, but make certain you put your quests there.    QuestLogDirectory = "Data/Quests/"            # This setting determines whether all quests are loaded at once or not.    # The purpose of this setting is to make the save files smaller, by loading    # quests when they're recieved, and freeing them from memory when they're    # completed. To determine whether you should use this feature, please refer    # to the Benchmarks.txt file within the root directory of this project.        # If TRUE: All quests MUST be loaded via script call before use.    # e.g. load_quest("<quest name>")        # If FALSE: All quests are automatically loaded upon game start, but the    # load_quest and dispose_quest script calls still function as intended.    LoadViaScriptCall = false # true or false    # false by default, to allow "plug-and-play" behavior... But true is advised #┌─────────────────────────────────────────────────────────────────────────────┐#│                        ** END EDITABLE REGION 1 **                          │#└─────────────────────────────────────────────────────────────────────────────┘ #------------------------------------------------------------------------------    Quests = { #<--- DO NOT EDIT THIS LINE#------------------------------------------------------------------------------    #┌─────────────────────────────────────────────────────────────────────────────┐#│                          ** EDITABLE REGION 2 **                            │#└─────────────────────────────────────────────────────────────────────────────┘            #All quests need to have a coma after them**      # All entries should follow this form: "<Quest Name>" => "<File>",# Example:"Example Quest" => "Example.txt",          # Add your quests here, add more space as necessary.             #┌─────────────────────────────────────────────────────────────────────────────┐#│                  ***      END EDITABLE REGION 2     ***                     │#│              ***     DO NOT MODIFY BEYOND THIS POINT     ***                │#└─────────────────────────────────────────────────────────────────────────────┘       "DEFAULT_QUEST" => "" #<--- ** Do not delete this!    }#<--- Do not delete!  endend    # And seriously, that was the end of the editable regions. Editing further down# here could mess up the entire script. Consider yourself warned.  #==============================================================================# ** Quest Log Scene#------------------------------------------------------------------------------#  This scene handles processing for the quest log#==============================================================================class Quest_Log_Scene < Scene_Base  include Typhon01::QuestLog  #--------------------------------------------------------------------------  # * Start  #--------------------------------------------------------------------------  def start    super    # Initialize all windows    init_quest_help_window    init_quest_selector_window    init_quest_description_window        #Initialize symbol variable    @current_symbol = nil        @quest_detail_window = Quest_Detail_Window.new  end  #--------------------------------------------------------------------------  # * Initialize Quest Help Window  #--------------------------------------------------------------------------  def init_quest_help_window    @quest_help_window = Window_Help.new    @quest_help_window.set_text(QuestLogHelpText1 + "\n" + QuestLogHelpText2)  end  #--------------------------------------------------------------------------  # * Initialize Quest Selector Window  #--------------------------------------------------------------------------  def init_quest_selector_window    @quest_selector_window = Quest_Selector_Window.new(0, @quest_help_window.height)    @quest_selector_window.set_handler:)cancel, method:)return_scene))  end  #--------------------------------------------------------------------------  # * Initialize Quest Description Window  #--------------------------------------------------------------------------  def init_quest_description_window    @quest_description_window = Quest_Description_Window.new(@quest_selector_window.width, @quest_help_window.height, Graphics.width * 0.6, Graphics.height - 72)   end     #--------------------------------------------------------------------------  # * Frame Update  #--------------------------------------------------------------------------  def update    super()    update_description_text  end  #--------------------------------------------------------------------------  # * Update Description Text  #--------------------------------------------------------------------------  def update_description_text    if @current_symbol != @quest_selector_window.current_symbol      @current_symbol = @quest_selector_window.current_symbol      $game_system.quest_name_array.each_index do |index_id|        if $game_system.quest_name_array[index_id] == @current_symbol.to_s          description_text = $game_system.quest_description_array[index_id]          @quest_description_window.set_description_text(description_text)          break        end      end    end  end  #--------------------------------------------------------------------------  # * Command Ok  #--------------------------------------------------------------------------  def command_ok    @quest_description_window.close    @quest_selector_window.close    @quest_help_window.set_text(@quest_selector_window.current_symbol.to_s)    @quest_detail_window.open    @quest_hddn_cmd_window.open    @quest_detail_window.activate    @quest_hddn_cmd_window.activate  end  #--------------------------------------------------------------------------  # * Reload Scene  #--------------------------------------------------------------------------  def reload_scene    @quest_detail_window.close    @quest_hddn_cmd_window.close    @quest_hddn_cmd_window.deactivate    @quest_help_window.set_text(QuestLogHelpText1 + "\n" + QuestLogHelpText2)    @quest_selector_window.open    @quest_description_window.open    @quest_selector_window.activate  endend     #==============================================================================# ** Quest Selector Window#------------------------------------------------------------------------------#  This Class holds all the information for the Quest Selector Window#==============================================================================class Quest_Selector_Window < Window_Command  #--------------------------------------------------------------------------  # * Initialize  #--------------------------------------------------------------------------  def initialize(x,y)    super(x,y)  end  #--------------------------------------------------------------------------  # * Window Width  #--------------------------------------------------------------------------  def window_width    return Graphics.width * 0.4  end  #--------------------------------------------------------------------------  # * Window Height  #--------------------------------------------------------------------------  def window_height    return Graphics.height - 72  end  #--------------------------------------------------------------------------  # * Create Command List  #--------------------------------------------------------------------------  def make_command_list    $game_system.quest_name_array.each_index do |index|            temp_name = $game_system.quest_name_array[index]      current_switch = $game_system.quest_switch_array[index].to_i            if $game_switches[current_switch]        add_command(temp_name, temp_name.to_sym)      end    end  end  #--------------------------------------------------------------------------  # Re-write of Draw Item  # Only affects Quest_Selector_Window(s)  #--------------------------------------------------------------------------  def draw_item(index)    enabled = command_enabled?(index)    change_color(normal_color, enabled)    rect = item_rect_for_text(index)    text = command_name(index)    $game_system.quest_name_array.each_index do |quest_index|      if $game_system.quest_name_array[quest_index] == text        if $game_system.quest_icon_array[quest_index]          draw_icon($game_system.quest_icon_array[quest_index].to_i, rect.x, rect.y)          rect.x += 28          rect.width -= 28#          draw_text(rect, text, alignment)#        else                                    # REDUNDANCIES!!!!! ACK!!!#          draw_text(rect, text, alignment)        end        draw_text(rect, text, alignment) # <- That solves that!      end    end  endend    #==============================================================================# ** Quest Description Window#------------------------------------------------------------------------------#  This class holds all the information for the Quest Description Window#==============================================================================class Quest_Description_Window < Window_Base  #--------------------------------------------------------------------------  # * Initialize  #--------------------------------------------------------------------------  def initialize(x, y, width, height)    super(x, y, width, height)  end  #--------------------------------------------------------------------------  # * Window Width  #--------------------------------------------------------------------------  def window_width    return Graphics.width * 0.6  end  #--------------------------------------------------------------------------  # * Window Height  #--------------------------------------------------------------------------  def window_height    return Graphics.height - 72  end    def set_description_text(text)    contents.clear    # Draw Text    draw_text_ex(0,0,text)  end    def draw_text_ex(x, y, text)    text = convert_escape_characters(text)    pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}    process_character(text.slice!(0, 1), text, pos) until text.empty?  end     #--------------------------------------------------------------------------  # * Wait After Output of One Character  #--------------------------------------------------------------------------  def wait_for_one_character    # Prevent Fiber.yield error  endend      #==============================================================================# ** Scene Menu#------------------------------------------------------------------------------#  This class performs the menu screen processing.#==============================================================================class Scene_Menu < Scene_MenuBase    alias anotherfreakingalias_02020      create_command_window  #--------------------------------------------------------------------------  # * Create Command Window  #--------------------------------------------------------------------------  def create_command_window    anotherfreakingalias_02020    if Typhon01::QuestLog::ShowInMenu      @command_window.set_handler:)questlog,    method:)command_questlog))    end  end  #--------------------------------------------------------------------------  # * Command Quest Log  #--------------------------------------------------------------------------  def command_questlog    SceneManager.call(Quest_Log_Scene)  end  end class Window_MenuCommand < Window_Command  #--------------------------------------------------------------------------  # * Add Exit Game to Command List  #--------------------------------------------------------------------------  alias winmencom_addgameendcom_typhon01_afoj       add_game_end_command  def add_game_end_command    if Typhon01::QuestLog::ShowInMenu      add_command("Quest Log", :questlog)    end    winmencom_addgameendcom_typhon01_afoj  endend     class Quest_Detail_Window < Window_Base  def initialize    super(0,72,Graphics.width,Graphics.height - 72)    self.openness = 0  endend   #==============================================================================# ** Game_System#------------------------------------------------------------------------------#  This class handles system data. It saves the disable state of saving and # menus. Instances of this class are referenced by $game_system.#============================================================================== class Game_System  include Typhon01::QuestLog  #--------------------------------------------------------------------------  # * Public Instance Variables  #--------------------------------------------------------------------------  attr_accessor :quest_name_array  attr_accessor :quest_raw_string_array  attr_accessor :quest_description_array  attr_accessor :quest_icon_array  attr_accessor :quest_switch_array  attr_accessor :quest_description_id_array  #--------------------------------------------------------------------------  # * Setup Quest Arrays (To be run on New Game Only)  #--------------------------------------------------------------------------  def setup_all_quest_arrays    @iterator = 0    @quest_name_array            = []    @quest_raw_string_array      = []    @quest_description_array     = []    @quest_icon_array            = []    @quest_switch_array          = []    @quest_description_id_array  = []    initialize_quest_arrays    @quest_raw_string_array      = []  end   #--------------------------------------------------------------------------  # * Initiailize Quest Arrays  #--------------------------------------------------------------------------  def initialize_quest_arrays    unless LoadViaScriptCall            Quests.each_key do |quest_name|        unless Quests[quest_name] == "" || Quests[quest_name] == "Example.txt"          @quest_name_array.push(quest_name)          temp_string = load_data(QuestLogDirectory + Quests[quest_name])          @quest_raw_string_array.push(temp_string.gsub(/\n/,"").gsub(/\r/,""))          initialize_description_array          initialize_icon_array          initialize_switch_array          initialize_descrip_id_array          @iterator += 1          temp_string = []        end      end    end  end  #--------------------------------------------------------------------------  # * Initialize Description Array  #--------------------------------------------------------------------------  def initialize_description_array    /<Quest Description>(.+)<\/Quest Description>/im.match(@quest_raw_string_array[@iterator])    @quest_description_array[@iterator] = $1  end  #--------------------------------------------------------------------------  # * Initialize Icon Array  #--------------------------------------------------------------------------  def initialize_icon_array    /<Quest Icon:\s*(\d+)>/im.match(@quest_raw_string_array[@iterator])    if $1 && $1 != ""      @quest_icon_array[@iterator] = $1    else      if Typhon01::QuestLog::UseDefaultIcon        @quest_icon_array[@iterator] = Typhon01::QuestLog::DefaultIcon      end    end  end  #--------------------------------------------------------------------------  # * Initialize Switch Array  #--------------------------------------------------------------------------  def initialize_switch_array    /<Quest Switch:\s*(\d+)>/im.match(@quest_raw_string_array[@iterator])    @quest_switch_array[@iterator] = $1  end    def initialize_descrip_id_array    @quest_description_id_array[@iterator] = 1  end  #--------------------------------------------------------------------------  # * Update Quest Description  #--------------------------------------------------------------------------  def update_quest_description(quest_name, description_id=nil)    # Create Boolean to prevent needless cycling    name_found = false    # Determine if description id was given    unless description_id      # if not...      # begin running through the quest list.      $game_system.quest_name_array.each_index do |index|                # compare quest in list with quest name given        if quest_name == $game_system.quest_name_array[index]                    # if it's a match, set the boolean to true and load the quest file.          name_found = true          temp_string = load_data(QuestLogDirectory + Quests[quest_name]).gsub(/\n/,'').gsub(/\r/,'')                    # set a temporary variable for determining which description to use          alfalfa = @quest_description_id_array[index] + 1                    # parse the loaded data.          /<Quest Description #{alfalfa}>\s*(.+)<\/Quest Description #{alfalfa}>/im.match(temp_string)          # alfalfa was used simply because it came to mind first.                    # determine if parsed data contained a match for the description.          if $1 && $1 != ""                        # if so, set description accordingly.            @quest_description_array[index] = $1            @quest_description_id_array[index] = alfalfa                        # no need to continue cycling quests at this point, break            break                      else            # if no match was found for the next description, report error via msg            msgbox_p("#{quest_name} does not have a definition for description #{alfalfa}, please check that the quest file is configured properly.")                        # no need to continue cycling quests at this point, break            break          end        end      end      # if every quest was cycled, and the quest name didn't match any of them...      if !name_found                # report error via msg box, inform them to double check the script.        msgbox_p("#{quest_name} was not recognized as a loaded quest. Please be sure to load the quest via script call before use.")      end    else      # If description id WAS given      # begin cycling all of the quests      $game_system.quest_name_array.each_index do |index|                # determine if the quest matches the given quest name        if quest_name == $game_system.quest_name_array[index]                    #if it's a match, set the boolean to true and load the quest file.          name_found = true          temp_string = load_data(QuestLogDirectory + Quests[quest_name]).gsub(/\n/,'').gsub(/\r/,'')                    # Determine what regular expression must be used to parse the information          if description_id == 1            # if description id is equal to 1...            /<Quest Description>\s*(.+)<\/Quest Description>/im.match(temp_string)            @quest_description_array[index] = $1 # NO ERROR HANDLING, ALL QUESTS            @quest_description_id_array[index] = 1 # SHOULD HAVE A DEFAULT DESC.          else            # if description id is equal to anything other than 1.            /<Quest Description #{description_id}>\s*(.+)<\/Quest Description #{description_id}/im.match(temp_string)            if $1 && $1 != ""                            # Determine if description actually exists.              @quest_description_array[index] = $1              @quest_description_id_array[index] = description_id            else              # if it doesn't, say so in a message box.              msgbox_p("#{quest_name} does not have a definition for description #{description_id}, please check that the quest file is configured properly.")            end          end        end      end      # if the quest name didn't match any of the quests      if !name_found        # display msg box detailing said error.        msgbox_p("#{quest_name} was not recognized as a defined quest. Please check the Quest Log script to be sure you have the quest name right.")      end    end  end    def load_quest(quest_name)    if Quests[quest_name] == nil      msgbox_p("Quest #{quest_name} was not recognized as a defined quest. Please check to be sure that everything is configured properly.")    else      @quest_raw_string_array = load_data(QuestLogDirectory + Quests[quest_name]).gsub(/\n/,"").gsub(/\r/,"")      unless @quest_name_array.include?(quest_name)        @quest_name_array << quest_name        set_loaded_quest_arrays(quest_name)        p(@quest_name_array, @quest_switch_array, @quest_description_array)      else        msgbox_p("Data Already Loaded")      end    end  end    def dispose_quest(quest_name)    if @quest_name_array.include?(quest_name)      delete_var = 10      @quest_name_array.each_index do |quest_index|        if @quest_name_array[quest_index] == quest_name          delete_var = quest_index          break        end      end      @quest_name_array.delete_at(delete_var)      @quest_description_array.delete_at(delete_var)      @quest_description_id_array.delete_at(delete_var)      @quest_icon_array.delete_at(delete_var)      @quest_switch_array.delete_at(delete_var)    else      msgbox_p(quest_name + " was not found. This may be because it has not been loaded. Please ensure that the quest is set up properly in the script, and that you have it loaded before you try to use/dispose of it.")    end  end    def set_loaded_quest_arrays(quest_name)    /<Quest Description>(.+)<\/Quest Description>/im.match(@quest_raw_string_array)    @quest_description_array << $1    /<Quest Icon:\s*(\d+)>/im.match(@quest_raw_string_array)    @quest_icon_array << $1    /<Quest Switch:\s*(\d+)>/im.match(@quest_raw_string_array)    @quest_switch_array << $1    @quest_description_id_array << 1    @quest_raw_string_array = []  endend    #==============================================================================# ** Game_Interpreter#------------------------------------------------------------------------------#  An interpreter for executing event commands. This class is used within the# Game_Map, Game_Troop, and Game_Event classes.#============================================================================== class Game_Interpreter  #--------------------------------------------------------------------------  # * Script Call: update_quest_description  #--------------------------------------------------------------------------  def update_quest_description(quest_name, description_id = nil)    $game_system.update_quest_description(quest_name, description_id)  end  #--------------------------------------------------------------------------  # * Script Call: load_quest  #--------------------------------------------------------------------------  # Use this to initialize quest arrays for a particular quest.  #--------------------------------------------------------------------------  def load_quest(quest_name)    $game_system.load_quest(quest_name)  end  #--------------------------------------------------------------------------  # * Script Call: update_quest_description  #--------------------------------------------------------------------------  # Use this to free the details of a particular quest from memory.  #--------------------------------------------------------------------------  def dispose_quest(quest_name)    $game_system.dispose_quest(quest_name)  endend # Many lines of code were saved due to deleting the crappy word-wrapping method# that I wrote. I highly recommend use of KilloZapit's Word Wrapping script for# all of your word-wrapping needs. #==============================================================================# ** Scene_Title#------------------------------------------------------------------------------#  This class performs the title screen processing.#============================================================================== class Scene_Title < Scene_Base  #--------------------------------------------------------------------------  # * Aliased Method: Command New Game.  #    Reason for alias: To insure the arrays for all of the quests only  #    initialize when a new game is started, rather than both at game launch  #    AND new game select.  #--------------------------------------------------------------------------  alias t01_questlogscript_scnttl_aoijf       command_new_game  def command_new_game    t01_questlogscript_scnttl_aoijf    $game_system.setup_all_quest_arrays  endend
     
    Marshal Fix:
     
    Code:
    class << Marshal  alias_method(:___load, :load)  def load(port, proc = nil)        ___load(port, proc)  rescue TypeError        if port.kind_of?(File)          port.rewind          port.read        else          port        end  endend unless Marshal.respond_to?(:___load)
     
    FAQ
    None yet.
    Potential question: Why "file and switch" based? What advantage does that bring?

    A) I chose to do things this way because it makes the most sense to me. A file contains all of the details of your quest, so all you need to do with the script is register what quest goes with what file, and I've tried to make that as intuitive as possible. The biggest advantage is as follows:

    Anything that is in the file that isn't between tags (as discussed within the instructions of the script) is essentially ignored by the script. This means you can put things in there that are only relevant to you. Things such as the giver of the quest, anywhere that particular quest might be mentioned, quest rewards, and whatever else you could think to put there. All of this information all in one place makes it really easy for you to make in-game changes should you ever decide that you need to change the quest up a little bit, especially if you have multiple quests in your game. Every quest has its own file, thus none of your references can be mixed up. When it comes down to it, I feel that this system truly allows you as a developer to stay organized, and organization is very important for anyone who's serious about finishing their projects.
     

    Another, minor advantage is, by using this script, you are free to edit your quest information with your favorite text editor. I personally feel a little better when I get to use something I'm familiar with.

    Credit
    Credits for the use of this script should go to Typhon01.
     
    This script is free for use in all projects, commercial or otherwise, as long as the proper credit is given.
     
    Do not claim this work as your own.
     
    Author's Notes
    As mentioned above, this script will not work without that Marshal Load "fix" snippet. I do not know who originally produced that snippet, but I found it online at Himeworks. More specifically, I found it at http://himeworks.com/2014/09/reading-files-in-rpg-maker/
    If anyone knows who originally produced that snippet, please let me know so I may give them special thanks.
     
    Also worth mentioning, this script does not have any word-wrapping features of its own, so you'll need to find something to cover that for you. Originally, I was writing code to support word-wrapping, but I found a script written by KilloZapit that works infinitely better than mine did. I recommend using that one, which can be found here. My script will run fine without, but it certainly looks better with the word-wrapping.

    This script does everything I've claimed it to do, and does so pretty well. I have features planned for future versions of this script (such as being able to "select" a quest to view more details about it), but progress has been slow in that regard as I've yet to attain an intuitive way to implement it so you as a developer can utilize the functionalities with ease...

    If you have any suggestions as to how I can make anything better, be it re-writing my instructions in a particular way, different formatting styles, or even things pertaining to code, I'm always listening for ideas, and I appreciate anyone who helps me. Thanks in advance!

    EDIT: My pictures didn't seem to appear... Placed a link in place.
     
    Last edited by a moderator: Nov 19, 2014
    #1
    Paramecium13 and GGSlayer like this.

Share This Page