Save Script for RMX-OS [Resolved]

Started by ojp2010, August 30, 2010, 11:43:49 pm

Previous topic - Next topic

ojp2010

August 30, 2010, 11:43:49 pm Last Edit: September 02, 2010, 12:06:40 pm by ojp2010
I am using the following script, quest script, and I can't seem to make a script that will allow RMX-OS to save the variables to the database, like in game_guys quest log <http://forum.chaos-project.com/index.php/topic,3689.0.html>

I need it to save what quest the player has and what quest are completed, if it is even compatible with RMX-OS.

Spoiler: ShowHide
#==============================================================================
#==============================================================================
#                            Tornado Quest Book
#                               Version 1.0
#                              Author: Storm
#                      http://rpgxpultimate.darkbb.com
#
# Instructions:
# Place the script above main.
#
# Use $scene = Scene_QuestBook.new to call it.
#
# Use $game_party.add_quest(id) to add quest.
#
# Use $game_party.delete_quest(id) to delete quest.
#
# Use $game_party.finish_quest(id) to finish quest.
#
# Use $game_party.unfinish_quest(id) to unfinish quest.
#
# In condition branch, at the script tab enter $game_party.quest_complete?(id)
# to check if that quest have completed yet.
#
# Features:
# Can custom menus name.
# Opacity configable.
# Customable complete quest color.
# Customable incomplete quest color.
# Able to set return scene.
# Auto replace text in the message.
# Replacements configable.
#
# Compatibility:
# Most of things. (Haven't test to any yet. :P)
#
# Credits and Thanks:
# Storm     - For making it.
# Game_Guy  - For teach me how to use array.
#
#==============================================================================
#==============================================================================
module TNDqb
 #============================================================================
 # START CONFIG
 #============================================================================
 
 #============================== General Config ==============================
 # General Config.
 #============================================================================
 QB_Name     = "Quest Book" #Quest Book name
 Author_Name = "Author" #Author name
 Title_Name  = "Title" #Title name
 Reward_Name = "Reward" #Reward name
 Status_Name = "Status" #Reward name
 Complete    = "Complete" #Complete name
 Incomplete  = "Incomplete" #Incomplete name
 Unknown     = "???" #Unknown Name
 Opacity     = 200 #Windows Opacity
 Screen      = 1 #(0 = black,1 = map,"quoted string" = picture)
 
 Cmp_Color   = Color.new(0, 255, 0, 255) #Complete color
 Incmp_Color = Color.new(255, 0, 0, 255) #Incomplete Color
 
 Return      = Scene_Map #Return Scene
 
 #================================ Ignore Part ===============================
 # Ignore Parts Under This.
 #============================================================================
 Quest       = []
 
 #============================ Replacement Config ============================
 # Replacements, this will auto replace texts in your message
 #
 # Replace = ["text","replace"]
 # NOTE: Maximum of replaces is 10. Replaces cannot be add or remove.
 #       Cannot include {name1}, {name2}, {name3} and {name4}
 #
 #       Completed Replacements: (Do not add)
 #       {name1} = 1st actor's name
 #       {name2} = 2nd actor's name
 #       {name3} = 3rd actor's name
 #       {name4} = 4th actor's name
 #============================================================================
 Replace1 = ["",""]
 Replace2 = ["",""]
 Replace3 = ["",""]
 Replace4 = ["",""]
 Replace5 = ["",""]
 Replace6 = ["",""]
 Replace7 = ["",""]
 Replace8 = ["",""]
 Replace9 = ["",""]
 Replace10 = ["",""]
 
 #=============================== Quest Config ===============================
 # Config quests here.
 #
 # Quest[id] = ["title","author's name","text","reward"]
 #============================================================================
 
 #PART 1
 Quest[1]    = ["Missing Puppy","Mr.Bean","Mr.Bean wants you to go and find his missing puppy.","1000 G"]
 Quest[2]    = ["Mountain Explore","Tom","Tom asked {name1} to go and explore Mt.River.","A thing (What thing?)"]
 
 #============================================================================
 # END CONFIG
 #============================================================================
end

#====================
# Game_Party
#====================
class Game_Party
 attr_accessor :quest
 attr_accessor :qComplete
 alias tnd_qb_init initialize
 def initialize
   @quest = []
   @qComplete = []
   tnd_qb_init
 end
 
 def add_quest(id)
   msg = TNDqb::Quest[id]
   return if msg == nil
   unless @quest.include?(id)
     @qComplete.delete(id)
     @quest.push(id)
   end
 end
 
 def delete_quest(id)
   msg = TNDqb::Quest[id]
   return if msg == nil
   if @quest.include?(id)
     @qComplete.delete(id)
     @quest.delete(id)
   end
 end
 
 def finish_quest(id)
   msg = TNDqb::Quest[id]
   return if msg == nil
   if @quest.include?(id)
     @qComplete.push(id)
   end
 end
 
 def unfinish_quest(id)
   msg = TNDqb::Quest[id]
   return if msg == nil
   if @quest.include?(id)
     @qComplete.delete(id)
   end
 end
 
 def quest_complete?(id)
   return if id == nil
   msg = TNDqb::Quest[id]
   return if msg == nil
   if @qComplete.include?(id)
     return true
   else
     return false
   end
 end
 
end

#====================
# Bitmap
#====================
class Bitmap
 def format_text(text, width)
   words = text.split(' ')
   return words if words.size == 1
   result, current_text = [], words.shift
   words.each_index {|i|
       if self.text_size("#{current_text} #{words[i]}").width > width
         result.push(current_text)
         current_text = words[i]
       else
         current_text = "#{current_text} #{words[i]}"
       end
       result.push(current_text) if i >= words.size - 1}
   return result
 end
end

#====================
# Window_QuestTitle
#====================
class Window_QuestTitle < Window_Base
 def initialize
   super(0, 0, 640, 60)
   self.back_opacity = TNDqb::Opacity
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 def refresh
   self.contents.clear
   self.contents.font.color = normal_color
   self.contents.font.size = 25
   cx = contents.text_size(TNDqb::QB_Name).width
   self.contents.draw_text(0, 0, cx, 37, TNDqb::QB_Name)
 end
end

#====================
# Window_QuestMain
#====================
class Window_QuestMain < Window_Base
 def initialize
   super(35, 100, 380, 340)
   self.back_opacity = TNDqb::Opacity
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 def refresh
   return if @quest_id == nil
   msg = TNDqb::Quest[@quest_id]
   return if msg == nil
   self.contents.clear
   self.contents.font.size = 20
   t = self.contents.text_size(TNDqb::Title_Name+": ").width
   t2 = self.contents.text_size(TNDqb::Author_Name+": ").width
   t3 = self.contents.text_size(TNDqb::Reward_Name+": ").width
   t4 = self.contents.text_size(TNDqb::Status_Name+": ").width
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, self.width, 32, TNDqb::Title_Name+": ")
   self.contents.draw_text(0, 32, self.width, 32, TNDqb::Author_Name+": ")
   self.contents.draw_text(0, 250, self.width, 32, TNDqb::Reward_Name+": ")
   self.contents.draw_text(0, 282, self.width, 32, TNDqb::Status_Name+": ")
   self.contents.font.color = normal_color
   self.contents.draw_text(t, 0, self.width, 32, msg[0])
   self.contents.draw_text(t2, 32, self.width, 32, msg[1])
   
   @text = msg[2]
   
   @text = @text.gsub(TNDqb::Replace1[0], TNDqb::Replace1[1])
   @text = @text.gsub(TNDqb::Replace2[0], TNDqb::Replace2[1])
   @text = @text.gsub(TNDqb::Replace3[0], TNDqb::Replace3[1])
   @text = @text.gsub(TNDqb::Replace4[0], TNDqb::Replace4[1])
   @text = @text.gsub(TNDqb::Replace5[0], TNDqb::Replace5[1])
   @text = @text.gsub(TNDqb::Replace6[0], TNDqb::Replace6[1])
   @text = @text.gsub(TNDqb::Replace7[0], TNDqb::Replace7[1])
   @text = @text.gsub(TNDqb::Replace8[0], TNDqb::Replace8[1])
   @text = @text.gsub(TNDqb::Replace9[0], TNDqb::Replace9[1])
   @text = @text.gsub(TNDqb::Replace10[0], TNDqb::Replace10[1])
   
   actor = $game_party.actors[0]
   @text = @text.gsub("{name1}", actor.name)

   
   draw_msg(@text, 0, 64)
   
   if $game_party.qComplete.include?(@quest_id)
     self.contents.draw_text(t3, 250, self.width, 32, msg[3])
     self.contents.font.color = TNDqb::Cmp_Color
     self.contents.draw_text(t4, 282, self.width, 32, TNDqb::Complete)
   else
     self.contents.draw_text(t3, 250, self.width, 32, TNDqb::Unknown)
     self.contents.font.color = TNDqb::Incmp_Color
     self.contents.draw_text(t4, 282, self.width, 32, TNDqb::Incomplete)
   end
 end
 def draw_msg(msg, x, y)
   text = self.contents.format_text(msg, 380)
   text.each_index {|i|self.contents.draw_text(x, y + i*32, 544, 32, text[i])}
 end
 def set_quest(id)
   return if @quest_id == id
   @quest_id = id
   refresh
 end
end

#====================
# Scene_QuestBook
#====================
class Scene_QuestBook
 def main
   if TNDqb::Screen.is_a?(Integer)
     if TNDqb::Screen == 1
       @back = Spriteset_Map.new
     end
   else
     @back = Sprite.new
     @back.bitmap = RPG::Cache.picture(TNDqb::Screen)
   end
   
   #Command window setup
   @quest = $game_party.quest
   @msg = []
   @quest.each {|i|
     @msg.push(TNDqb::Quest[i][0])
   }
   @msg = [""] if @msg.size < 1
   
   #Create command window
   @command_window = Window_Command.new(180, @msg)
   @command_window.x = 460
   @command_window.back_opacity = TNDqb::Opacity
   @command_window.height = 420
   @command_window.y = 60
   j = 0
   @quest.each{|i|
   if $game_party.qComplete.include?(i)
     @command_window.draw_item(j, TNDqb::Cmp_Color)
   end
   j += 1}
   
   #Make main windows
   @title = Window_QuestTitle.new
   @main = Window_QuestMain.new
   
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     #Update windows and inputs
     update
     inputUpdate
     #Break if scene is not Scene_QuestBook
     if $scene != self
       break
     end
   end
   Graphics.freeze
   
   #Dispose windows
   if TNDqb::Screen == 1
     @back.dispose
   end
   @command_window.dispose
   @title.dispose
   @main.dispose
 end
 
 def command_refresh
   @newIndex = @command_window.index
   @msg = []
   @command_window.dispose
   @command_window = nil
   @quest.each {|i|
   @msg.push(TNDqb::Quest[i][0])
   }
   @msg = [""] if @msg.size < 1
   @command_window = Window_Command.new(180, @msg)
   @command_window.x = 460
   @command_window.back_opacity = TNDqb::Opacity
   @command_window.height = 420
   @command_window.y = 60
   @command_window.index = @newIndex
   j = 0
   @quest.each{|i|
   if $game_party.qComplete.include?(i)
     @command_window.draw_item(j, TNDqb::Cmp_Color)
   end
   j += 1}
 end
 
 def inputUpdate
   if Input.trigger?(Input::B)
     #Play Cancel SE
     $game_system.se_play($data_system.cancel_se)
     #Return to set scene
     $scene = TNDqb::Return.new
   elsif Input.trigger?(Input::C)
     #Play Decision SE
     $game_system.se_play($data_system.decision_se)
     #Refresh quest data
     @main.set_quest(@quest[@command_window.index])
     #Goto command_refresh
     command_refresh
   end
 end
 
 def update
   #Updates
   @command_window.update
   @title.update
   @main.update
 end
end

[Luke]

For Blizz's sake. Can't you just observe other topics and learn something instead of posting requests without reading ALL THE SIMILAR THREADS first?
module RMXOS
  module Options
    SAVE_DATA[Game_party].push('@quest')
    SAVE_DATA[Game_party].push('@qComplete')
  end
end

Should work. If it doesn't, search for other variables in the script that have to be saved.

ojp2010

Oh sorry now you trolling my post darn it and this on I forgot to mark as resolved.