Mail Database
#1
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.


This is for use with this script.
...(Find link to GoldenShadow's MAIL CLIENT)

Instruction are in the commants. Try it out. You don't need a demo.

Code:
#================================
#  Email Database R2
#
#        Written By RPG Fan
#================================
#  How to Use:
#
#   Inserting:
#      Just insert this entire script above main and your done.
#
#   Editing:
#      Editing is required here. The first thing you should
#      edit is the initialization of the @mail_font variable.
#      That is the default font the system will use to send
#      your emails.
#
#     If your number of emails is larger than the variable
#     @highest_id then simply change the number in the
#     initialize method to a number that fits.
#
#     Finally with all of the when statements you can add
#     more emails adding when id (id being the id of your
#     email) and then the code to send the mail. Make
#     sure that in the syntax for composing the mail where
#     it asks for type you print type and where it asks
#     for font just say font there and it'll use the contents
#     of the variables which you will set when sending the
#     mail
#
#   Using the Database.
#      To send a mail in the database use the syntax:
#      $mail_db.send_mail(id,font,type)
#      ID: The Id of your email
#      Font: The font used in your mail (default will be
#               used if nil)
#      Type: Whether it's corrupted or whatever (if nil it's
#                normal.
#
#   Changing the default font mid-game:
#        This is why I put the default font in a variable,
#         so it could be changed mid-game.
#         Just use:
#         $mail_db.mail_font = "new font name"
#         It does not require the file extension.
#         Make sure to include all fonts with your game if
#         you think the player might be missing some.
#================================
#    Known Errors:
#          ?????? Could not find mail ??????
#            This is your own error for trying to use an
#            ID out of range. Simply go back line 17 of
#            this script and follow the insrtuctions there.
#================================
#   Enjoy my first full script :)
#================================

class Mail_Database
  #---------------------------------------------------------------
  attr_accessor :id
  attr_accessor :mail_font
  attr_reader :highest_id
  #---------------------------------------------------------------
  
  def initialize
    @id = 0  # Initlializes ID variable for mail
    @mail_font = "MS PMincho"  # Default font used in mail
    @highest_id = 5
  end
  
  def send_mail(id,font,type)
    
    @id = id # Assigns ID to intance variable
    
    if font == nil # Check if a specific font is set
      font = @mail_font # If no specific font is set, set to default
    end
    
    if @id < 1 or @id > @highest_id # Checks if ID is out of range
      @id = 0 # Sets to error message
    end
    
    case @id # Checks ID's
    
    when 0 # Error message
      print("?????? Could not find mail ??????")
      exit  # Ends Game
    when 1
      $mail.write_mail("Tri-net Networking", "Success", ["Congrats!"], type, font) # Successful Email
    end
    @id = 0
    font = nil
    type = nil
    # ^Resets Variables
  end
end

class Scene_Title
  alias db_new_game command_new_game
  def command_new_game
    db_new_game
    $mail_db = Mail_Database.new
  end
end

class Scene_Save
  alias db_save_data write_save_data
  def write_save_data(file)
    db_save_data(file)
    Marshal.dump($mail_db, file)
  end
end

class Scene_Load
  alias db_read_data read_save_data
  def read_save_data(file)
    db_read_data(file)
    begin
      $mail_db        = Marshal.load(file)
    rescue EOF
      $mail_db = Mail_Database.new
    end
  end
end



Enjoy!

RPG Fan

EDIT: Minor yet old update and fixed formatting
}




Users browsing this thread: 1 Guest(s)