Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quest Manager
#1
Quest Manager Revision 1
by Prexus
Reposted by Me™ / Derk-Jan
Jun 4 2005

This is a locked, single-post thread from Creation Asylum.  Archived here to prevent its loss.
No support is given.


# â—? .completed
# - If true, the name will be green in the quest menu.
# [NEW] This field will automatically update if conditions for quest are met.

5% credit to Mr. DJ
295% credit to Prexus

Prexus Wrote:One of the first scripts i've ever wanted to make was a quest manager. Through a little try and try again I made some craptastic one. I forgot about it, and since became a fairly good scripter. I went back and made a really good one.

# To use this script, simply paste it #
# above main. It should not interfere #
# with any other scripts unless they use #
# or change scene_load and scene_save and#
# scene_title, as they are the only #
# default scripts that are affected. #


The Script:

Place in a new script above main called PRX_Quest

Code:
#----------------------------------------#
# â—? Quest Manager Revision by Prexus â—? #
#----------------------------------------#
# Created on Friday, June 3rd            #
# Revised on Sunday, June 5th            #
# www.prexus.nearfantasticaonline.com    #
# All Rights Reserved                    #
#----------------------------------------#
# Interferance Scripts:                  #
# Quest Manager Revision uses these      #
# default classes, so make sure no other #
# scripts interfere. If they do, update  #
# them accordingly.                      #
# Game_Party                             #
# Scene_Title                            #
# Scene_Save                             #
# Scene_Load                             #
#----------------------------------------#
# New in Revision 1:                     #
# The quests look better visually, using #
# a duallist for requirements and easier #
# access to a quests status in the list. #
# Also, when a quest uses switches or    #
# variables, $game_switches/variables is #
# no longer used. This is important to   #
# note because now, you must use Call    #
# Script to change the values.           #
# Like so:                               #
# $quest_variables[id] (will return the value at id.)
# $quest_variables[id] += value (will add value to the current value of the var)
# $quest_variables[id] -= value (will subtract value from the current var)
# $quest_variables[id] /= value (will divide the current var with value)
# $quest_variables[id] *= value (will mulitple the current var by value)
# $quest_switches[id] (will return true or false based on the id)
# $quest_switches[id] = true (will set switch to true)
# $quest_switches[id] = false (will set switch to false)
# â—? Thank you Mr. DJ for the idea =) â—? #
#----------------------------------------#
# To use this script, simply paste it    #
# above main. It should not interfere    #
# with any other scripts unless they use #
# or change scene_load and scene_save and#
# scene_title, as they are the only      #
# default scripts that are affected.     #
# To add a quest to the database, in     #
# Call Script, put the following:        #
# â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—? #
# $quest[id] = PRX_Quest.new       Change ID to whatever you want. Just never use the same twice.
# $quest[id].name = "Enter Name Here"
# $quest[id].type = 0-3 (explained below)
# $quest[id].description = "Short Explaination of Quest"
# $quest[id].requirements = [] (An array of values, Explained Below)
# $quest[id].values = [] (An array of values, explained below)
# $quest[id].switches = [] (Array of switch IDs, explained below.)
# $quest[id].variables = [] (Array of variable IDs, explained below.)
# $quest[id].completed = Set this to true/false when the quest is done
# $quest[id].disabled = If you want the quest to appear disabled, set this to true
# â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—? #
# Important Notes about Values:
# â—? .name
#   - A string value that appears in the list.
# â—? .type
#   - An integer value 0-3.
#     When the value is set to 0, make sure to set .requirements to string values.
#     These will appear in the quest menu and never change.
#
#     If type is set to 1, make sure to set .requirements to string values and
#     set .variables accordingly. Also, .values needs to be set
#     appropriately as well. For example:
#     .requirements = ["Kill Two Goblins", "Find 3 Eggs"]
#     .values = [2, 3]
#     .variables = [1, 2]
#     If variable 1 is 2 or higher, the first requirement will appear green and
#     if variable 2 is 3 or higher, the second requirement will appear green.
#
#     If it is set to 2, make sure to set .requirements to string values and
#     set .switches accordingly. For example:
#     .requirements = ["Fight Orc", "Capture Flag"]
#     .switches = [1, 2]
#     If switch 1 is on, Fight Orc will appear green in the menu and if switch 2
#     is on, Capture Flag will also appear green.
#
#     If type is set to 3, make sure to set .requirements to IDs of Items from
#     the database. Then make sure .values are set appropriately.
#     For example:
#     .requirements = [1, 2, 3]
#     .values = [3, 2, 1]
#     You'd need 3 potions, 2 high potions, and 1 full potion.
# â—? .description
#   - A string value that appears in the description box explaining quest.
# â—? .requirements
#   - An array which if type is 0 2 or 3, will contain string values, for example
#     ["Kill the King", "Save the Princess", "Dance a Jig"]
#     If type is 1, be sure to fill it with item ids such as
#     [1, 2, 3] will return Potion, High Potion, Full Potion by default
# â—? .values
#   - An array which holds integer values. If the type is 0, this field can be
#     blank as it will have no effect. If type is 1, these values correspond with
#     how much of the items in .requirements you need. For example:
#     .requirements = [1, 2, 3]
#     .values = [3, 2, 1]
#     You need 3 Potions, 2 High Potions, and 1 Full Potion.
#     If type is 1, this holds how much of each Quest Variable you need.
# â—? .switches
#   - Holds integer values of the IDs of Quest_Switches. This is used if the .type
#     is set to 2.
# â—? .variables
#   - Holds integer values of the IDs of Quest_Variables. This is used if the .type
#     is set to 1.
# â—? .completed
#   - If true, the name will be green in the quest menu.
#     [NEW] This field will automatically update if conditions for quest are met.
# â—? .disabled
#   - If true, the name will be greyed out in the quest menu.
# Note: If both completed and disabled are true, it will appear completed.
#
# If any further questions are needed refer to the RMXP.net thread.
# â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—?â—? #

# Visual Aspects:

# New Class
#-------------------#
# â—? Scene Quest â—? #
#-------------------#
class Scene_Quest
def main
 @quest = Window_Quest.new
 @desc = Window_Description.new
 @req = Window_Requirements.new
 @quest.help_window = @desc
 @quest.req_window = @req
 Graphics.transition
 loop do
   Graphics.update
   Input.update
   update
   if $scene != self
     break
   end
 end
 Graphics.freeze
 @quest.dispose
 @desc.dispose
 @req.dispose
end
def update
 @quest.update
 @desc.update
 @req.update
 if Input.trigger?(Input::B)
   $scene = Scene_Map.new
 end
end
end
# End New Class

# New Class
#--------------------#
# â—? Window Quest â—? #
#--------------------#
class Window_Quest < Window_Selectable
attr_reader :req_window
def initialize
 super(0, 0, 640, 192)
 @column_max = 2
 refresh
 self.index = 0
end
def quest
 return @data[self.index]
end
def refresh
 if self.contents != nil
   self.contents.dispose
   self.contents = nil
 end
 @data = []
 for i in 0...$quest.size
   if $quest[i] != nil
     @data.push($quest[i])
   end
 end
 @item_max = @data.size
 if @item_max > 0
   self.contents = Bitmap.new(width - 32, row_max * 32)
   self.contents.font.name = $fontface
   self.contents.font.size = $fontsize
   for i in 0...@item_max
     draw_item(i)
   end
 end
end
def draw_item(index)
 quest = @data[index]
 text = ""
 if quest.type == 0
   self.contents.font.color = normal_color
   text = quest.name
 else
   if quest.disabled
     self.contents.font.color = disabled_color
     text += "(?) " + quest.name.to_s
   elsif quest.completed
     self.contents.font.color = Color.new(0, 255, 0, 255)
     text += "(*) " + quest.name.to_s
   else
     self.contents.font.color = Color.new(255, 0, 0, 255)
     text += "(!) " + quest.name.to_s
   end
 end
 x = 4 + index % 2 * (288 + 32)
 y = index / 2 * 32
 self.contents.draw_text(x, y, 212, 32, text, 0)
end
def update_help
 @help_window.set_text(self.quest == nil ? "" : self.quest.description)
 if self.quest != nil
   if @req_window != nil
     @req_window.clear_text
     for i in 0...self.quest.requirements.size
       quest = self.quest
       if quest.type == 0
         @req_window.add_text(quest.requirements[i].to_s, -1)
       elsif quest.type == 1
         quest_variable = $quest_variables[quest.variables[i]]
         if quest_variable != nil
           @req_window.add_text(quest.requirements[i].to_s, quest_variable.to_i, quest.values[i], quest.type)
         else
           @req_window.add_text("Not Found?", -1)
         end
       elsif quest.type == 2
         quest_switch = $quest_switches[quest.switches[i]]
         if quest_switch != nil
           @req_window.add_text(quest.requirements[i].to_s, quest_switch, quest.values[i], quest.type)
         else
           @req_window.add_text("Not Found?", -1)
         end
       elsif quest.type == 3
         quest_item = $data_items[quest.requirements[i]]
         if quest_item != nil
           @req_window.add_text(quest_item.name.to_s, $game_party.item_number(quest_item.id), quest.values[i], quest.type)
         else
           @req_window.add_text("Not Found?", -1)
         end
       end
     end
   end
 end
end
def help_window=(help_window)
 @help_window = help_window
 if self.active and @help_window != nil
   update_help
 end
end
def req_window=(req_window)
 @req_window = req_window
 if self.active and @req_window != nil
   update_help
 end
end
end
# End New Class

# New Class
#---------------------------#
# â—? Window Requirements â—? #
#---------------------------#
class Window_Requirements < Window_Base
def initialize
 super(0, 256, 640, 480-256)
 self.contents = Bitmap.new(width - 32, height - 32)
 self.contents.font.name = $fontface
 self.contents.font.size = $fontsize
 @full_text = []
 @amount = []
 @amount_needed = []
 @type = []
end
def add_text(text, amount, amount_needed = -1, type = 0)
 @full_text.push(text)
 @amount.push(amount)
 @amount_needed.push(amount_needed)
 @type.push(type)
 show_text
end
def clear_text
 @full_text = []
 @amount = []
 @amount_needed = []
 @type = []
end
def show_text
 self.contents.clear
 self.contents.font.color = normal_color
 for i in 0...@full_text.size
   x = 4 + i % 2 * (288 + 32)
   y = i / 2 * 32
   if @type[i] == 0
     self.contents.font.color = normal_color
     self.contents.draw_text(x, y, (self.width / 2) - 40, 32, @full_text[i], 0)
   elsif @type[i] == 1 or @type[i] == 3
     if @amount[i] >= @amount_needed[i]
       self.contents.font.color = Color.new(0, 255, 0, 255)
     else
       self.contents.font.color = Color.new(255, 0, 0, 255)
     end
     self.contents.draw_text(x, y, (self.width / 2) - 40, 32, @full_text[i], 0)
     self.contents.draw_text(x, y, (self.width / 2) - 40, 32, @amount[i].to_s + "/" + @amount_needed[i].to_s, 2)
   elsif @type[i] == 2
     if @amount[i] == true
       self.contents.font.color = Color.new(0, 255, 0, 255)
     else
       self.contents.font.color = Color.new(255, 0, 0, 255)
     end
     self.contents.draw_text(x, y, (self.width / 2) - 40, 32, @full_text[i], 0)
   end
 end
 self.visible = true
end
end
# End New Class

# New Class
#--------------------------#
# â—? Window Description â—? #
#--------------------------#
class Window_Description < Window_Base
def initialize
 super(0, 192, 640, 64)
 self.contents = Bitmap.new(width - 32, height - 32)
 self.contents.font.name = $fontface
 self.contents.font.size = $fontsize
end
def set_text(text, align = 0)
 if text != @text or align != @align
   self.contents.clear
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
   @text = text
   @align = align
 end
 self.visible = true
end
end
# End New Class

# Programming Aspects:

# New Class
#-----------------#
# â—? PRX_Quest â—? #
#-----------------#
class PRX_Quest
attr_accessor :name
attr_accessor :type
attr_accessor :description
attr_accessor :requirements
attr_accessor :values
attr_accessor :switches
attr_accessor :variables
attr_accessor :completed
attr_accessor :disabled
def initialize
 @name = ""
 @type = 0
 @description = ""
 @requirements = []
 @values = []
 @switches = []
 @switches = Array.new(5000, false)
 @variables = []
 @variables = Array.new(5000, 0)
 @completed = false
 @disabled = false
end
end
# End New Class

# Modified Class
#-------------------#
# â—? Scene Title â—? #
#-------------------#
class Scene_Title
def command_new_game
 $game_system.se_play($data_system.decision_se)
 Audio.bgm_stop
 Graphics.frame_count = 0
 $game_temp           = Game_Temp.new
 $game_system         = Game_System.new
 $game_switches       = Game_Switches.new
 $quest_switches      = Quest_Switches.new # New
 $game_variables      = Game_Variables.new
 $quest_variables     = Quest_Variables.new # New
 $game_self_switches  = Game_SelfSwitches.new
 $game_screen         = Game_Screen.new
 $game_actors         = Game_Actors.new
 $game_party          = Game_Party.new
 $game_troop          = Game_Troop.new
 $game_map            = Game_Map.new
 $game_player         = Game_Player.new
 $quest               = [] # New
 $game_party.setup_starting_members
 $game_map.setup($data_system.start_map_id)
 $game_player.moveto($data_system.start_x, $data_system.start_y)
 $game_player.refresh
 $game_map.autoplay
 $game_map.update
 $scene = Scene_Map.new
end
end
# End Modified Class

# Modified Class
#------------------#
# â—? Scene Save â—? #
#------------------#
class Scene_Save
def write_save_data(file)
 characters = []
 for i in 0...$game_party.actors.size
   actor = $game_party.actors[i]
   characters.push([actor.character_name, actor.character_hue])
 end
 Marshal.dump(characters, file)
 Marshal.dump(Graphics.frame_count, file)
 $game_system.save_count += 1
 $game_system.magic_number = $data_system.magic_number
 Marshal.dump($game_system, file)
 Marshal.dump($game_switches, file)
 Marshal.dump($quest_switches, file) # New
 Marshal.dump($game_variables, file)
 Marshal.dump($quest_variables, file) # New
 Marshal.dump($game_self_switches, file)
 Marshal.dump($game_screen, file)
 Marshal.dump($game_actors, file)
 Marshal.dump($game_party, file)
 Marshal.dump($game_troop, file)
 Marshal.dump($game_map, file)
 Marshal.dump($game_player, file)
 Marshal.dump($quest, file) # New
end
end
# End Modified Class

# Modified Class
#------------------#
# â—? Scene Load â—? #
#------------------#
class Scene_Load
def read_save_data(file)
 characters = Marshal.load(file)
 Graphics.frame_count = Marshal.load(file)
 $game_system         = Marshal.load(file)
 $game_switches       = Marshal.load(file)
 $quest_switches      = Marshal.load(file) # New
 $game_variables      = Marshal.load(file)
 $quest_variables     = Marshal.load(file) # New
 $game_self_switches  = Marshal.load(file)
 $game_screen         = Marshal.load(file)
 $game_actors         = Marshal.load(file)
 $game_party          = Marshal.load(file)
 $game_troop          = Marshal.load(file)
 $game_map            = Marshal.load(file)
 $game_player         = Marshal.load(file)
 $quest               = Marshal.load(file) # New
 if $game_system.magic_number != $data_system.magic_number
   $game_map.setup($game_map.map_id)
   $game_player.center($game_player.x, $game_player.y)
 end
 $game_party.refresh
end
end
# End Modified Class

# New Class
#----------------------#
# â—? Quest Switches â—? #
#----------------------#
class Quest_Switches
def initialize
 @data = []
 @data = Array.new(5000, false)
end
def [](switch_id)
 if switch_id <= 5000 and @data[switch_id] != nil
   return @data[switch_id]
 else
   return false
 end
end
def []=(switch_id, value)
 if switch_id <= 5000
   @data[switch_id] = value
   comp_count = 0
   for i in 0...$quest.size
     if $quest[i].type == 2
       for k in 0...$quest[i].requirements.size
         if @data[$quest[i].switches[k]] == true
           comp_count += 1
         end
       end
       if comp_count == $quest[i].requirements.size
         $quest[i].completed = true
       else
         $quest[i].completed = false
       end
     end
   end
 end
end
end
# End New Class

# New Class
#-----------------------#
# â—? Quest Variables â—? #
#-----------------------#
class Quest_Variables
def initialize
 @data = []
 @data = Array.new(5000, 0)
end
def [](variable_id)
 if variable_id <= 5000 and @data[variable_id] != nil
   return @data[variable_id]
 else
   return 0
 end
end
def []=(variable_id, value)
 if variable_id <= 5000
   @data[variable_id] = value
   comp_count = 0
   for i in 0...$quest.size
     if $quest[i].type == 1
       for k in 0...$quest[i].requirements.size
         if @data[$quest[i].variables[k]] != nil
           if @data[$quest[i].variables[k]] >= $quest[i].values[k]
             comp_count += 1
           end
         end
       end
       if comp_count == $quest[i].requirements.size
         $quest[i].completed = true
       else
         $quest[i].completed = false
       end
     end
   end
 end
end
end
# End New Class

# Modified Class
#------------------#
# â—? Game Party â—? #
#------------------#
class Game_Party
def gain_item(item_id, n)
 if item_id > 0
   @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
   # New
   comp_count = 0
   for i in 0...$quest.size
     if $quest[i].type == 3
       for k in 0...$quest[i].requirements.size
         if item_number($quest[i].requirements[k]) >= $quest[i].values[k]
           comp_count += 1
         end
       end
       if comp_count == $quest[i].requirements.size
         $quest[i].completed = true
       else
         $quest[i].completed = false
       end
     end
   end
   # End New
 end
end
end
# End Modified Class


To call the scene, use:
Code:
$scene = Scene_Quest.new


[Image: CallScript1.png]
This code defines a regular item quest:
Code:
$quest[1] = PRX_Quest.new # Sets the quest
$quest[1].name = "Food Search" # Gives it a name
$quest[1].type = 3 # Defines it as an item quest
$quest[1].description = "Find The Food" # Gives it a description
$quest[1].requirements = [1, 2, 3] # Sets the requirements to item IDs, in this case Potion, High Potion, Full Potion
$quest[1].values = [3, 2, 1] # Sets the amount of each item you need to succeed. In this case, 3 Potions, 2 High Potions, 1 Full Potion.


[Image: CallScript2.png]
This code defines a regular variable quest:
Code:
$quest[7] = PRX_Quest.new # Sets the quest, as always.
$quest[7].name = "Variable Quest" # Gives it a name
$quest[7].type = 1 # Defines it as a variable quest
$quest[7].description = "Variables!" # Gives it a description
$quest[7].requirements = ["VarA", "VarB"] # Labels the requirements.. this may say something like, ["Bugbears Killed:", "Locks Picked:"] or something.
$quest[7].values = [2, 2] # This defines how much of each requirement you need, in this case you need 2 VarA and 2 VarB, or 2 Bugbear's Killed and 2 Locks Picked.
$quest[7].variables = [1, 2] # This sets QuestVar IDs to the requirements. These IDs correspond with $quest_variables[ID]



[Image: CallScript4.png]
This code demonstrates how to use $quest_switches:
Code:
# $quest_switches[id] = true/false
$quest_switches[1] = true # Sets switch 1 to true.
$quest_switches[2] = false # Sets switch 2 to false.

And a screenshot of the default quest menu:
[Image: MenuShot1.png]
[Image: MenuShot2.png]
[Image: MenuShot3.png]
[Image: MenuShot4.png]
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updated version of Game_Guy's Quest log Lethrface 0 2,328 01-28-2012, 01:00 PM
Last Post: Lethrface
  Quest Book Zeriab 0 2,390 01-09-2009, 01:00 PM
Last Post: Zeriab
  Dragon Quest VII Class Changing System Sephirothtds 0 2,406 11-15-2007, 01:00 PM
Last Post: Sephirothtds
  Quest Script Samo the thief 0 2,216 03-12-2007, 01:00 PM
Last Post: Samo the thief
  Quest Script by SAMO Samo the thief 0 2,208 12-29-2006, 01:00 PM
Last Post: Samo the thief



Users browsing this thread: