Mail Client
#1
Mail Client
by GoldenShadow
v 1.1
Jul 12, 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Okay, this is a mail client I made some weeks ago, but recently have updated it to the best I can for this Ver. 1. I hope you guys like it, and don't flame mail me if you think it's useless.

GoldenShadow Wrote:Demo not required: Make a Test Project and just test it yourself.


The Script is located in here:
Code:
#==============================================
# <> Mail Client v1.1
# ==> You can delete all my comments except the copyright and creator info. Thanks.
# ==> Do not rip, repost or any other way of reproducing without proper credit. Thanks.
# ShadowClan Technologies © 2003-2005 - All rights reserved. Creation Asylum rules :-)
#--------------------------------------------------------------------------------------
# * Why you need this?
# Everytime I post a script, I get bad comments on why anyone should need this or that it's
# useless or something like that. I hate that and it's disencouraging.
# So, why -should- you need this? Making a .hack//infection like game perhaps?
# Maybe a high developed planet game? Or just a modern like game?
# Maybe you're making a real life game? Or you're making just a regular RPG
# with neat stuff like this one? So many ideas... no reason for you to flame mail me again.
# If you still think it's useless, your comment is not welcome.
#
# * How it works
# When you start a new game, initially a email will be made. (You can change it anytime).
# Default mail is the name of the actor ID 0 + @RXSC.net, so like: Arshes@RXSC.net.
# For the more advanced game developers, I've made it possible to show messages
# while the mail is read, like the player reacts to the received mail.
# I don't really know how you can set a message but some of ya people should know.
# Also made it so the player can see which email is new and which not.
# It will show a green text saying 'NEW' when it's unread yet.
# To make it more nice, I made it so that every mail can have a different font type
#
# * How to import this to properly work
# Put the '$mail = Mail.new' BEFORE '$scene = Scene_Map.new' in the Title Scene
# at the command_new_game command.
# This !should! work. From that point on, you can use '$mail.*' commands anywhere.
# Where the '*' symbol can be replaced with 'write_mail', 'received_include?' or 'is_new?'.
#
# * How to receive mails/write mails
# You can use this anywhere! First use: $mail = Mail.new (like Title screen?)
# The you can use:
# $mail.write_mail("sender", "subject", ["msg line 1","msg line 2", "etc"], type, font)
# The extra's:
# Specify type for the type of mail, default: 1 = corrupt, 2 = infected
# and 3 = incomplete
# Specify font for the font in the mail content, (not for sender or subject).
#
# * How to change the email address at any given event
# Use a Call Script function event and enter the following:
# $mail.account = "new@account.here"
# That will change it immediatly.
#
# * Special buttons
# In your In Box, press the 'D' button to Delete. You're not warned for it and it removes
# it immidiatly, so watch out.
# Press the 'A' button to delete ALL the emails received. Also, here your _not_ warned.
#
# * How to check mail status in a conditional branch?
# Use: $mail.received_include?("topic name")
# You can also replace the topic name with the senders name.
# If you have the mail with the topic specified it returns true
# And if you have a mail with the sender specified it also returns true
# If you don't have both, it returns false.
# Use: $mail.is_new?("topic name")
# Returns true if the mail is unread. Returns false if it's already read.
#
# * Limitations
# Unfortunely, this isn't like the real thing... so what can't it do or support is:
# You cannot put a 'Files attached' option... well you can, but you must script it by yourself.
# You cannot put directories in the InBox like the 'real' ones. But maybe... in ver. 2.........;-)
# Maximum lines for mail is 20. You can increase it but I won't recommend...
# Don't make mails with the same topic. That wil make all mails with same topic share
# the same message and the same option if NEW or not. Only the Sender is different.
#
# * Some really REALLY stupid things to keep in mind
# The Script Call function in RPG Maker XP doesn't allow you to write as much lines as you want.
# It sucks! Best way to do that anyway is by scripting. And that can really suck too.
# Better use the Script Call for medium-short messages.
# Sorry for this bug, it's not my fault RPG Maker XP is so greedy on the lines...
#
# * What's fixed in ver 1.1 ?
# - Instead of the global variables, it uses attribute accessors.
# Much more efficient and of course easier.
#
# * Changes from ver 1ß to ver 1.1 :
# - Don't use $rxsc_mail for the email of the player, just use $mail.account.
# - Same goes for all the others btw, just $mail.*, replace * with the arrays.
#
# That would end the little explaining for now. I -really- hope you like this script.
#-----------------------------------------------------------------------------------------
# * Suggestions? ==> PM or post in the Game Making > RPG Maker > Finished Scripts > Mail Client
# * Created by: GoldenShadow
#====================================================

module SC # don't delete module, it's ripping if done anyway!
RXSC_MAIL = "Mail Client Script: Ver.1.1"
MAIL_HEAR_SOUND = true # set to true to hear a sound on receive
end

class Mail

attr_accessor :mail # Mail
attr_accessor :msg # Content of mail
attr_accessor :account # Your e-mail account
attr_accessor :sender # The sender
attr_accessor :read # If it's read or new
attr_accessor :font # Contents font

def initialize # Define the variables we're going to use
# Why are they global variables you ask? So we can use 'em outside this class
@mail = [] # mail IDs
@msg = {} # mail msgs
@account = "#{$game_party.actors[0].name}@RXSC.net" # This is the player's mail
@sender = [] # sender IDs
@read = {} # unread option IDs
@font = {} # font
end

def received_include?(string) # check if string is in mail or sender (can be number)
if @mail.include?(string)
return true
elsif @sender.include?(string)
return true
else
return false
end
end

def is_new?(string) # see if mail is unread
if @read[string] == true
return false
elsif @read[string] == false
return true
else
return false
end
end

def write_mail(topic = nil,from = nil,msg = [], type = nil, font = nil)
if SC::MAIL_HEAR_SOUND == true # Sound when receiving
Audio.se_play("Audio/SE/055-Right01", 100, 150) # You may change the soundfile
# In fact, you may even use Music Effects, BGM (not recommended) or BGS.
# Change the 'se_play' to 'me_play','bgm_play' or 'bgs_play' respectivly.
# You should also change the directory when something else than SE is used.
end
if topic == nil or topic == ""# Subject of message
@mail.push("(no subject)") # if no subject specified
else
@mail.push(topic)
end
if msg == nil # Write a message in array format, like: ["line1, "line2, "etc"]
@msg[topic] = ["* AUTO MAIL*","No message specified by the sender."," ","Greetings from webmaster@mailserver.rxsc"]
else
@msg[topic] = msg
end
if from == nil or from == "" # The sender of the mail
@sender.push("(unknown)") # if no sender specified
else
@sender.push(from)
end
if font != nil
@font[topic] = font
end
@read[topic] = false # set it to unread
if type != nil # some cool stuff
if type == 1
# Type 1: Corrupted Mail
@msg[topic].push("","* AUTO MAIL *","The mail is corrupted.","Sorry for this inconvinience.","","Greetings from Webmaster")
elsif type == 2
# Type 2: Infected Mail
@msg[topic].push("","* AUTO MAIL *","This mail is infected.","Delete it immediately.","","Greetings from Webmaster")
elsif type == 3
# Type 3: Incomplete Mail
@msg[topic].push("","* AUTO MAIL *","Mail was not sent correctly.","Some parts may have been lost.","","Greetings from Webmaster")
elsif type == 4
# Add more if you like, see above for the examples
end
end
end
end

# This is the topic window or in other words the message window.
# So this is the window where the contents of a mail is shown.
# You may change it in how you want it actually.
# Screwing this up is your own fault... but then again, you can always repaste...
class Window_Topic < Window_Base

def initialize(mail)
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.visible = false
@mail = mail # This is the index of the inbox and will be converted to the mail ID
refresh
end

def refresh
self.contents.clear
unless @mail == "none" # Just a block
self.contents.draw_text(4, 0, self.width - 40, 32, "Subject: #{$mail.mail[@mail]}")
self.contents.draw_text(4, 32, self.width - 40, 32, "From: #{$mail.sender[@mail]}")
self.contents.draw_text(4, 64, self.width - 40, 32, "To: #{$mail.account}")
rect = Rect.new(0, 100, self.width, 2)
self.contents.fill_rect(rect, Color.new(255, 255, 255)) # Modify the color as pleased
end
end

def show_msg(msg) # Show the mail message contents
@topic = $mail.mail[@mail].to_s
@msg = $mail.msg[@topic]
y = 85 # start line 1 at this y-position
unless @msg == nil or @mail == "none" # Also just a block
for line in 0...20 # this is the message, as you see, max lines is 20
y += 16 # space between the lines
self.contents.font.size = 16 # font size
if $mail.font[@topic] != nil
self.contents.font.name = $mail.font[@topic] # own font
end
self.contents.draw_text(4, y, self.width, 32, @msg[line].to_s)
end
end
end
end

# This is the inbox
# When email is received it will be added at the end of the list.
# So that you can see, like the real one, which one's old or new.
class Window_Inbox < Window_Selectable

def initialize
super(0, 64, 640, 416)
@column_max = 1
self.index = 0
refresh
end

def item
return @data[self.index]
end

def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 0...$mail.mail.size # This is the var for mails
@data.push($mail.mail[i])
end
@item_max = @data.size
if @item_max >= 0
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = 24
for i in 0...@item_max
draw_item(i)
end
end
end

def draw_item(index)
item = @data[index]
self.contents.font.color = normal_color
x = 4
y = index * 32 # 32 stands for space between lines
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(x, y, self.width - 40, 32, item.to_s) # mail topic (subject)
self.contents.draw_text(x + 400, y, self.width - 40, 32, $mail.sender[index].to_s) # Sender
if $mail.read[item] == false
self.contents.font.color = Color.new(130,225,89)
self.contents.draw_text(x + 300, y, self.width - 40, 32, "NEW") # if mail is unread
else
self.contents.font.color = normal_color
self.contents.draw_text(x + 300, y, self.width - 40, 32, "") # if mail is read, change as pleased
end
end
end

# This is the built-in mail client.
# You may modify it but try not to screw it too much up.
class Scene_Mail

def main
@help_window = Window_Help.new
if $mail.mail.size == 0 or $mail.mail == nil
@help_window.set_text("Signed in with #{$mail.account} and you have no mails.")
else
@help_window.set_text("Signed in with #{$mail.account} and you have #{$mail.mail.size} mail(s).")
end
@help_window.z = 100
@inbox = Window_Inbox.new
@inbox.active = true
@inbox.visible = true
@inbox.z = 200
@topic_window = Window_Topic.new("none")
@topic_window.z = 100
@message_window = Window_Message.new # For msg's to show...
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@inbox.dispose
@topic_window.dispose
@message_window.dispose
@help_window.dispose
end

def update
@message_window.update
@inbox.update
@help_window.update
@topic_window.update
if $game_temp.message_window_showing
return
end
if @inbox.active == false
update_topic
return
end
if @inbox.active == true
update_inbox
return
end
end

def update_inbox
if $mail.mail.size == 0 or $mail.mail == nil
@inbox.index = -1
end
if Input.trigger?(Input::C) # selecting the topic at inbox
if @inbox.index == nil or $mail.mail.size == 0 # if no topics...
$game_system.se_play($data_system.buzzer_se) # errrr
return
end
$game_system.se_play($data_system.decision_se)
@topic_window.contents.clear
@topic_window = Window_Topic.new(@inbox.index)
@topic_window.show_msg(@inbox.index)
if $mail.read[$mail.mail[@inbox.index]] == false
$mail.read[$mail.mail[@inbox.index]] = true
@inbox.refresh
end
@topic_window.visible = true
@inbox.active = false
@inbox.visible = false
@help_window.visible = false
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new # This would be the previous scene
end
if Input.trigger?(Input::Z) # Deletes selected email
$mail.mail.delete_at(@inbox.index)
$mail.msg.delete(@inbox.index)
$mail.sender.delete_at(@inbox.index)
$game_system.se_play($data_system.decision_se)
@inbox.refresh
if $mail.mail.size == 0
@inbox.index = 0
@help_window.set_text("Signed in with #{$mail.account} and you have no mails.")
else
@help_window.set_text("Signed in with #{$mail.account} and you have #{$mail.mail.size} mail(s).")
end
if @inbox.index > 1
@inbox.index -= 1
else
@inbox.index = 0
end
end
if Input.trigger?(Input::X) # Deletes all
$mail.mail.clear
$mail.msg.clear
$mail.sender.clear
$game_system.se_play($data_system.decision_se)
@inbox.refresh
@help_window.set_text("Signed in with #{$mail.account} and you have no mails.")
@inbox.index = -1 # this will make the cursor be hidden (cuz there arent any mails)
end
end

def update_topic # this command is for the topic window, add stuff if you like
if Input.trigger?(Input::B) # cancel button to return to inbox
$game_system.se_play($data_system.cancel_se)
@inbox.active = true
@inbox.visible = true
@help_window.visible = true
@topic_window.visible = false
end
end
end

# This is a example mail for you to learn from.
# Study this and you'll learn it in no time!
class Scene_Title
alias mail_title_new_game command_new_game
def command_new_game
mail_title_new_game
$mail = Mail.new
$mail.write_mail("Info: Your Mail Client","ShadowClan Tech.",
["To the owner of this account,"," ",
"Thank you for using my Mail Client Script Ver. 2.1.",
"I hope you really love this script because I had a rough time making it,",
"and trust me if I say a ROUGH time!",
"And I've been recently busy making good updates for this",
"making it not so messy in the core.so turned out greater than ever!",
"",
"➢ What's Fixed? 「Version 1.1」",
"▸ No global variables but one: $mail! They work with ATTRs now!",
"▸ Info is better formulated.",
"",
"For more information, take a look at Creation Asylum forums.",
" ",
"Have fun,",
"GoldenShadow a.k.a カヤシュ-サン"], type = nil, font = "MS PMincho")
end
end
# FINAL UPDATE: July 2nd 2005, 21:54


Peace.

EDIT: Weird marks all over the place, I reposted it and it's clean now. Enjoy.
EDIT2: Updated Ruby code, and added explaination how to change account.
}




Users browsing this thread: 1 Guest(s)