The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Raven War on July 07, 2008, 03:35:07 AM

Title: [RESLOVED]Help with quest script...
Post by: Raven War on July 07, 2008, 03:35:07 AM
[spoiler]=begin

Quest Script v2.2 Free of Bugs by Samo, the thief.

I removed the Enournmous header and there is a more simple one.

Ok, this is posted because there was too much people that had the version 2.1 and it had too much bugs.
The thing is that that version was my first script. Now i have advanced greatly much in scripting, and
there is this new and refixed v.

~I see the script at the same than last v., what does it have of new?

-Bugs removed when saving and loading
-Advanced Text Paragrapher included, now you only do a long line and it will
be automatically paragraphed.
-More simple way to create quests.
-Removed stupid global variables
-Faster.


~How to install this?
-Add this in a new slot above Main
-Go to Scene_Title and add the lines between ADDED

    $game_player        = Game_Player.new
    #-----------------ADDED------------------------
    $quest = {}
    #-----------------ADDED-----------------------
    $game_party.setup_starting_members

~Come on, how to create a quest?
 
  At the start of your game in a call script
 
  -$quest[x] - Quest.new(name, image, line, difficulty, state)
 
  x will be a number.
 
~Great, but, the quest is always the same, I want to update it, how?
  -$quest[x].parameter = value
 
  parameter will be one of these next:
 
  name
  image
  state_number
  difficulty_level
  line
 
  value will be the next value of the parameter.
 
~Do you have something more to say?
  -Yes, if you find a bug report it.
  -If you like this new version, please, say it.
  -If you have a suggestion, please, post it.
 
  Good luck!
               Samo, the thief.
=end




#8 and 9 colors were done by me, and i replaced the def in window_base.
# if you want a new color, just add another when statement and copy the line.
#the color can be created more easily whith the script generator of Dubealex.




#Samo's Quest script begins
class Window_Base
#--------------ADDED---------------------
  def text_color(n)
    case n
    when 0
      return Color.new(255, 255, 255, 255)
    when 1
      return Color.new(128, 128, 255, 255)
    when 2
      return Color.new(255, 128, 128, 255)
    when 3
      return Color.new(128, 255, 128, 255)
    when 4
      return Color.new(255, 39, 39, 255)
    when 5
      return Color.new(255, 128, 255, 255)
    when 6
      return Color.new(255, 255, 128, 255)
    when 7
      return Color.new(192, 192, 192, 255)
    when 8   # Celeste EXTRA EASY
      return Color.new(0,255,255,255)
    when 9   #rojo EXTRA HARD
      return Color.new(155,0,80,255)
    when 10   #complete
      return Color.new(62,55,0,235)
    when 11 #Primary
      return Color.new(232,0,0,255)
    else
      normal_color
    end
  end
#--------------ADDED---------------------
 
  end

 
 
 
 
 
 
 
#==============================================================================
# ? Window_Command_Quest
# created for complete color feature
#------------------------------------------------------------------------------

class Window_Command_Quest < Window_Selectable
  #--------------------------------------------------------------------------
    def initialize(width, commands)
    super(0, 0, width, commands.size * 32 + 32)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    self.contents.font.name = 'Arial'
    self.contents.font.size = 28
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  #-----------------ADDED-----------------------------------------------
  def complete_item(index)
    draw_item(index, text_color(10))
  end
  #---------------------------------------------------------------------
  def just_finish_item(index)
    draw_item(index, text_color(6))
  end
end
#Command_Quest ends here, it doesn't replace the original window_command.








#---------------------------------------------------
#===================================================
# - CLASS Scene_Quest Begins
#===================================================
#---------------------------------------------------
class Scene_Quest

#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
  def initialize(quest_index = 0)
    @quest_index = quest_index
    $MAP_BACKGROUND = true      #Map Background. True or false? set it as you wish.
    @quest_options = []
  end
 
  #------------------------------------------------
 
def main
  if $MAP_BACKGROUND
    @spriteset = Spriteset_Map.new
    end
    @window5 = Window_Quest_Diary.new
    @window5.z= 300
 
    for i in $quest.keys.sort
       name = $quest[i].name
       @quest_options.push(name)
     end
    @command_window = Window_Command_Quest.new(160, @quest_options)
    @command_window.index = @quest_index
    @command_window.z = 250
    @command_window.height = 150
    for i in $quest.keys.sort
     if $quest[i].state_number == 1
      @command_window.disable_item(i)
     elsif $quest[i].state_number == 4
      @command_window.complete_item(i)
    elsif  $quest[i].state_number == 3
      @command_window.just_finish_item(i)
   end   
end
Graphics.transition (20)
    loop do
      Graphics.update
      Input.update
     update
      if $scene != self
        break
      end
    end
    Graphics.transition
    Graphics.freeze
    @command_window.dispose
    @quest_options.clear
    @window5.dispose
  if $MAP_BACKGROUND
    @spriteset.dispose
  end
   $quest_seen = false
  end
#---------------------------------------------------------------------------------

#---------------------------------------------------------------------------------
  def update
    @command_window.update
    if @command_window.active
      update_command
      return
    end
    if Input.trigger?(Input::B)
      if @command_window.active == false
        $game_system.se_play($data_system.cancel_se)
        @command_window.active = true
        @window1.dispose
      @window2.dispose
      @window3.dispose
      @window4.dispose
          else
      $game_system.se_play($data_system.cancel_se)

#if you want that when you exit it calls the menu, just put a # before
#  $scene = Scene_Map.new and delete the # in $scene = Scene_Menu.new
      #$scene = Scene_Menu.new
      $scene = Scene_Map.new
        end

      return
    end
  end
#---------------------------------------------------------------------------------
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
     
      for i in $quest.keys.sort
        case @command_window.index
          when i
            if $quest[i].state_number == 1
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          $game_system.se_play($data_system.decision_se)
           $ACTUAL_QUEST = $quest[i]
          update_quest
      end
    end
  end
  end
 
  def update_quest
    @command_window.active = false
    @window1 = Window1.new
    @window2 = Window2.new
    @window3 = Window_Difficulty.new
    @window4 = Window_Status_Quest.new
    @window1.z= 220
    @window2.z= 200
    @window3.z= 230
    @window4.z= 230
    end

end


class Window1 < Window_Base

#---------------------------------------------------------------------------------     
  def initialize
    super(120, 10, 520,100)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Comic Sans MS"
    self.contents.font.size = 40
    self.contents.font.color = text_color(4) #color of name
    self.contents.draw_text(50, 20, 400, 40, $ACTUAL_QUEST.name)
  end


  #--------------------------------

#--------------------------------
end



class Window2 < Window_Base

#---------------------------------------------------------------------------------     
  def initialize
    super(80, 110, 540,340)


    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = 26
    self.contents.font.color = text_color(0) # color of quest lines
    src_rect = Rect.new(0, 0, 500, 100) # pictures can be 480x80
    image = RPG::Cache.picture($ACTUAL_QUEST.image)
    self.contents.blt(10, 10, image, src_rect, 255)
    #self.contents.draw_text(20, 100, 500, 33, $ACTUAL_QUEST.line1)
   paragraph = str_paragraph($ACTUAL_QUEST.line,500)
    draw_paragraph(20,100,500,33,paragraph)
  end

end
#---------------------------------------------------------------------------------   
# this window puts the difficulty.
class Window_Difficulty < Window_Base
  def initialize
    super(50, 400, 300, 80)


    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = 26
    self.opacity = 225
    self.contents.font.color = system_color
    self.contents.draw_text(10, 2, 80, 33, "Difficulty: ")
    self.contents.font.color = text_color($ACTUAL_QUEST.difficulty[0])
    self.contents.draw_text(100, 2, 100, 33, $ACTUAL_QUEST.difficulty[1])
  end
end


#---------------------------------------------------



class Window_Status_Quest < Window_Base
  def initialize
    super(400, 400, 240, 80)


    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = 26
    self.opacity = 225
    self.contents.font.color = system_color
    self.contents.draw_text(10, 2, 80, 33, "Status: ")
    self.contents.font.color = text_color(0)
    self.contents.draw_text(100, 2, 100, 33, $ACTUAL_QUEST.state)
  end

end
#---------------------------------------------------



class Window_Quest_Diary < Window_Base
  def initialize
    super(490, 5, 150, 60)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = 26
    self.opacity = 225
    self.contents.font.color = text_color(4)
    self.contents.draw_text(0, 0, 100, 33, "Quest Diary")
  end

end


#______________________________________________________________________________
#______________________________________________________________________________
#================================================================
#================================================================
#================================================================
#QUEST CLASS BY SAMO
#The main proccess. This creates the quests and returns their name, lines, etc.
#Only the #EDITABLE can be modified. Don't touch something else.
#================================================================
#================================================================
#================================================================
#______________________________________________________________________________
#______________________________________________________________________________




class Quest

attr_accessor :name
attr_accessor :image
attr_accessor :line
attr_reader :difficulty_level
attr_reader :state_number
attr_reader :difficulty
attr_reader :state

#-----------------------------------------------------
  def initialize(name, image, line, difficulty_level, state_number)
    @name = name
    @image = image
    @line = line
    @difficulty_level = difficulty_level
    set_difficulty_name
    @state_number = state_number
    set_state_name
  end
 
#-----------------------------------------------------
  def set_state_name#EDITABLE  change the strings and if you want add another
    #when statement

    case @state_number
          when 0
      @state = "------"
          when 1
      @state = "Active"
          when 2
      @state = "Complete"
     
    end
  end
#-----------------------------------------------------     
  def set_difficulty_name
  case    @difficulty_level#EDITABLE#case of the level of difficulty. To add another difficulty
                #just put another when statement and copy the line. the values are
                #  [color, "name of difficulty"]
      when 0    #Nothing
        @difficulty = [0, " "]
      when 1    #EXTRA EASY
         @difficulty = [8, "Very Easy"]
      when 2    #EASY
         @difficulty = [4, "Easy"]
      when 3    #NORMAL
         @difficulty = [3, "Normal"]
      when 4    #HARD
         @difficulty = [2, "Hard"]
      when 5    #EXTRA HARD
         @difficulty = [9, "Extra Hard"]
       end
     end
def name
  if @state_number == 1
    return '----'
  else
    return @name
  end 
end
     
def state_number=(value)
  @state_number = value
  set_state_name
end 

def difficulty_level=(value)
  @difficulty_level = value
  set_difficulty_name
end 

   
end


#-----THE FINAL END-------------

class Scene_Save < Scene_File

alias samo_new_save write_save_data

def write_save_data(file)
    samo_new_save(file)
    Marshal.dump($quest, file)
  end
end


class Scene_Load < Scene_File

alias samo_new_load read_save_data

def read_save_data(file)
      samo_new_load(file)
      $quest = Marshal.load(file)

end
end


#---------------


=begin

ATP(Advanced Text Paragrapher) V1.0 by Samo, The thief

Ok, Something of The Scripters do normally to draw a text in form of a paragraph is
doing an array [] that contains each line. The Time Has come For
This Microsoft Word Effect!
This Script Just need a Long String and it will paragraph it!

How to call it?

   paragraph = str_paragraph(string, width of the paragraph.)
   
   Example :
   
   @my_paragraph = str_paragraph("La la la la la la la la la , This is a Looooong Strriiiing!", 120)
   

Returns an Array with each line separately.

How to draw it?

   draw_paragraph(x,y,width,height, paragraph)

width and height for each line, not for the paragraph.

       .::-NOTE-::.
       
  If you put a ' ^ '(must be between spaces), the text will pass to the next line.
  This Symbol Won't be drawed.
 
  Reminder: Always use '' instead of ""! It works faster!

=end


class Window_Base < Window
  #--------------------------------------------------
  def str_paragraph(str_old, width)
    temp_str = '' 
    str = '' + str_old
    words = []       
    size = 0
    str_size = 0
    #
    while ((c = str.slice!(/./m)) != nil)
     temp_str += c
     str_size += 1
     if c == ' '
       words.push(temp_str)
       temp_str = ''
     end
     if str.size == 0
       words.push(temp_str)
       temp_str = ''
      end
    end 
    lines = []
    for i in 0...words.size
      word = words[i]
      if word == '^ '
        lines.push(temp_str)
        temp_str = ''
        next
      end
      temp_str += word
      size = contents.text_size(temp_str).width
      if size > width - contents.text_size(' ').width
        for i in 1..word.size
          temp_str = temp_str.chop
        end
        lines.push(temp_str)
        temp_str = ''
        temp_str += word
      end
    end
    words = words.compact
    if temp_str != ''
      lines.push(temp_str)
    end
   return lines
end
#---------------------------------------------------------------------
def draw_paragraph(x,y,width,height,lines,align = 0)
   for i in 0...lines.size
     self.contents.draw_text(x, y + i * self.contents.font.size + 1, width, height, lines[i], align)
   end
end 
#-----------------------------------------------------------------
end
[/spoiler]

Okay, that's Samo's quest script for XP. Following the instructions, I made a self-terminating parrallel process event adding the quest like this to activate it:

$quest[1] = Quest.new('Test', 'Quest',
'This is a test', 1, 1)


but, whenever I try to open the log screen using the S key through a parrallel event, I get this error:

Script 'Samo Quest Script' line 144: TypeError occured.
Cannot convert nil into string


And here's line 144 for quick reference:

self.contents.draw_text(rect, @commands[index])

Anyone know what I'm doing wrong?
Title: Re: Help with quest script...
Post by: modern algebra on July 08, 2008, 03:07:40 AM
It is likely because you split the arguments into two lines. Try this:

a = 'Test'
b = 'Quest'
c = 'This is a test'
$quest[1] = Quest.new (a, b, c, 1, 1)
Title: Re: Help with quest script...
Post by: Raven War on July 08, 2008, 05:37:46 AM
Still get the same thing.

When I booted up the original script, there was an error with the font size and fone face, which I editted to fix, but it leads me to believe that the fact that it was int here to begin with means taht this script has one or two parts that don't work in it. If that's the case, is there anything I can do with my limited knowledge of scripting to fix it?

And, if it can't be fixed, are there any other quest log scripts I can use? I believe I saw one on this site, but I think it was only for one main quest, and I will have many quests I wish to list.
Title: Re: Help with quest script...
Post by: modern algebra on July 08, 2008, 11:37:38 AM
Are you using PK?

The only reason I can think of to cause that error is if you have a quest without a name. Since that isn't the problem, I can't really think of anything that would be causing it, unless you have called a second quest  :'(

Sorry. See if the error still occurs without initializing your first quest.
Title: Re: Help with quest script...
Post by: Raven War on July 08, 2008, 04:01:29 PM
If you mean not capitolizing the 'a = 'Test'', when I tested itout, nothing but 'Quest.new' was capitolized, so that isn't the problem. And I'm not using PK. Man, this script is becoming more trouble than its worth...
Title: Re: Help with quest script...
Post by: modern algebra on July 08, 2008, 11:03:06 PM
No, that's not what I was saying. The name is the first argument, so 'Test' in your case. The error looks like it is occurring because the array @commands has a nil element in it, but from my brief overview of the script, that array is garnered by this:


    for i in $quest.keys.sort
       name = $quest[i].name
       @quest_options.push(name)
     end


which would imply that

$quest[i].name == nil for some i


. If you could, place just before those lines:

p $quest

and tell me what you get.
Title: Re: Help with quest script...
Post by: Raven War on July 09, 2008, 02:08:27 AM
Okay, didn't understand a word you, err, typed, but this is what came up:

{1=>#<Quest:0x12fabc0 @state="Active", @name="test", @difficulty_level=1, @line="this is a test", @state_number=1, @image="Quest", @difficulty=[8, "Very Easy"]>}

And then, the error.
Title: Re: Help with quest script...
Post by: modern algebra on July 09, 2008, 11:08:23 AM
Okay, well then we can try something else. Right below this part of the script:




class Window_Command_Quest < Window_Selectable
  #--------------------------------------------------------------------------
    def initialize(width, commands)
    super(0, 0, width, commands.size * 32 + 32)
    @item_max = commands.size
    @commands = commands


put p @commands.

You can delete the p $quest now though - it wasn't helpful.
Title: Re: Help with quest script...
Post by: Raven War on July 09, 2008, 05:21:32 PM
All that comes up is

"[----]"
Title: Re: Help with quest script...
Post by: modern algebra on July 10, 2008, 12:25:03 AM
Ok, well I imagine the script is taking the index of the quests and sending them in as the index of the command window. For now, see if the error still occurs if you add this line in at around line 141:


    return if index >= @commands.size


so that the method looks like this:


  def draw_item(index, color)
    return if index >= @commands.size
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end


It's just a quick fix at best and doesn't fix the actual problem, but it is hard to read that script and so that's as far as I will go if it works. If it doesn't work, I'll actually read the script <sigh>
Title: Re: Help with quest script...
Post by: Raven War on July 10, 2008, 01:21:46 AM
Well, while it does fix the error, it causes the script not to work beyond the menu part of it.... This thing's a hassle.

Thanks for your help, but you don't have to go any further into this unless you actually want to. I have stopped working on the project I once required this script for for two reasons: 1) I got VX and am now tinkering around with that. 2) The project was going to be in the style of ORPGs, and by the time it was finished, RPG Maker 123456 would have been released :D

Again, thank you, but I don't wish to trouble you with it anymore. Afterall, I got a better one for use with VX- yours! :D
Title: Re: [RESLOVED]Help with quest script...
Post by: modern algebra on July 10, 2008, 01:30:15 AM
 :P

Good to hear