Send Mail Script

*Created by Taz.*

```
Using "RC_Core.rcm"
; By Naddaz on TAZCO

Function Main()
Player = Actor()
Target = ContextActor()
PName$ = Name(Player)
TName$ = Name(Target)

;mailing system this will trigger when mail is sent.
;runs using 2 dialog windows, one for the wizard and the other for the message to be sent.
;need to add a option to not use the wizard.

    ChatBox$ = OpenDialog(Player, Target, "Mail to send") ; message to send to recipient, will be updated in this text box.
    ChatBox1$ = OpenDialog(Player, Target, "Mail Wizard") ;this dialog box will display instructions on how to send mail.
DialogOutPut(Player, ChatBox1, "NOTE: window behind this one, will update to your message.", 255, 145, 23)
DialogOutPut(Player, ChatBox1, "Enter the name of you would like to send mail to.", 230, 145, 23)
MailNamEnter$ = Input(Player, "Enter name of player", "", 4)

DialogOutPut(Player, ChatBox1, + MailNamEnter + " is this name ok?", 230, 145, 23)
Confname% = Dialoginput(Player, ChatBox1, "No, yes")

    If (Confname = 1) ;Exit make sure to close both dialogs
        DialogOutPut(Player, ChatBox1, "Please restart", 230, 145, 23)
        DialogInput(Player, ChatBox1, "Ok")
        CloseDialog(Player, ChatBox)
        CloseDialog(Player, ChatBox1)
        Return
     Endif
 ;Continue with mailing
DialogOutPut(Player, ChatBox, "NAME: " + MailNamEnter, 230, 145, 23) ;enter name that was entered on the first chatbox.

   CloseDialog(Player, ChatBox1)
   ChatBox1$ = OpenDialog(Player, Target, "Mail Wizard") ;this dialog box will display instructions on how to send mail.
   DialogOutPut(player, ChatBox1, "Enter the subject of you message.", 230, 145, 12)
   SubEnter$ = Input(Player, "Enter subject", "", 4)

    DialogoutPut(Player, ChatBox, "SUBJECT: " + SubEnter, 230, 145, 23) ; enter the subject of the mail to first chatbox

    DialogOutPut(Player, ChatBox1, "Enter your message.", 230, 145, 23)

     MsgEnter$ = Input(Player, "Enter your msg", "", 4)

     DialogOutPut(Player, ChatBox, "MESSAGE: " + MsgEnter, 230, 145, 23)
    CloseDialog(Player, ChatBox1) ;close instructions

     DialogOutPut(Player, ChatBox, "Is this message ok?", 230, 145, 23)
    Msgopt% = DialogInPut(Player, ChatBox, "No,Yes")

         If (Msgopt = 1) ;player picked no end script.
            CloseDialog(Player, ChatBox)
            Return
        Endif

     ;Continue with sending mail

     DialogOutPut(Player, ChatBox, "Send this message?", 230, 145, 23)
    SendMsg% = DialogInput(Player, ChatBox, "No,Yes") ;ask player if this message should be sent.

         If (SendMsg = 1) ;close and get rid of message
            CloseDialog(Player, ChatBox)
            Return
        Endif

     ;Get message ready to send to text file so a player can grab it.

         Mailsend$ = OpenFile(+ MailNamEnter + "Mail.txt") ;attach name to player mail.

         If (Mailsend = 0) ;there is no mail for player, make file.
            PetitonList$ = WriteFile(+ MailNamEnter + "Mail.txt")
            CloseFile(Mailsend) ;close opened mail file
        Else
         ;tell player there is a msg already.
        ;will change to multibale mail at a later date.
            DialogOutPut(Player, ChatBox, + MailNamEnter + " Already has mail, you can not send mail at this time.", 255, 145, 23)
            DialogInput(Player, ChatBox, "Close")
            CloseDialog(Player, ChatBox)
            Return
        Endif
            CloseDialog(Player, ChatBox)
            ChatBox$ = OpenDialog(Player, Target, "Mail Sent")
            ;setup message, that will be stored in a file for player to retrive later.
            Msgtosend$ = "FROM:" + PName + " SUBJECT:" + SubEnter + " MESSAGE:" + MsgEnter

             Mailsend$ = OpenFile(+ MailNamEnter + "Mail.txt") ;attach name to player mail.
            WriteLine(Mailsend, Msgtosend) ;write message from setup above.
            DoEvents(2000)
            DialogOutPut(Player, ChatBox, "Measge has been sent to " + MailNamEnter, 230, 145, 23)
            DialogInput(Player, Chatbox, "Close")
            CloseDialog(Player, ChatBox)
            CloseFile(Mailsend)
         ;End sending mail
End Function

```