Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Sign in to follow this  
corpsegirl

Dialog from text file

Recommended Posts

I didn't make this. IT is made to be compatible with the AMS

 

class Interpreter
 #--------------------------------------------------
 alias trebor_dial_command_101 command_101
 def command_101
   bool= trebor_dial_command_101
   $game_temp.message_text.gsub!(/\\[Dd]ial_pnj_ID\[([0-9]+)\]/) do
     $data_pnj[$1.to_i] != nil ? $game_temp.message_text=load_dial($data_pnj[$1.to_i]) : ""
   end
   $game_temp.message_text.gsub!(/\\[Dd]ial_story_ID\[([0-9]+)\]/) do
     $data_story[$1.to_i] != nil ? $game_temp.message_text=load_dial($data_story[$1.to_i]) : ""
   end
   if bool !=nil
     return bool
   end
 end
 #---------------------------------------------------
 def load_dial(str)  #str le message à transmettre type string
   @str=str.dup  # Enregistrement de la chaine originale
   @old_str=str.dup
   @command_array=[]
   @command_size=[]
   @command_trie=[]
   @com=[]
   @str=clear_com(@str)
   last_str=@old_str
   if str.size>=40
     nb = 40
     nb_ligne=(str.size/nb).ceil
     if nb_ligne>=4 
       last_str="Message trop long" 
     else
     for i in 1..nb_ligne
       deb_int=(nb*(i-1))
       fin_int=(nb*i)
       temp=@str[deb_int..fin_int]
       id_sp=temp.rindex(" ")
       if id_sp!=nil
         id=id_sp+(deb_int)
       else
         id =fin_int
       end
       str_g=@str[0..id]
       str_d=@str[(id+1)..(@str.size-1)]
       str_d==nil ? str_d="" : str_d=str_d
       @str=str_g+"\n"+str_d
     end
     for i in 0..@com.size-1
       deb_com=@com[i][1]
       nb_nl=@str[0..deb_com].count("\n")
       deb_com>1? str_fg=@str[0..deb_com+nb_nl-1] : str_fg=""
       deb_com>0? str_fd=@str[deb_com+nb_nl..@str.size] : str_fd=@str
       str_fg==nil ? str_fg="" : str_fg=str_fg
       str_fd==nil ? str_fd="" : str_fd=str_fd

       @str=str_fg+@com[i][0]+str_fd
     end
     last_str=@str
     end
   end
   return last_str # renvoie la chaine non nettoyée, découpée ou non
 end
 #---------------------------------
 def clear_com(str)
   begin
     last_text = str.clone
     str.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
   end until str == last_text
   str.gsub!(/\\[Nn]\[([0-9]+)\]/) do
     $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
   end
   str.gsub!(/\\[Mm]\[([0-9]+)\]/) do
     $data_enemies[$1.to_i] != nil ? $data_enemies[$1.to_i].name : ""
   end
   str.gsub!(/\\[Pp]rice\[([0-9]+)\]/) do
     $data_items[$1.to_i] != nil ? $data_items[$1.to_i].price : ""
   end
   str.gsub!(/\\[Cc]lass\[([0-9]+)\]/) do
     $data_classes[$data_actors[$1.to_i].class_id] != nil ? $data_classes[$data_actors[$1.to_i].class_id].name : ""
   end
   str.gsub!(/\\[Mm]ap/) do
     $game_map.name    != nil ? $game_map.name    : ""
   end
   count_command(/\\[%]/,str)
   count_command(/\\[Ff]\[(.*?)\]/,str)
   count_command(/\\[Nn]ame\[(.*?)\]/,str)
   count_command(/\\[Pp]\[([-1,0-9]+)\]/,str)
   count_command(Regexp.new('/\\[Cc]\[([0123456789ABCDEF#]+)\]/'),str)
   count_command(/\\[Gg]/,str)
   count_command(/\\[ss]\[([0-9]+)\]/,str)
   count_command(/\\[Aa]\[(.*?)\]/,str)
   count_command(/\\[Cc]\[([0-9]+)\]/,str)
   count_command(/\\[Tt]\[(.*?)\]/,str)
   count_command(/\\[.]/,str)
   count_command(/\\[|]/,str)
   count_command(/\\[>]/,str)
   count_command(/\\[<]/,str)
   count_command(/\\[!]/,str)
   count_command(/\\[~]/,str)
   count_command(/\\[Ee]\[([0-9]+)\]/,str)
   count_command(/\\[ii]/,str)
   count_command(/\\[Oo]\[([0-9]+)\]/,str)
   count_command(/\\[Hh]\[([0-9]+)\]/,str)
   count_command(/\\[bb]\[([0-9]+)\]/,str)
   count_command(/\\[Rr]\[(.*?)\]/,str)
   @command_trie=@command_array.sort {|x,y| x <=> y }
   for i in 0..@command_trie.size-1
     deb_com=@command_trie[i]
     j=@command_size[@command_array.index(deb_com)]
     fin_com=deb_com+j-1
     str_com=@old_str[deb_com..fin_com]
     if str_com[-1,1]!="]"
       str_com.chop!
     end
     @com.push([str_com,deb_com])
   end
   return str
 end
 #-----------------------------------------------------
 def count_command(reg,str)
   it = 0
   for i in 0..@old_str.size
     if @old_str.index(reg,it) !=nil 
       id=@old_str.index(reg,it)
       it=id+1
       @command_array.push(id)
       last_str_size=str.size
       str.sub!(reg, "")
       diff=last_str_size-str.size
       @command_size.push(diff)
     end
   end
 end
 #-----------------------------------------------------
end
#==========================================================================
class Scene_Title
 alias dial_main main
 def main
   dial_main
   #$data_pnj =create_data("text/pnj.txt")
   $data_story = create_data("text/story.txt")
 end
 #--------------------------------------------------------------------------
 def create_data(filename)
   data =nil
   if FileTest.exist?(filename)
     filestr= IO.readlines(filename)
     data=[]
     it = 0
     for line in filestr
       phrase = line.split('\244')
       if phrase.length>1
         data.push(phrase[1].chomp)
         it+=1
       else
         if phrase[0][0,1] !='#' and it>=1
           data[it-1]+=phrase[0].chomp 
         else
           next
         end
       end
     end
   end
   return data
 end
 #--------------------------------------------------------------------------
end

Now the text file's constraints:

- 2 files to create in Data folder: PNJ.txt & story.txt

- You Must Save in UTF-8 in case you'll use accents or Special letter else RPG MAker won't display them.

- One message on One Line.

- Each message must begin by: Idvalue\244

the first begin with this ID value : 0.

- Of course, Sort IDs in Crescent Order^^...

 

The event message command :

- For a non-Playable Character: (I mean not very important dialogues)

Dial_pnj_ID[n°id]

- For a Story Dialogue:

Dial_story_ID[n°id]

 

There hasn't been support for this in ages. I get errors when I use it but it might be me and not an issue with the script itself. No one else seemed ot have any errors where I found it. Again, it hasn't bee touched in ages that I know of.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...