zolo8

Member
So I have this code....(Below) - It allows me to capture players emails (All working well so far).
I would like to reward players who provide the email with a small gift..... how would i best add a line or two to drop an item in there backpack when they give me there email? (Setemail.cs is not my script, but i do like it).

I tried just adding "AddItem(new Lemon()); break;" or Addtopack and pack.DropItem... but failure.... anyone have an idea?

using Server;
using System;
using Server.Gumps;
using Server.Items;
using Server.Accounting;
using Server.Commands;
using Server.Network;
namespace Server.Gumps
{
public class SetEMail : Gump
{
public static void Initialize()
{
CommandSystem.Register ( "setemail", AccessLevel.Player, new CommandEventHandler ( Email_OnCommand ) );
}
public static void Email_OnCommand( CommandEventArgs e )
{
Account acct = e.Mobile.Account as Account;
string MailString = acct.GetTag( "EMailRecieved" );
if( MailString != null )
{
e.Mobile.SendMessage( "E-Mail has already been set" );
}
else
{
e.Mobile.CloseGump( typeof ( SetEMail ) );
e.Mobile.SendGump( new SetEMail() );
}
}
public SetEMail() : base(0, 0)
{
this.Closable = true;
this.Disposable = true;
this.Dragable = true;
this.Resizable = false;
this.AddPage(0);
this.AddBackground(133, 77, 414, 206, 3600);
this.AddLabel(279, 97, 1150, @"Set E-Mail");
this.AddLabel(160, 130, 1150, @"Magic Word:"); //1299
this.AddLabel(160, 160, 1150, @"E-Mail:");
this.AddLabel(160, 190, 1150, @"Confirm E-Mail:");
this.AddButton(306, 230, 247, 248, 1, GumpButtonType.Reply, 0);
this.AddAlphaRegion(321, 190, 200, 20);
this.AddAlphaRegion(321, 160, 200, 20);
this.AddAlphaRegion(321, 130, 200, 20);
this.AddTextEntry( 321, 130, 200, 20, 1175, 1, "");
this.AddTextEntry( 321, 160, 200, 20, 1175, 2, "");
this.AddTextEntry( 321, 190, 200, 20, 1175, 3, "");
}
private string GetString(RelayInfo info, int id)
{
TextRelay t = info.GetTextEntry(id);
return (t == null ? null : t.Text.Trim());
}
public override void OnResponse(NetState sender, RelayInfo info)
{
Mobile m = sender.Mobile;
switch (info.ButtonID)
{
case 0:
{
m.SendMessage(1278, "Your e-mail has not been set.");
return;
}
case 1:
{
string MagicWord = GetString( info, 1 );
string EMAIL = GetString( info, 2 );
string confirmEMAIL = GetString( info, 3 );
Account acct = m.Account as Account;
if ( EMAIL.Length <= 6 || MagicWord.Length <= 3 || EMAIL.Length > 40 || MagicWord.Length > 40 )
{
acct.RemoveTag( "EMAIL" );
m.CloseGump( typeof( SetEMail ) );
m.SendGump( new SetEMail() );
m.SendMessage(37, "Your e-mail must be at least 7 letters or numbers. Magic Word must be at least 4 letters or numbers.");
return;
}
if ( EMAIL != confirmEMAIL )
{
m.SendMessage(37, "The 'E-mail' values do not match. Remember it is cAsE sEnSaTiVe. ");
m.CloseGump( typeof( SetEMail ) );
m.SendGump( new SetEMail() );
return;
}
if ( EMAIL != null && MagicWord != null)
{
acct.SetTag( "EMailRecieved", " ( " + EMAIL + " ) " );
acct.SetTag( "MagicWord", " ( " + MagicWord + " ) " );
m.SendMessage(68, "Your Magic Word is '" + MagicWord + "' and your e-mail is '" + EMAIL + "'. Remember this!");
}
break;
}
}
}
}
}
 
Got it working.. I think.....

I added this.... to the end of the scripts (Tested with axe of heavens).
if ( EMAIL != null && MagicWord != null)
{
acct.SetTag( "EMailRecieved", " ( " + EMAIL + " ) " );
acct.SetTag( "MagicWord", " ( " + MagicWord + " ) " );
Item item = new AxeOfTheHeavens();
m.AddToBackpack( item );
}
Seems to work.
 
Glad you did get this working, I was going to suggest something like this, but then I'm not a coder :)
if m.mobile
mobile.AddToBackpack( new ItemNameToGive() );
 
I suck at coding (I have worked in IT for 20 years but mostly on Infra side)...

Really appreciate the help - Its so nice when you get something working lol
 
string MagicWord = GetString( info, 1 );
string EMAIL = GetString( info, 2 );
string confirmEMAIL = GetString( info, 3 );
Account acct = m.Account as Account;
if ( EMAIL.Length <= 6 || MagicWord.Length <= 3 || EMAIL.Length > 40 || MagicWord.Length > 40 )
{
acct.RemoveTag( "EMAIL" );
m.CloseGump( typeof( SetEMail ) );
m.SendGump( new SetEMail() );
m.SendMessage(37, "Your e-mail must be at least 7 letters or numbers. Magic Word must be at least 4 letters or numbers.");
return;
}
if ( EMAIL != confirmEMAIL )
{
m.SendMessage(37, "The 'E-mail' values do not match. Remember it is cAsE sEnSaTiVe. ");
m.CloseGump( typeof( SetEMail ) );
m.SendGump( new SetEMail() );
return;
}
if ( EMAIL != null && MagicWord != null)
{
acct.SetTag( "EMailRecieved", " ( " + EMAIL + " ) " );
acct.SetTag( "MagicWord", " ( " + MagicWord + " ) " );
m.SendMessage(68, "Your Magic Word is '" + MagicWord + "' and your e-mail is '" + EMAIL + "'. Remember this!");
}

One problem I see with this:

When you initialize MagicWord, EMAIL and confirmEMAIL, there is a chance you could set them to null, according to your "GetString" method. The problem is you don't check for null until the 3rd "IF" statement down. This means the first "IF" statement might easily throw a null reference error and crash the shard.
 
oh - right - will have a look. Tested it 10 times (on test shard) but will see if i can figure out what to do.
 
Did you ever figure it out Zolo? I like your code and am just looking for a basic way for players to store their emails incase they forget their passwords but am not the best coder.
 
Will send you what i have - It works and is simple (gives the free gift on player registration).

The original script was some one elses, i just modified it a bit.

Z
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back