Simple Mail System
Version: 1.1
Author: cozziekuns
Date: May 13, 2010
Version History
- <Version 1.1> 06.28.2010 - Rewrote some code, seeing as it was pretty sloppy.
- <Version 1.0a> 06.14.2010 - Changed the Switch function around a bit
- <Version 1.0> 05.13.2010 - Original Release
Planned Future Versions
Description
A simple mail system akin to the one in Final Fantasy VII: Crisis Core, and Final Fantasy III DS.
Features
- Easily Configurable.
- Mails can go up to twelve lines.
- Up to 999 letters can be sent to the player.
Screenshots Instructions
See header.
~ NOTICE ~ You can call it using the script call "$scene = Scene_Mail.new" ~ NOTICE ~
Script
Requires Modern Algebra's Paragraph Formatter and Special Codes Formatter. Get both here#===============================================================================
#
# Cozziekuns' Simple Mail System
# Last Date Updated: 5/13/2010
#
# A simple mail system akin to the one in Final Fantasy VII: Crisis Core, and
# Final Fantasy III DS.
#
#===============================================================================
# Updates
# -----------------------------------------------------------------------------
# o 06/28/10 - Rewrote some code, seeing as it was pretty sloppy.
# o 06/14/10 - Changed the Switch function around a bit
# o 05/13/10 - Created Script
#===============================================================================
# What's to come?
# -----------------------------------------------------------------------------
# o A lot of things. Probably too many to count.
# o For example, a deleting system?
# o Attachments...
# o More than one page...
# o The list goes on.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ? Materials but above ? Main. Remember to save. You can
# edit the modules as you wish.
#
# Special codes can be input into messages at any time, thanks to Modern
# Algebra's Special Codes Formatter. Just use:
#
# \n - line break to next paragraph (Note the single \, NOT \\)
# \\v[x] - Shows the value located in the variable x
# \\n[x] - Shows the name of the Actor with ID x
# \\c[x] - Changes the colour of the text to x. x can be 0 - 31
# \\c[#hex] - Changes the colour of text to the hex value
# \\ - \
# \\pid[x] - Shows Actor ID of Party Member in position X (0-3)
# \\nc[x]- Shows the name of class with ID x
# \\np[x]- Shows the name of the Party Member with index x
# \\ne[x]- Shows the name of Event with ID x on the map
# \\nm[x]- Shows the name of Monster with ID x
# \\ni[x]- Shows the name of Item with ID x
# \\nw[x]- Shows the name of Weapon with ID x
# \\na[x]- Shows the name of Armour with ID x
# \\pi[x]- Shows the price of Item with ID x
# \\pw[x]- Shows the price of Weapon with ID x
# \\pa[x]- Shows the price of Armour with ID x
# \\iicon[x] - Shows the Icon of Item with ID x
# \\wicon[x] - Shows the Icon of Weapon with ID x
# \\aicon[x] - Shows the Icon of Armour with ID x
# \\icon[x] - Shows the Icon with ID x
# \\vocab[value] - prints vocab for that item type. Suitable values are:
# level, level_a, hp, hp_a, mp, mp_a, atk, def, spi,
# agi, weapon, armor1, armor2, armor3, armor4, weapon1,
# weapon2, attack, skill, guard, item, equip, status, save,
# game_end, fight, escape, new_game, shutdown, to_title,
# continue, cancel, gold
# \\f[key] - Show Filter phrase attached to key
# \\b - Bold ON
# \/b - Bold OFF
# \\i - Italic ON
# \/i - Italic OFF
# \\u - Underline ON
# \/u - Underline OFF
# \\s - Shadow ON
# \/s - Shadow OFF
# \\hl[x] - Highlights with color x. \\hl toggles off
# \\ac[x]- Shows class of actor with ID x
# \\a...[x] - Shows the ... of Actor X. ... can be any of the following:
# hp, maxhp, mp, maxmp, atk, def, spi, agi, exp_s, next_exp_s,
# next_rest_exp_s, level, weapon_id, armor1_id, armor2_id,
# armor3_id, armor4_id - and any other methods from Game_Actor.
# \\c - Centres text
# \\r - Sets right alignment to text
#
# Call with $scene = Scene_Mail.new
#===============================================================================
$imported = {} if $imported == nil
$imported["CozSimpleMailSystem"] = true
module COZZIEKUNS
COMMAND_X = 0 # Where you want the command window to be.
COMMAND_Y = 56 # Where you want the command window to be.
COMMAND_WINDOWSKIN = "Window" # The windowskin you want your window to be in.
ICONS = true # If you want to use icons or not.
MAIL_LEFT = "Mail:" # What shows up on the left of the top window.
MAIL_RIGHT = "Shinra Electrical Power Company" # What shows up on the right of the top window.
COMING_FROM_MENU = false # Whether or not your going to the mail system throug the menu.
ICON_INDEX ={
# Syntax: Vocab => Icon Number
"Salutations from Cozziekuns!" => 112,
"Salutations from Cozziekuns the 2nd!" => 112,
}
#===============================================================================
# * Mail Command Instructions
# -----------------------------------------------------------------------------
# This array lets you order you mail. For example, an array of
#
# 151
# 152
#
# Would show up as:
#
# "(151's Text)"
# "(152's Text)"
#
#===============================================================================
MAIL_COMMANDS =[
151, # Salutations from Cozziekuns
152, # Salutations from Cozziekuns the 2nd
]
#===============================================================================
# * Mail Data Instructions
# -----------------------------------------------------------------------------
# This hash lets you determine what you want to call your mail, as well as what
# switch hides your mail. For example,
#
# 151 => [151, "Shop"]
#
# Would show up as
#
# Shop
#
# and could be hidden if the switch 151 is OFF.
#
#===============================================================================
MAIL_DATA ={
# Syntax: Switch ID, Text
151 => [151, "Salutations from Cozziekuns!"],
152 => [152, "Salutations from Cozziekuns the 2nd!"],
}
#--------------------------------------------------------------------------
# * Command List
#--------------------------------------------------------------------------
def self.create_mail_data(id)
from = " \\c[18]Not Specified\/c[0] "
message = " \\c[18]Not Specified\/c[0] "
date = " \\c[18]Not Specified\/c[0] "
case id
#===============================================================================
# * Mail Data Instructions.
# -----------------------------------------------------------------------------
# All this holds is the data that goes in the mail. For example, in the demo
# message, from is who the person is from, message is what's in the message, and
# the date is, obviously the date.
#
#===============================================================================
when 151
from = "Cozziekuns"
message = "There are a few new functions in Version 1.1 that probably don't mean much to you. Obviously, it uses \\c[16]Paragraph Formatting\\c[0] now. Also, if you close the command window, you'll notice that it \\bdoesn't\/b open and close anymore. That's because it created \\blag\/b with \\btoo many mail options\/b. Finally, the mail index is now stored and your cursor is \\bredirected\/b to your last mail index upon arrival. \n \n ~ Cozziekuns"
date = "6/26/2010"
when 152
from = "Cozziekuns the 2nd"
message = "This paragraph is paragraph formatted, courtesy of Modern Algebra's Paragraph Formatter 2.0. The mail system also utilizes Modern Algebra's Special Codes formatter which can do things like \\bBolden\/b, \\c[14]Colour\\c[0] and \\uUnderline/\u your text automatically. Pretty neat, huh? \n \n ~ Cozziekuns the 2nd"
date = "6/26/2010"
end
return from, message, date
end
end
#==============================================================================
# ** Window_MailTop
#------------------------------------------------------------------------------
# This window displays a window that helps you out.
#==============================================================================
class Window_MailTop < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# x : window X coordinate
# y : window Y coordinate
#--------------------------------------------------------------------------
def initialize
super(0, 0, 544, WLH + 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 544, WLH, COZZIEKUNS::MAIL_LEFT, 0)
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 500, WLH, COZZIEKUNS::MAIL_RIGHT, 2)
end
end
#==============================================================================
# ** Window_MailSecond
#------------------------------------------------------------------------------
# This class performs the Mail window processing.
#==============================================================================
#
class Window_MailSecond < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# x : window X coordinate
# y : window Y coordinate
#--------------------------------------------------------------------------
def initialize(mail_index)
super(0, 0, 544, 416)
@mail_index = mail_index
@from, @message, @date = COZZIEKUNS.create_mail_data(mail_index)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 120, WLH, "From:", 0)
self.contents.draw_text(4, WLH * 2, 120, WLH, "Message:", 0)
self.contents.draw_text(4, WLH * 14, 120, WLH, "Date:", 0)
self.contents.font.color = normal_color
self.contents.draw_text(65, 0, 544, WLH, @from)
formatter = Paragrapher::Formatter_SpecialCodes.new
artist = Paragrapher::Artist_SpecialCodes.new
specifications = 500
pg = Paragrapher.new(formatter, artist)
text_bitmap = pg.paragraph(@message, specifications)
self.contents.blt(4, WLH * 3.5, text_bitmap, Rect.new(0, 0, text_bitmap.width, text_bitmap.height))
self.contents.draw_text(65, WLH * 14, 544, WLH, @date)
end
end
#==============================================================================
# ** Window_MailCommand
#------------------------------------------------------------------------------
# This window displays the icons in the mail screen.
#==============================================================================
class Window_MailCommand < Window_Command
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# enabled : enabled flag. When false, draw semi-transparently.
#--------------------------------------------------------------------------
def draw_item(index, enabled = true)
rect = item_rect(index)
rect.x += 4
rect.width -= 8
rectx = rect.x
recty = rect.y
rectw = rect.width
recth = rect.height
self.contents.clear_rect(rect)
self.contents.font.color = normal_color
if COZZIEKUNS::ICON_INDEX.include?(@commands[index])
icon = COZZIEKUNS::ICON_INDEX[@commands[index]]
else
icon = 0
end
draw_icon(icon, rectx, recty)
self.contents.font.color.alpha = enabled ? 255 : 128
self.contents.draw_text(rectx + 24, recty, rectw - 24, recth, @commands[index])
rect = item_rect(index)
rect.x += 4
rect.width -= 8
end
end
#==============================================================================
# ** Scene_Mail
#------------------------------------------------------------------------------
# This class performs the mail screen processing.
#==============================================================================
class Scene_Mail < Scene_Base
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
@menu_index = menu_index
end
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
create_command_window
@mailtop_window = Window_MailTop.new
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
@mailtop_window.dispose
@unread_window.dispose
dispose_menu_background
end
#--------------------------------------------------------------------------
# * Command List
#--------------------------------------------------------------------------
def create_command_list
commands = []
@ex_cmds = {}
COZZIEKUNS::MAIL_COMMANDS.each_with_index { |c, i|
case c
when 0..999
next unless COZZIEKUNS::MAIL_DATA.include?(c)
mail_list = COZZIEKUNS::MAIL_DATA[c]
next unless $game_switches[mail_list[0]]
@ex_cmds[c] = commands.size
commands.push(mail_list[1])
end
}
return commands
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
@unread_window.update
if @unread_window.active
if Input.trigger?(Input::B)
Sound.play_cancel
if COZZIEKUNS::COMING_FROM_MENU
$scene = Scene_Menu.new
else
$scene = Scene_Map.new
end
elsif Input.trigger?(Input::C)
index = @unread_window.index
for key in @ex_cmds
if @ex_cmds[key[0]] == index
return_check = false
found_key = key[0]
break
end
end
if found_key == 0
Sound.play_buzzer
elsif found_key >= 0
Sound.play_decision
$scene = Scene_MailSecond.new(found_key, index)
end
end
end
end
#--------------------------------------------------------------------------
# * Create Command Window
#--------------------------------------------------------------------------
def create_command_window
@unread_files = create_command_list
if COZZIEKUNS::ICONS
@unread_window = Window_MailCommand.new(544, @unread_files)
else
@unread_window = Window_Command.new(544, @unread_files)
end
@unread_window.index = @menu_index
@unread_window.x = COZZIEKUNS::COMMAND_X
@unread_window.y = COZZIEKUNS::COMMAND_Y
@unread_window.height = 360
@unread_window.windowskin = Cache.system(COZZIEKUNS::COMMAND_WINDOWSKIN)
end
end
#==============================================================================
# ** Scene_MailSecond
#------------------------------------------------------------------------------
# This class performs the bulk of the mail message.
#==============================================================================
class Scene_MailSecond < Scene_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor_index : actor index
#--------------------------------------------------------------------------
def initialize(mail_index, index)
@mail_index = mail_index
@index = index
end
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
@mailsecond_window = Window_MailSecond.new(@mail_index)
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@mailsecond_window.dispose
end
#--------------------------------------------------------------------------
# * Return to Original Screen
#--------------------------------------------------------------------------
def return_scene
$scene = Scene_Mail.new(@index)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
update_menu_background
@mailsecond_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
end
super
end
end
Credit
- Cozziekuns
- Modern Algebra (PF2 and SCF).
Thanks
- Modern Algebra, for clearing out my brackets, braces problem, his Paragraph Formatter, and for helping me with other miscellaneous problems.
Support
Just post down below.
Known Compatibility Issues
None so far.
Demo
See attached.
Author's Notes
Probably won't be updating this for a long time, seeing as I'm kinda busy right now.
Restrictions