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
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi43.tinypic.com%2F2r6037r.png&hash=6aaff04eb40ad4545c77cf2888a4b5381e9ac06b)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi40.tinypic.com%2F9ad18i.png&hash=5d0405ada3429f5578d95bb17ad4337e2575ed19)
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 (http://rmrk.net/index.php/topic,25129.0.html)
#===============================================================================
#
# 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
:ccby:
I like it ~ You might want to put in a safeguard so that people don't need to initialize a variable for every line of the message though, either by initializing them prior to the case branch or by using an array. That's nothing major though.
Really cool. Definitely going to use this. One question though: is there any way to make it to the mail is unavailable until the switch is on? Instead of the other way around like it is now?
Yeah, I could try that. Haven't touched this script in a long time.
Glad you like it BTW.
EDIT: Ok, I updated it.
I just hit a wall.
I made a new letter, and am testing it, and I got this error:
@command_window.update
at line 216. Any way to fix it?
Did you get it from the script? Not the demo (outdated by miles).
THANK YOU THANK YOU THANK YOU!
EDIT: It works perfectly now!
Forgive me for double posting, but I had an idea for another update. You could make it so that the icons next to the letter title change after you've looked at the letter once so that you know which letters you have and haven't opened.
I like it, but there are a few problems. 1st, I don't want it to say Shinra Electric Power Company and I can't find out where in the script you can adjust this.
2nd,
# 151 => [151, "Shop"] won't work for me... Do you write w/o the [ ?
1. MAIL_RIGHT = "Shinra Electrical Power Company" # What shows up on the right of the top window.
Do a Ctrl+Shift+F for that.
2. Take out the #.
Thnks. All fixed. It's a great script. One of the best I've found. :)
Is there a way to make this script view mail as old and new messages?
Nope :(
Guess I should really work on this script more, huh.
I can't even get to the mail list. No option appears in the menu.
You can call it through the script call "$scene = Scene_Mail.new". It's in the demo, but I guess I should've put it up on the main script page as well. I apologise.
I didn't think it was necessary since so many CMS's have their own input command function, and TBH I didn't really know how to do that without overwriting a part of Scene_Menu at that time, which wouldn't work too well.
I added a new message, but the starting line is a syntax error...
What am I doing wrong?
Quotewhen 152
from = 'Cozziekuns the 2nd'
message1 = 'This message is really long. Really, really long.'
message2 = 'I do not know why I had to make it so long, but'
message3 = 'I guess it was to show you how long messages'
message4 = 'can be. They can go up to 12 message lines.'
message5 = 'Amazing stuff, huh? The problem with this is'
message6 = 'that you have to fill out every single message'
message7 = 'line. That means you either have to make your'
message8 = 'message go for 12 lines, or leave some lines'
message9 = 'blank, like so:'
message10 = ''
message11 = ''
message12 = '~ Cozziekuns the 2nd'
date = '5/13/2010'
end
when 153
from = 'Your Mom'
message1 = 'How are you these days, Ness? I know you love to'
message2 = 'travel, but please be careful and come home safe'
message3 = 'and sound, okay? I packed a comms device in'
message4 = 'your bag, so you can contact me.'
message5 = 'Stay safe, honey.'
message6 = ''
message7 = ''
message8 = ''
message9 = ''
message10 = ''
message11 = ''
message12 = 'Your mother'
date = '13/13/199X'
end
EDIT: If I "Dummy Out" the line (Make it a comment) a syntax error occurs on the last "end" line in that section
EDIT2: Deleting the second letter glitches up the script as well. It appears the way the script is coded it cannot support more or less than two letters, the total number of letters in the game must equal two. With serious problems like these I'd strongly suggest to make a completely new script from scratch.
That's not true, it's your fault and it's because you put the next branch outside of the end there.
when 152
from = 'Cozziekuns the 2nd'
message1 = 'This message is really long. Really, really long.'
message2 = 'I do not know why I had to make it so long, but'
message3 = 'I guess it was to show you how long messages'
message4 = 'can be. They can go up to 12 message lines.'
message5 = 'Amazing stuff, huh? The problem with this is'
message6 = 'that you have to fill out every single message'
message7 = 'line. That means you either have to make your'
message8 = 'message go for 12 lines, or leave some lines'
message9 = 'blank, like so:'
message10 = ''
message11 = ''
message12 = '~ Cozziekuns the 2nd'
date = '5/13/2010'
end
when 153
from = 'Your Mom'
message1 = 'How are you these days, Ness? I know you love to'
message2 = 'travel, but please be careful and come home safe'
message3 = 'and sound, okay? I packed a comms device in'
message4 = 'your bag, so you can contact me.'
message5 = 'Stay safe, honey.'
message6 = ''
message7 = ''
message8 = ''
message9 = ''
message10 = ''
message11 = ''
message12 = 'Your mother'
date = '13/13/199X'
end
Delete that red end and it will probably be fine. The case branch should only have one end at the end of it, so:
case blah
when 1
...
when 2
...
when 3
...
when n
...
end
It is a necessity for scripts to use in my opinion. It makes anyone's game a bit better. Tuns of games I've played have a mail system so it's quite a popular system to have. Although it would be better with a new mail thing. :)
Updated to Version 1.1. No Un/Read Function as of yet I'm afraid, and I'm probably not going to be updating it since I'm going to be pretty busy in the next few weeks.
Even without the unread/read option, It's an amazing script and I'm using it in my RPG. Thanks for making it, cozziekuns! :D
*opens the door of this topic to see yuyubabe talking to a bunch of skeletons*
Quote from: Welfare-Daddy Pacman on January 25, 2011, 09:23:03 AM
*opens the door of this topic to see yuyubabe talking to a bunch of skeletons*
I thought maybe I could bring them back to life.... :,(
um cozziekuns... sorry to necropost but it was over a year ago you said you would be busy so I was wondering if there was a simple way of editing the script to say which ones have been read through messages using icons as mentioned in an earlier reply... on the bright side my necropost isn't spam ^-^