[XP] Mail Box System

Started by G_G, August 01, 2010, 04:14:26 pm

Previous topic - Next topic

G_G

August 01, 2010, 04:14:26 pm Last Edit: July 15, 2011, 07:32:21 pm by game_guy
Mail Box System
Authors: game_guy
Version: 1.1
Type: Messaging System
Key Term: Misc System



Introduction

Small mail-box system. Have npc's send your players mail. Then have your Player read it. Sorta like the pokemon cellphone system. Where trainers would call you for a rematch.


Features


  • Completely Customizable
  • -Customize Text
  • -Customize Color
  • -Customize Opacity
  • Easy to setup mail
  • Easy to get mail
  • Check to see if a mail has been read



Screenshots

Unread Mail
Spoiler: ShowHide

Read Mail
Spoiler: ShowHide



Demo

N/A


Script

Spoiler: ShowHide

#===============================================================================
# Mail Box System
# Author game_guy
# Version 1.1
#-------------------------------------------------------------------------------
# Intro:
# Small mail-box system. Have npc's send your players mail. Then have your
# Player read it. Sorta like the pokemon cellphone system. Where trainers
# would call you for a rematch.
#
# Features:
# Completely Customizable
# -Customize Text
# -Customize Color
# -Customize Opacity
# Easy to setup mail
# Easy to get mail
# Check to see if a mail has been read
#
# Instructions:
# Go down to config. Configure the variables there.
# Everythings self explanatory down below.
# Colors are setup like this.
# Color.new(red, green, blue)
#
# Script Calls:
# Use
# $scene = Scene_Mail.new to go to mail box
# Use
# $game_party.add_mail(mail_id) to add a new mail
# Use
# $game_party.take_mail(mail_id) to delete a mail
# Use
# $game_party.mark_read(mail_id) to mark a message read
# To see if a message has been read, use the script call in
# a conditional branch.
# $game_party.mail_read?(mail_id)
#
# Compatibility:
# Not tested with SDK.
#
# Credits:
# game_guy ~ For making it
# Darth Spy ~ Requesting it
#===============================================================================
module GGMail
 #===================================================
 # Config
 #===================================================
 #--------------------
 # Mail Bag - Name of your mail holder.
 # Example: Mail Box :O
 #--------------------
 Mail_Word       = "Mail Bag"
 #--------------------
 # Action_Message - Text to show
 # how to mark messages read.
 #--------------------
 Action_Message  = "Press Space to Mark as Read"
 #--------------------
 # From_Text - Text displayed
 # with the sender of the mail
 # Example: Sender:
 #--------------------
 From_Text       = "From: "
 #--------------------
 # Title_Text - Text displayed
 # with the title of the mail.
 #--------------------
 Title_Text      = "Title: "
 #--------------------
 # Message_Text - Text displayed
 # with the message of the mail.
 #--------------------
 Message_Text    = "Message: "
 #--------------------
 # Label_Color - Color of
 # From, Title, and Message text
 #--------------------
 Label_Color     = Color.new(192, 224, 255, 255)
 #--------------------
 # New_Color - Color of new
 # unread mail
 #--------------------
 New_Color       = Color.new(255, 255, 64, 255)
 #--------------------
 # Read_Color - Color of
 # old already read mail
 #--------------------
 Read_Color      = Color.new(255, 255, 255)
 #--------------------
 # Mail - Ignore this line
 #--------------------
 Mail            = []
 #--------------------
 # Opacity - The transparency
 # of the windows in the layout
 #--------------------
 Opacity         = 128
 #--------------------
 # Background - The background
 # that displays in the mail
 # scene.
 # 0 = blank
 # 1 = map
 # "quoted string" = picture
 #--------------------
 Background      = 1
 #--------------------
 # Return_Scene - Scene
 # that it goes to when exiting
 # the mail
 #--------------------
 Return_Scene    = Scene_Map
 #===================================================
 # Configure Mail
 #---------------------------------------------------
 # Add a new line
 # Mail[id of mail] = ["title", "sender", "message"]
 Mail[1] = ["How goes it?", "Granny", "Hey sonny. Was wondering how you were doing. Be safe and don't die!"]
 Mail[2] = ["Help!", "Hooker", "Help me! I was working my corner and I was kidnapped!"]
 #===================================================
 # End Config
 #===================================================
end
class Game_Party
 attr_accessor :mail
 attr_accessor :mread
 alias gg_init_mail_party_lat initialize
 def initialize
   @mail = []
   @mread = []
   gg_init_mail_party_lat
 end
 def add_mail(id)
   msg = GGMail::Mail[id]
   return if msg == nil
   unless @mail.include?(id)
     @mail.push(id)
     @mread[id] = false
   end
 end
 def take_mail(id)
   msg = GGMail::Mail[id]
   return if msg == nil
   if @mail.include?(id)
     @mail.delete(id)
   end
 end
 def mark_read(id)
   return if id == nil
   msg = GGMail::Mail[id]
   return if msg == nil
   if @mail.include?(id)
     @mread[id] = true
   end
 end
 def mail_read?(id)
   return if id == nil
   msg = GGMail::Mail[id]
   return if msg == nil
   return @mread[id]
 end
end
class Window_Mail_Help < Window_Base
 def initialize
   super(16, 16, 576, 96)
   self.back_opacity = GGMail::Opacity
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 def refresh
   self.contents.draw_text(0, 0, 576, 32, GGMail::Mail_Word, 1)
   self.contents.draw_text(0, 32, 576, 32, GGMail::Action_Message, 1)
 end
end
class Bitmap
 def format_text(text, width)
   words = text.split(' ')
   return words if words.size == 1
   result, current_text = [], words.shift
   words.each_index {|i|
       if self.text_size("#{current_text} #{words[i]}").width > width
         result.push(current_text)
         current_text = words[i]
       else
         current_text = "#{current_text} #{words[i]}"
       end
       result.push(current_text) if i >= words.size - 1}
   return result
 end
end
class Window_Mail_Message < Window_Base
 def initialize
   super(192 + 16, 96 + 16, 416 - 32, 388 - 32)
   self.back_opacity = GGMail::Opacity
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 def refresh
   return if @mail_id == nil
   msg = GGMail::Mail[@mail_id]
   return if msg == nil
   self.contents.clear
   w = self.contents.text_size("Title: ").width
   w2 = self.contents.text_size("From: ").width
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, self.width, 32, "Title: ")
   self.contents.draw_text(0, 48, self.width, 32, "From: ")
   self.contents.draw_text(0, 96, self.width, 32, "Message: ")
   self.contents.font.color = normal_color
   self.contents.draw_text(w + 8, 0, self.width, 32, msg[0])
   self.contents.draw_text(w2 + 8, 48, self.width, 32, msg[1])
   draw_msg(msg[2], 0, 128)
 end
 def draw_msg(msg, x, y)
   text = self.contents.format_text(msg, 392)
   text.each_index {|i|
       self.contents.draw_text(x, y + i*32, 544, 32, text[i])}
 end
 def set_mail(id)
   return if @mail_id == id
   @mail_id = id
   refresh
 end
end
class Scene_Mail
 def main
   create_background
   @mail = $game_party.mail
   @messages = []
   @mail.each {|i|
   @messages.push(GGMail::Mail[i][0])}
   @messages = [""] if @messages.size < 1
   @mail_window = Window_Command.new(192, @messages)
   @mail_window.x = 16
   @mail_window.back_opacity = GGMail::Opacity
   @mail_window.height = 388 - 32
   @mail_window.y = 96 + 16
   j = 0
   @mail.each{|i|
   if $game_party.mread[i] == false
     @mail_window.draw_item(j, GGMail::New_Color)
   end
   j += 1}
   @mail_help = Window_Mail_Help.new
   @mail_info = Window_Mail_Message.new
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   @mail_window.dispose
   @mail_help.dispose
   @mail_info.dispose
   if @back != nil
     @back.dispose
   end
 end
 def create_background
   n = GGMail::Background
   if GGMail::Background.is_a?(Integer)
     if n == 1
       @back = Spriteset_Map.new
     end
   else
     @back = Sprite.new
     @back.bitmap = RPG::Cache.picture(n)
   end
 end
 def refresh_command
   @messages = []
   @mail_window.dispose
   @mail_window = nil
   @mail.each {|i|
   @messages.push(GGMail::Mail[i][0])}
   @messages = [""] if @messages.size < 1
   @mail_window = Window_Command.new(192, @messages)
   @mail_window.x = 16
   @mail_window.height = 388 - 32
   @mail_window.y = 96 + 16
   @mail_window.back_opacity = GGMail::Opacity
   j = 0
   @mail.each{|i|
   if $game_party.mread[i] == false
     @mail_window.draw_item(j, GGMail::New_Color)
   end
   j += 1}
 end
 def update
   @mail_window.update
   @mail_help.update
   @mail_info.update
   @mail_info.set_mail(@mail[@mail_window.index])
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = GGMail::Return_Scene.new
     return
   elsif Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     $game_party.mark_read(@mail[@mail_window.index])
     refresh_command
     return
   end
 end
end



Instructions

In the script. Place below Scene_Debug.


Compatibility

Not tested with SDK.


Credits and Thanks


  • game_guy ~ For making it
  • mattfriends ~ For Requesting it



Author's Notes

Enjoy! :D

Blizzard

I thought SBR* requested it.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

From pm
Spoiler: ShowHide
QuoteDarth Spy
Basic Member


Level: 0
[Level++] [Level--]
Offline

Gender:
Posts: 14


Light up guys!!


       PLEASE HELP!!!
« Sent to: game_guy on: July 30, 2010, 03:51:03 AM »
« You have forwarded or responded to this message. »   Quote Reply Remove  

Can you give me one script? The script that can storge mails.

Example:
Command:
Mail.add("From","Title","Message")

Screen:
+----------------------------------------------------------------------------------------+
| Mails                                                                                                                    |
+----------------------------------------------------------------------------------------+
| Title 1     |   TITLE: Title 1                                                                                       |
| Title 2     |                                                                                                            |
| Title 3     |   FROM: Someone                                                                                   |
| Title 4     |                                                                                                            |
|              |   MESSAGE:                                                                                            |
|              |   This is Someone and the example message.                                                |
|              |                                                                                                            |
|              |                                                                                                            |
|              |                                                                                                            |
+----------------------------------------------------------------------------------------+

Thank you in advice.

WhiteRose

By the looks of things, this is quite a bit like the mail system in Crisis Core, yes?

G_G

Actually yea it is. :D Never realized it til now xD

The Niche

Well done, G_G, this is awesome. For it, I shall consent to being your slave. But you should change the line in your signature to "Is Niche's master"
I might use it at some point, but I think my game has enough scripts in it for the minute.
Level me down, I'm trying to become the anti-blizz!
Quote from: winkio on June 15, 2011, 07:30:23 pm
Ah, excellent.  You liked my amusing sideshow, yes?  I'm just a simple fool, my wit entertains the wise, and my wisdom fools the fools.



I'm like the bible, widely hated and beautifully quotable.

Dropbox is this way, not any other way!

stripe103

This is really nice. I don't know if I'm going to use it though, maybe, but I have a feature idea for those who are.
Just as in GTA IV, there could be a Positive Reply and a Negative Reply. And also two call scripts, one for checking if you got an email and one for checking if you have replied to one.

Just an idea, nothing you have to do :D

By Axerax

element

Ur really a great scripter...
U should make a mail system for RMX-os so u can send mails to other players online in ur friend list or somethin  :P

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Actually, in me and subs project, I planned on replacing the way you read pms with this. You'll still sends pm's through the chatbox but this way you can read them.
Also planned on making a buddys list for our game.

Other planned things if you care:
Server Status - Tells whether server is on or off (done)
Online Users List - Shows whos online (almost done)
Buddys List
New Inbox
Animation Chat Commands - Type in /sit it'll change your graphic to a sitting one.
Vehicles
Costumes
Minigames

I think I've said too much.

Blizzard

That's something different. That would be wrapping up the PM system and putting it on a GUI. I am all for it.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

SBR*

Quote from: Blizzard on August 01, 2010, 05:09:45 pm
I thought SBR* requested it.


No way! I would've scripted this myself...

The Niche

August 02, 2010, 02:21:22 pm #12 Last Edit: August 02, 2010, 02:22:26 pm by The Niche
I bet. :V:

That said, you could try doing another version of this, like the phone in pokemon or something else you might happen to come up with.
Level me down, I'm trying to become the anti-blizz!
Quote from: winkio on June 15, 2011, 07:30:23 pm
Ah, excellent.  You liked my amusing sideshow, yes?  I'm just a simple fool, my wit entertains the wise, and my wisdom fools the fools.



I'm like the bible, widely hated and beautifully quotable.

Dropbox is this way, not any other way!

Nadim13

Is it possible to activate any type of switch/variable when the player open a particular PM? If possible, how can I do that (Call Script, editing the script, other?)?

Good work however, level ++! ;)

G_G

Updated.
@Nadim: I updated it so you can now use this in a conditional branch
$game_party.mail_read?(id)


If its been read you can turn on a switch or whatever you need. ;D Thanks for the idea

Nadim13

Quote from: Adjutant game_guy on August 04, 2010, 12:37:43 pm
Updated.
@Nadim: I updated it so you can now use this in a conditional branch
$game_party.mail_read?(id)


If its been read you can turn on a switch or whatever you need. ;D Thanks for the idea

Thank you man! Tomorrow I'll try this script and I'll decide to use it or not. Thanks, however! ;)

Magus

October 01, 2010, 02:57:56 pm #16 Last Edit: October 01, 2010, 03:00:07 pm by Magus
Okay, it's working. I'm getting this to work slowly xD
LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

LiTTleDRAgo

this is very nice script but I can't use command like \n[1] or \v[1] in mail box
well, that isn't much matter for me but for suggestion, can you add a function like that in your script? ^^

Mimi Chan

Nice script *.*
Would it be more cool if npc has the ability of sending you items/gold as well *.*
What's a sig?

LiTTleDRAgo

Quote from: Mimi Chan on October 15, 2010, 11:16:39 am
Nice script *.*
Would it be more cool if npc has the ability of sending you items/gold as well *.*

you could do that manually in event

script : $scene = Scene_Mail.new
change gold : + 400000


so after you close the mail, you'll receive 400000 G