Introduction
I did this years ago, but recreated it per a request. This script acts in place of a show_text command, reading an outside file and rendering its contents in a message box.
It can read from Txt files in a specified directory, or from converted rxdata files within the Data folder. Please note, only files encrypted into .rxdata format will properly compress and encrypt within the Data folder if you choose to compress\encrypt a final encrypted game. Text files do not encrypt and must be sent with the final Game.rgssad product.
For those interested in converting their files into .rxdata format, I included two additional script calls that will convert text files to and from .rxdata format.
Demo
Meh... not this time
Script
Here ya go
Code:
#==============================================================================
# ** Message Text from Files
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 04-12-2016
# RGSS / RMXP
#==============================================================================
#
# INTRODUCTION:
#
# I did this years ago, but recreated it per a request. This script acts
# in place of a show_text command, reading an outside file and rendering
# its contents in a message box.
#
# It can read from Txt files in a specified directory, or from converted
# rxdata files within the Data folder. Please note, only files encryp-
# ted into .rxdata format will properly compress and encrypt within the
# Data folder if you choose to compress\encrypt a final encrypted game.
# Text files do not encrypt and must be sent with the final Game.rgssad
# product.
#
# For those interested in converting their files into .rxdata format, I
# included two additional script calls that will convert text files to
# and from .rxdata format.
#
#
#------------------------------------------------------------------------------
#
# NOTES ON USAGE:
#
# As stated above, this system will work with normal text files or files
# changed into .rxdata format. The .rxdata files must be kept within the
# game's Data while the .txt format files must be held within a folder
# as set by a specified directory. The name of that folder is set by the
# script's one configurable value: MTFF_TXTFOLDER. Right now, that value
# is currently set to a folder named Text (imaginative, eh?).
#
#
#------------------------------------------------------------------------------
#
# SCRIPT COMMANDS:
#
# messagefile(filename)
# * This command reads a .txt/.rxdata file from its location and calls
# the show message command to render it.
#
# simple_txt_to_rgss(filename)
# * This command reads a text file from the specified text file folder
# and converts it into an .rxdata file within the Data folder. It is
# a destructive call and will erase any previously made .rxdata file.
#
# simple_rgss_to_txt(filename)
# * This command reads an .rgss file from the Data folder and converts
# it into a .txt file within the specifiled text file folder. It is
# a destructive command and will erase any previously made .txt file.
#
#------------------------------------------------------------------------------
#
# COMPATABILITY AND ISSUES
#
# This script merely creates three new script calls and does not alter or
# overwrite any of the default code. As such, this script should be com-
# patible with any existing RPGMaker XP message system.
#
#
#==============================================================================
#
# TERMS AND CONDITIONS:
#
# Free for use, even in commercial games. And as this script was requested
# by Whisper, you have to give both of us credit for this script.
#
#==============================================================================
#==============================================================================
#
# THE ONE CONFIGURABLE VALUE:
#
# Set the folder name for Txt files (again, this folder will not encrypt into
# an .rgssad product.
#
MTFF_TXTFOLDER = "Text"
#
# NOTE: A folder with this name MUST be in the root directory of the project
# and is where all text files will be located.
#
# =============================================================================
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Show Messagebox from File
# filename : outside filename
#--------------------------------------------------------------------------
def messagefile(filename)
# Test file for txt format
if FileTest.exist?(MTFF_TXTFOLDER + "/" + filename + ".txt")
# Load text file into temporary holder
file = File.open(MTFF_TXTFOLDER + "/" + filename + ".txt", "r")
msgtext = file.readlines
file.close
# Otherwise if an rgss file
elsif FileTest.exist?("Data/" + filename + ".rxdata")
file = File.open(filename + ".rxdata", "r")
msgtext = load_data("Data/" + filename + ".rxdata")
file.close
# Otherwise, invalid and return
else
return
end
# Reset scrolling index value and position
indexval = 0
position = 0
# Cycle through message
for msgline in msgtext
# Chop off any pesky \n at end of line
msgline.chop!
# Create event command and create newly formatted message
msgtemp = RPG::EventCommand.new
msgtemp.parameters = [msgline]
msgtemp.indent = 0
msgtemp.code = (indexval == 0) ? 101 : 401
# If first line, insert in command position
if indexval == 0
@list[@index] = msgtemp
# Otherwise, insert after position pushing all other commands down
else
position = @index + indexval
@list.insert(position, msgtemp)
end
# And advance the line
indexval += 1
end
# Perform the message call
command_101
end
#--------------------------------------------------------------------------
# * Convert txt file into rgss file
# filename : outside filename
#--------------------------------------------------------------------------
def simple_txt_to_rgss(filename)
return unless FileTest.exist?(MTFF_TXTFOLDER + "/" + filename + ".txt")
rxfile = "Data/" + filename + ".rxdata"
txfile = MTFF_TXTFOLDER + "/" + filename + ".txt"
file = File.new(txfile)
lines = file.readlines
file.close
save_data(lines, rxfile)
end
#--------------------------------------------------------------------------
# * Convert rgss file into txt file
# filename : outside filename
#--------------------------------------------------------------------------
def simple_rgss_to_txt(filename)
return unless FileTest.exist?("Data/" + filename + ".rxdata")
rxfile = "Data/" + filename + ".rxdata"
txfile = MTFF_TXTFOLDER + "/" + filename + ".txt"
lines = load_data(rxfile )
file = File.open(txfile, "w")
file.write(lines)
file.close
end
end
Instructions
They're in the script. Plenty enough for your moderate-level script user.
Compatibility
This script merely creates three new script calls and does not alter or overwrite any of the default code. As such, this script should be compatible with any existing RPGMaker XP message system.
Terms and Conditions
Free for use, even in commercial games. And as this script was requested by Whisper, you have to give both of us credit for this script.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)