RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

S1980 Shard Referral Reward System

Skullx

Wanderer
a great script...very useful and simple! i've been looking for a so good script for a long time...tnk you!
 

Shadow1980

Wanderer
Skullx said:
a great script...very useful and simple! i've been looking for a so good script for a long time...tnk you!

No problem! Please let me know how it turns out, I appreciate the feedback.
 

Sunshine

Wanderer
Shadow1980

I just love this system and am soo glad you are sharing it with us.. Nice to see so many shards using it too.. I hope in the future you will continue to share scripts with us, well I know you need some special for your shard but the ones you can bare to part with I would LOVE to see...

AWSOME

shard owners:
If you are thinking of implementing this I reccomend you do, if you are worried about how hard it is to add to a shard.. do not worry ..he has made it soo easy and gives step by step how to adjust things if you want them adjusted...
 

Shadow1980

Wanderer
Sunshine said:
Shadow1980

I just love this system and am soo glad you are sharing it with us.. Nice to see so many shards using it too.. I hope in the future you will continue to share scripts with us, well I know you need some special for your shard but the ones you can bare to part with I would LOVE to see...

AWSOME

I'll think about it when making future additions to my shard :) Any system I can bare to part with that isn't so big that support would be a nightmare I will consider releasing if I think it is useful & creative enough. There are already enough deeds for x and items y really ;)
 

madphatboy2

Wanderer
I've tried changing the reward. I've got most everything figured out but this part:

RunUO - [www.runuo.com] Version 1.0.0, Build 36918
Scripts: Compiling C# scripts...failed (1 errors, 0 warnings)
- Error: Scripts\Custom\referral\TellAFriend.cs: CS0246: (line 251, column 32)
The type or namespace name 'RoseofTrinsic' could not be found (are you missing a
using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

And here is the section of code it's referring to:

public class ReferrerReward : RoseofTrinsic
{
[Constructable]
public ReferrerReward() : base( 0x234D )
{
Name = String.Format("{0} RoseofTrinsic", TellAFriend.TAFShardName );
LootType = LootType.Blessed;
m_Petals = 0;
Weight = 1.0;
StartSpawnTimer( TimeSpan.FromMinutes( 1.0 ) );
}

With the first reference of RoseofTrinsic being line 251. What am I doing wrong?
 

Shadow1980

Wanderer
madphatboy2 said:
I've tried changing the reward. I've got most everything figured out but this part:



And here is the section of code it's referring to:



With the first reference of RoseofTrinsic being line 251. What am I doing wrong?

There are two ways in which you could solve this.

1 - You could give the actual RoseofTrinsic as a reward, by changing lines 72 and 95 to the correct name of the roseoftrinsic.

2 - Probably the one you want. This line is the issue:

public class ReferrerReward : RoseofTrinsic

You need to define ReferrerReward, in this case base it on the actual RoseofTrinsic, which is an Item and a Securable:
public class RoseOfTrinsic : Item, ISecurable

Your code would be: public class ReferrerReward : Item, ISecurable

It is also quite likely that you need the rest of the code of the RoseofTrinsic for it to work properly. You can for the most part copy/paste this directly from the RoseofTrinsic code, change everything referring to RoseofTrinsic to ReferrerReward, get rid of the labelnumber override, insert a name. Also make sure to take special care about the petals, they are a seperate item within the item and you might not want them to come out as ReferrerRewardPetal in-game ;)

If you had a go and run into some issues, please feel free to post them. I will be happy to provide some assistance.
 

stu

Wanderer
received the following when a new player logged in. Im assuming they are leaving the field blank:
Code:
Server Crash Report
===================

RunUO Version 1.0.0, Build 36918
Operating System: Microsoft Windows NT 5.2.3790.0
.NET Framework: 1.1.4322.2300
Time: 4/28/2006 4:18:01 PM
Mobiles: 21499
Items: 418482
Clients:
- Count: 64

clients removed

Exception:
System.ArgumentNullException: Key cannot be null.
Parameter name: key
   at System.Collections.Hashtable.get_Item(Object key)
   at Server.Accounting.Accounts.GetAccount(String username)
   at Server.TellAFriend.TAFLogin(LoginEventArgs args)
   at Server.LoginEventHandler.Invoke(LoginEventArgs e)
   at Server.Network.PacketHandlers.DoLogin(NetState state, Mobile m)
   at Server.Network.PacketHandlers.PlayCharacter(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns)
   at Server.Network.MessagePump.Slice()
   at Server.Core.Main(String[] args)
 

Shadow1980

Wanderer
stu said:
received the following when a new player logged in. Im assuming they are leaving the field blank:
Code:
Server Crash Report
===================

RunUO Version 1.0.0, Build 36918
Operating System: Microsoft Windows NT 5.2.3790.0
.NET Framework: 1.1.4322.2300
Time: 4/28/2006 4:18:01 PM
Mobiles: 21499
Items: 418482
Clients:
- Count: 64

clients removed

Exception:
System.ArgumentNullException: Key cannot be null.
Parameter name: key
   at System.Collections.Hashtable.get_Item(Object key)
   at Server.Accounting.Accounts.GetAccount(String username)
   at Server.TellAFriend.TAFLogin(LoginEventArgs args)
   at Server.LoginEventHandler.Invoke(LoginEventArgs e)
   at Server.Network.PacketHandlers.DoLogin(NetState state, Mobile m)
   at Server.Network.PacketHandlers.PlayCharacter(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns)
   at Server.Network.MessagePump.Slice()
   at Server.Core.Main(String[] args)

Hi stu,

Just to get some things straight - what are your settings for the TAF System, and which version are you using?
Also did you make any modifications?

With more information it will be easier to track down the problem :)
 

stu

Wanderer
I made no modifications..............my script is as follows:
Code:
/* 
 * RunUO Shard Referral System
 * Author: Shadow1980
 * Files: TellAFriend.cs
 * Version 1.3
 * Public Release: 17-04-2006
 * 
 * Description:
 * This system allows you to reward players for bringing friends into the shard. 
 * When a new player joins, they receive a gump asking them who referred them to the shard.
 * They can enter the account name of the person in question there, which will add two tags to their account.
 * Once certain configurable conditions are met, the referrer will receive a reward.
 * Everything is handled on login, so to receive a reward for a referral both accounts have to remain active.
 * 
 * Please note only the referrer receives a reward, but you can easely give a reward to the new player as well.
 * To do this, uncomment lines 69 and 70. The reward can be found at line 206. Modify as you see fit.
 */
using System;
using Server.Accounting;
using Server.Network;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;

namespace Server
{
	public class TellAFriend
	{
		// Configure Required Ingame Time For Both New Player and Referrer Before a Reward is given:
		public static readonly TimeSpan RewardTime = TimeSpan.FromHours( 80.0 );
		// Both Accounts need to have logged in during the last x days set here:
		public static readonly DateTime mindate = DateTime.Now - TimeSpan.FromDays( 7.0 );
		// New Player Account has this many days to enter a referrer & also requires to be this old before a reward is given to the referrer:
		public static readonly DateTime age = DateTime.Now - TimeSpan.FromDays( 7.0 );
		// Edit Shard Name
		public static readonly string TAFShardName = "removed";
	
		public static void Initialize()
		{
			EventSink.Login += new LoginEventHandler( TAFLogin );
		}
	
		private static void TAFLogin( LoginEventArgs args )
		{
			Mobile m = args.Mobile;
			Account ac = (Account)m.Account;
			bool toldfriend = ToldAFriend( m );
			bool gotfriend = GotAFriend( m );
			if ( ac.Created >= age )
			{
				if ( !toldfriend )
				{
				m.SendGump( new TAFGump( m ) );
				}
			}
			else if ( toldfriend )
			{
				string friend = ac.GetTag( "Referrer" );
				Account friendacct = Accounts.GetAccount( friend );
				if ( friendacct == null )
				{
					ac.RemoveTag( "Referrer" );
				}
				else
				{
					if ( ac.LastLogin > mindate && friendacct.LastLogin > mindate && ac.TotalGameTime >= RewardTime && friendacct.TotalGameTime >= RewardTime )
					{
						m.SendMessage( String.Format( "Your friend {0} will receive a reward for referring you to {1} next time (s)he logs in.", friend, TAFShardName ) );
						//m.SendMessage( String.Format( "You receive a reward for your loyalty to {0}.", friend, TAFShardName ) );
						//m.AddToBackpack( new ReferrerReward() );
						friendacct.SetTag( "GotAFriend", "true" );
						friendacct.SetTag( "GotFriend", ac.ToString() );
						ac.RemoveTag( "Referrer" );
						ac.RemoveTag( "ToldAFriend" );
					}
				}
			}
			else if ( gotfriend )
			{
				string friend = ac.GetTag( "GotFriend" );
				m.SendMessage( String.Format( "You receive a reward for referring your friend {0} to {1}.", friend, TAFShardName ) );
				m.AddToBackpack( new ReferrerReward() );
				ac.RemoveTag( "GotAFriend" );
				ac.RemoveTag( "GotFriend" );
			}
		}
	
		public class TAFGump : Gump
		{
			private NetState m_State;
			public TAFGump( Mobile from ) : this( from, "" )
			{
			}
			private string tere;
			private const int LabelColor32 = 0xFFFFFF;

			public string Center( string text )
			{
				return String.Format( "<CENTER>{0}</CENTER>", text );
			}

			public string Color( string text, int color )
			{
				return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
			}
			public TAFGump( Mobile from, string initialText ) : base( 30, 20 )
			{
				if ( from == null )
					return;

           	 	this.AddPage(1);
				this.AddBackground(50, 0, 479, 309, 9270);
				Mobile m_from = from;
				Account tgt = (Account)from.Account;
				int terg = tgt.TotalGameTime.Days;
				int terh = tgt.TotalGameTime.Hours;
				int teri = tgt.TotalGameTime.Minutes;
				int terj = tgt.TotalGameTime.Seconds;				
				tere = from.Name;

				this.AddImage(0, 0, 10400);
				this.AddImage(0, 225, 10402);
				this.AddImage(495, 0, 10410);
				this.AddImage(495, 225, 10412);
				this.AddImage(60, 15, 5536);
				this.AddImage(275, 15, 1025);
				this.AddLabel(205, 43, 88, "Account Name" );
				this.AddLabel(205, 57, 0x480, from.Account.ToString() );
				this.AddLabel(355, 43, 88, "Online Character" );
				this.AddLabel(355, 57, 50, tere );
				this.AddLabel(205, 80, 88, "Total Game Time" );
				this.AddLabel(205, 100, 50, terg.ToString() + " Days." );
				this.AddLabel(205, 115, 50, terh.ToString() + " Hours." );
				this.AddLabel(205, 130, 50, teri.ToString() + " Minutes." );
				this.AddLabel(205, 145, 50, terj.ToString() + " Seconds." );				
				bool toldfriend = ToldAFriend( from );
				if ( !toldfriend )
				{
				this.AddLabel(205, 175, 50, String.Format("Who referred you to {0}?", TAFShardName ) );
				this.AddButton(450, 200, 4023, 4025, 1, GumpButtonType.Reply, 0); //Okay for acct name button
				this.AddImageTiled(300, 200, 140, 20, 0xBBC );
				this.AddTextEntry(300, 200, 140, 20, 1152, 2, "");
				this.AddLabel(205, 200, 88, "Account Name:" );
				}
				else
				{
				Account tagacct=(Account)from.Account;
				string referrer = tagacct.GetTag("Referrer");
				this.AddLabel(205, 200, 88, "Referrer:" );
				this.AddLabel(300, 200, 0x480, referrer );
				}
				this.AddHtml(205, 230, 205, 56,  Color( Center( initialText ), 0xFF0000 ) , false, false);
		 	}

			public override void OnResponse( NetState state, RelayInfo info )
			{
				Mobile from = state.Mobile;
				Account acct = (Account)from.Account;
				int id = info.ButtonID;
				
				if( id == 1 )
				{
					string input = info.GetTextEntry( 2 ).Text;					
					Account tafacc = Accounts.GetAccount( input );					
					string initialText = "";
					
					if ( tafacc == null )
					{
						initialText = String.Format( "Account: '{0}' NOT found", input );
					}
					else if ( input == "" )
					{
						initialText = "Please enter a valid Account name.";
					}
					else if ( input == acct.ToString() )
					{
						initialText = "You can't enter you own Account name!";
					}
					else
					{
						initialText = String.Format( "{0} Marked as Referrer", tafacc );
						acct.SetTag( "ToldAFriend", "true" );
						acct.SetTag( "Referrer", tafacc.ToString() );
					}
					from.SendGump( new TAFGump( from, initialText ) );
				}
			}
		}
	 	private static bool ToldAFriend( Mobile m )
        {
            Account acct=(Account)m.Account;
            bool told = Convert.ToBoolean( acct.GetTag("ToldAFriend") );
            if ( !told )
               	return false;
            return true;
    	}
        private static bool GotAFriend( Mobile m )
        {
        	Account acct=(Account)m.Account;
           	bool got = Convert.ToBoolean( acct.GetTag("GotAFriend") );
            if ( !got )
            	return false;
           	return true;
    	}
    }
	public class ReferrerReward : HalfApron
	{
		[Constructable]
		public ReferrerReward() : base()
		{
			Name = String.Format("{0} Referrer Apron", TellAFriend.TAFShardName );
			Hue = 1266;
			LootType = LootType.Blessed;
			Attributes.DefendChance = 10;
			Resistances.Poison = 5;
		}

		public ReferrerReward(Serial serial) : base(serial)
		{
		}

		public override void Serialize(GenericWriter writer)
		{
			base.Serialize(writer);

			writer.Write((int) 0);
		}

		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize(reader);

			int version = reader.ReadInt();
		}
	}	
}
 

Shadow1980

Wanderer
For your version ( 1.3 ) please try this:

Code:
	/* 
 * RunUO Shard Referral System
 * Author: Shadow1980
 * Files: TellAFriend.cs
 * Version 1.3
 * Public Release: 17-04-2006
 * 
 * Description:
 * This system allows you to reward players for bringing friends into the shard. 
 * When a new player joins, they receive a gump asking them who referred them to the shard.
 * They can enter the account name of the person in question there, which will add two tags to their account.
 * Once certain configurable conditions are met, the referrer will receive a reward.
 * Everything is handled on login, so to receive a reward for a referral both accounts have to remain active.
 * 
 * Please note only the referrer receives a reward, but you can easely give a reward to the new player as well.
 * To do this, uncomment lines 69 and 70. The reward can be found at line 206. Modify as you see fit.
 */
using System;
using Server.Accounting;
using Server.Network;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;

namespace Server
{
	public class TellAFriend
	{
		// Configure Required Ingame Time For Both New Player and Referrer Before a Reward is given:
		public static readonly TimeSpan RewardTime = TimeSpan.FromHours( 80.0 );
		// Both Accounts need to have logged in during the last x days set here:
		public static readonly DateTime mindate = DateTime.Now - TimeSpan.FromDays( 7.0 );
		// New Player Account has this many days to enter a referrer & also requires to be this old before a reward is given to the referrer:
		public static readonly DateTime age = DateTime.Now - TimeSpan.FromDays( 7.0 );
		// Edit Shard Name
		public static readonly string TAFShardName = "removed";
	
		public static void Initialize()
		{
			EventSink.Login += new LoginEventHandler( TAFLogin );
		}
	
		private static void TAFLogin( LoginEventArgs args )
		{
			Mobile m = args.Mobile;
			Account ac = (Account)m.Account;
			bool toldfriend = ToldAFriend( m );
			bool gotfriend = GotAFriend( m );
			if ( ac.Created >= age )
			{
				if ( !toldfriend )
				{
				m.SendGump( new TAFGump( m ) );
				}
			}
			else if ( toldfriend )
			{
				string friend = ac.GetTag( "Referrer" );
                                if ( friend == null )
                                {
                                ac.RemoveTag( "ToldAFriend" );
                                }
                                else
                                {
				Account friendacct = Accounts.GetAccount( friend );

				if ( friendacct == null )
				{
					ac.RemoveTag( "Referrer" );
				}
				else
				{
					if ( ac.LastLogin > mindate && friendacct.LastLogin > mindate && ac.TotalGameTime >= RewardTime && friendacct.TotalGameTime >= RewardTime )
					{
						m.SendMessage( String.Format( "Your friend {0} will receive a reward for referring you to {1} next time (s)he logs in.", friend, TAFShardName ) );
						//m.SendMessage( String.Format( "You receive a reward for your loyalty to {0}.", friend, TAFShardName ) );
						//m.AddToBackpack( new ReferrerReward() );
						friendacct.SetTag( "GotAFriend", "true" );
						friendacct.SetTag( "GotFriend", ac.ToString() );
						ac.RemoveTag( "Referrer" );
						ac.RemoveTag( "ToldAFriend" );
					}
				}
                                }
			}
			else if ( gotfriend )
			{
				string friend = ac.GetTag( "GotFriend" );
				m.SendMessage( String.Format( "You receive a reward for referring your friend {0} to {1}.", friend, TAFShardName ) );
				m.AddToBackpack( new ReferrerReward() );
				ac.RemoveTag( "GotAFriend" );
				ac.RemoveTag( "GotFriend" );
			}
		}
	
		public class TAFGump : Gump
		{
			private NetState m_State;
			public TAFGump( Mobile from ) : this( from, "" )
			{
			}
			private string tere;
			private const int LabelColor32 = 0xFFFFFF;

			public string Center( string text )
			{
				return String.Format( "<CENTER>{0}</CENTER>", text );
			}

			public string Color( string text, int color )
			{
				return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
			}
			public TAFGump( Mobile from, string initialText ) : base( 30, 20 )
			{
				if ( from == null )
					return;

           	 	this.AddPage(1);
				this.AddBackground(50, 0, 479, 309, 9270);
				Mobile m_from = from;
				Account tgt = (Account)from.Account;
				int terg = tgt.TotalGameTime.Days;
				int terh = tgt.TotalGameTime.Hours;
				int teri = tgt.TotalGameTime.Minutes;
				int terj = tgt.TotalGameTime.Seconds;				
				tere = from.Name;

				this.AddImage(0, 0, 10400);
				this.AddImage(0, 225, 10402);
				this.AddImage(495, 0, 10410);
				this.AddImage(495, 225, 10412);
				this.AddImage(60, 15, 5536);
				this.AddImage(275, 15, 1025);
				this.AddLabel(205, 43, 88, "Account Name" );
				this.AddLabel(205, 57, 0x480, from.Account.ToString() );
				this.AddLabel(355, 43, 88, "Online Character" );
				this.AddLabel(355, 57, 50, tere );
				this.AddLabel(205, 80, 88, "Total Game Time" );
				this.AddLabel(205, 100, 50, terg.ToString() + " Days." );
				this.AddLabel(205, 115, 50, terh.ToString() + " Hours." );
				this.AddLabel(205, 130, 50, teri.ToString() + " Minutes." );
				this.AddLabel(205, 145, 50, terj.ToString() + " Seconds." );				
				bool toldfriend = ToldAFriend( from );
				if ( !toldfriend )
				{
				this.AddLabel(205, 175, 50, String.Format("Who referred you to {0}?", TAFShardName ) );
				this.AddButton(450, 200, 4023, 4025, 1, GumpButtonType.Reply, 0); //Okay for acct name button
				this.AddImageTiled(300, 200, 140, 20, 0xBBC );
				this.AddTextEntry(300, 200, 140, 20, 1152, 2, "");
				this.AddLabel(205, 200, 88, "Account Name:" );
				}
				else
				{
				Account tagacct=(Account)from.Account;
				string referrer = tagacct.GetTag("Referrer");
				this.AddLabel(205, 200, 88, "Referrer:" );
				this.AddLabel(300, 200, 0x480, referrer );
				}
				this.AddHtml(205, 230, 205, 56,  Color( Center( initialText ), 0xFF0000 ) , false, false);
		 	}

			public override void OnResponse( NetState state, RelayInfo info )
			{
				Mobile from = state.Mobile;
				Account acct = (Account)from.Account;
				int id = info.ButtonID;
				
				if( id == 1 )
				{
					string input = info.GetTextEntry( 2 ).Text;					
					Account tafacc = Accounts.GetAccount( input );					
					string initialText = "";
					
					if ( tafacc == null )
					{
						initialText = String.Format( "Account: '{0}' NOT found", input );
					}
					else if ( input == "" )
					{
						initialText = "Please enter a valid Account name.";
					}
					else if ( input == acct.ToString() )
					{
						initialText = "You can't enter you own Account name!";
					}
					else
					{
						initialText = String.Format( "{0} Marked as Referrer", tafacc );
						acct.SetTag( "ToldAFriend", "true" );
						acct.SetTag( "Referrer", tafacc.ToString() );
					}
					from.SendGump( new TAFGump( from, initialText ) );
				}
			}
		}
	 	private static bool ToldAFriend( Mobile m )
        {
            Account acct=(Account)m.Account;
            bool told = Convert.ToBoolean( acct.GetTag("ToldAFriend") );
            if ( !told )
               	return false;
            return true;
    	}
        private static bool GotAFriend( Mobile m )
        {
        	Account acct=(Account)m.Account;
           	bool got = Convert.ToBoolean( acct.GetTag("GotAFriend") );
            if ( !got )
            	return false;
           	return true;
    	}
    }
	public class ReferrerReward : HalfApron
	{
		[Constructable]
		public ReferrerReward() : base()
		{
			Name = String.Format("{0} Referrer Apron", TellAFriend.TAFShardName );
			Hue = 1266;
			LootType = LootType.Blessed;
			Attributes.DefendChance = 10;
			Resistances.Poison = 5;
		}

		public ReferrerReward(Serial serial) : base(serial)
		{
		}

		public override void Serialize(GenericWriter writer)
		{
			base.Serialize(writer);

			writer.Write((int) 0);
		}

		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize(reader);

			int version = reader.ReadInt();
		}
	}	
}

I will look into this issue and see if I can come up with a better solution for the current release. Thanks for letting me know.
I am not entirely sure how it would have happened though, can people delete their accounts on your shard? The player must have entered a referrer to get the tag ToldAFriend, but for this crash to happen the tag Referrer could not have been valid anymore.
Any information you might have is welcome, please let me know if above 'fix' helped.
 
stu said:
received the following when a new player logged in. Im assuming they are leaving the field blank:
Code:
Server Crash Report
===================
 
RunUO Version 1.0.0, Build 36918
Operating System: Microsoft Windows NT 5.2.3790.0
.NET Framework: 1.1.4322.2300
Time: 4/28/2006 4:18:01 PM
Mobiles: 21499
Items: 418482
Clients:
- Count: 64
 
clients removed
 
Exception:
System.ArgumentNullException: Key cannot be null.
Parameter name: key
   at System.Collections.Hashtable.get_Item(Object key)
   at Server.Accounting.Accounts.GetAccount(String username)
   at Server.TellAFriend.TAFLogin(LoginEventArgs args)
   at Server.LoginEventHandler.Invoke(LoginEventArgs e)
   at Server.Network.PacketHandlers.DoLogin(NetState state, Mobile m)
   at Server.Network.PacketHandlers.PlayCharacter(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns)
   at Server.Network.MessagePump.Slice()
   at Server.Core.Main(String[] args)
Ive been using this about 6 days now and now I'm getting the same crash! Wtf?
 

Shadow1980

Wanderer
autumntwilight said:
Ive been using this about 6 days now and now I'm getting the same crash! Wtf?

What version are you using & do you have any other information than 'wtf' ?

Have you tried the fix posted ONE post above this?

Mind you - Our shard is using this system as well and we have had no crashes yet. Could you please attach the version you are currently using, including all settings/changes you made to it.
 

Sunshine

Wanderer
We too are getting crashes suddenly

the same crash report using verion 1,5

we think that the player who logs in each time and we crash is ready for his reward time.

Can we safely remove this and not cause mroe serious issues like loosing players accounts?
We removed the script in the test shard but the account remains tagged as TAF = true



Code:
/* 
 * RunUO Shard Referral System
 * Author: Shadow1980
 * Files: TellAFriend.cs
 * Version 1.5
 * Public Release: 17-04-2006 || Latest Release 20-04-2006
 * 
 * Description:
 * This system allows you to reward players for bringing friends into the shard. 
 * When a new player joins, they receive a gump asking them who referred them to the shard.
 * They can enter the account name of the person in question there, which will add two tags to their account.
 * v1.4+ they can also target a player character ingame and there is no mention of Account Name anywhere.
 * Once certain configurable conditions are met, the referrer will receive a reward.
 * Everything is handled on login, so to receive a reward for a referral both accounts have to remain active.
 * 
 * Please note only the referrer receives a reward, but you can easely give a reward to the new player as well.
 * To do this, uncomment lines 71 and 72. The reward can be found at line 251. Modify as you see fit.
 */
using System;
using Server.Accounting;
using Server.Network;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
namespace Server
{
 public class TellAFriend
 {
  // Configure Required Ingame Time For Both New Player and Referrer Before a Reward is given:
  public static readonly TimeSpan RewardTime = TimeSpan.FromHours( 120.0 );
  // Both Accounts need to have logged in during the last x days set here:
  public static readonly DateTime mindate = DateTime.Now - TimeSpan.FromDays( 7.0 );
  // New Player Account has this many days to enter a referrer & also requires to be this old before a reward is given to the referrer:
  public static readonly DateTime age = DateTime.Now - TimeSpan.FromDays( 7.0 );
  // Edit Shard Name
  public static readonly string TAFShardName = "Reality Bites";
 
  public static void Initialize()
  {
   EventSink.Login += new LoginEventHandler( TAFLogin );
  }
 
  private static void TAFLogin( LoginEventArgs args )
  {
   Mobile m = args.Mobile;
   Account ac = (Account)m.Account;
   bool toldfriend = ToldAFriend( m );
   bool gotfriend = GotAFriend( m );
   if ( ac.Created >= age )
   {
    if ( !toldfriend )
    {
    m.SendGump( new TAFGump( m ) );
    }
   }
   else if ( toldfriend )
   {
    string friend = ac.GetTag( "Referrer" );
    Account friendacct = Accounts.GetAccount( friend );
    if ( friendacct == null )
    {
     ac.RemoveTag( "Referrer" );
    }
    else
    {
     if ( ac.LastLogin > mindate && friendacct.LastLogin > mindate && ac.TotalGameTime >= RewardTime && friendacct.TotalGameTime >= RewardTime )
     {
      m.SendMessage( String.Format( "Your friend will receive a reward for referring you to {1} next time (s)he logs in.", TAFShardName ) );
      m.SendMessage( String.Format( "You receive a reward for your loyalty to {0}.", TAFShardName ) );
      m.AddToBackpack( new LoyalToken() );
      if ( Convert.ToBoolean( ac.GetTag("GotAFriend") ) ) 
      {
       string friends = ac.GetTag( "GotFriend" ) + "," + ac.ToString();
       friendacct.SetTag( "GotFriend", friends );
      } 
      else 
      {
       friendacct.SetTag( "GotAFriend", "true" );
       friendacct.SetTag( "GotFriend", ac.ToString() );
      }      
      ac.RemoveTag( "Referrer" );
      ac.RemoveTag( "ToldAFriend" );
     }
    }
   }
   else if ( gotfriend )
   {
    string friend = ac.GetTag( "GotFriend" );
    string[] friends = friend.Split(',');
    for(int i=0;i<friends.Length;++i)
    {
     m.SendMessage( String.Format( "You receive a reward for referring one of your friends to {1}.", TAFShardName ) );
     m.AddToBackpack( new ReferralToken() );
    }    
    ac.RemoveTag( "GotAFriend" );
    ac.RemoveTag( "GotFriend" );
   }
  }
 
  public class TAFGump : Gump
  {
   private NetState m_State;
   public TAFGump( Mobile from ) : this( from, "" )
   {
   }
   private string tere;
   private const int LabelColor32 = 0xFFFFFF;
   public string Center( string text )
   {
    return String.Format( "<CENTER>{0}</CENTER>", text );
   }
   public string Color( string text, int color )
   {
    return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
   }
   public TAFGump( Mobile from, string initialText ) : base( 30, 20 )
   {
    if ( from == null )
     return;
              this.AddPage(1);
    this.AddBackground(50, 0, 479, 309, 5054);
    Mobile m_from = from;
    Account tgt = (Account)from.Account;
    int terg = tgt.TotalGameTime.Days;
    int terh = tgt.TotalGameTime.Hours;
    int teri = tgt.TotalGameTime.Minutes;
    int terj = tgt.TotalGameTime.Seconds;    
    tere = from.Name;
    this.AddImage(0, 0, 10400, 1160);
    this.AddImage(0, 225, 10402, 1160);
    this.AddImage(495, 0, 10410, 1160);
    this.AddImage(495, 225, 10412, 1160);
    this.AddImage(60, 15, 5536);
    this.AddLabel(215, 15, 43, "Welcome to Reality Bites" );
    //this.AddImage(215, 15, 1025);//275 to 205
    this.AddLabel(140, 43, 43, "Account Name" );//135 TO 205 43 50
    this.AddLabel(140, 57, 50, from.Account.ToString() );
    this.AddLabel(335, 43, 43, "Online Character" );
    this.AddLabel(335, 57, 50, tere );
    this.AddLabel(140, 80, 43, "Total Game Time" );
    this.AddLabel(140, 100, 50, terg.ToString() + " Days." );
    this.AddLabel(140, 115, 50, terh.ToString() + " Hours." );
    this.AddLabel(140, 130, 50, teri.ToString() + " Minutes." );
    this.AddLabel(140, 145, 50, terj.ToString() + " Seconds." );    
    bool toldfriend = ToldAFriend( from );
    if ( !toldfriend )
    {
    this.AddLabel(140, 175, 43, String.Format("Who referred you to {0}?", TAFShardName ) );
    this.AddButton(450, 200, 4023, 4025, 1, GumpButtonType.Reply, 0); //Okay for acct name button 4205
    this.AddImageTiled(300, 200, 140, 20, 0xBBC );
    this.AddTextEntry(300, 200, 140, 20, 1152, 2, "");
    this.AddLabel(140, 200, 43, "Account Name:" );
    this.AddLabel(140, 230, 43, "If no one referred you enter account name gift" );
    this.AddLabel(140, 260, 43, "Or target your friend's character:" );
    this.AddButton(450, 260, 4023, 4025, 2, GumpButtonType.Reply, 0); //Target player button
    }
    else
    {
    this.AddLabel(140, 200, 88, "You now entered a referrer." );
    }
    this.AddHtml(140, 245, 205, 56,  Color( Center( initialText ), 0xFF0000 ) , false, false);
    }
   public override void OnResponse( NetState state, RelayInfo info )
   {
    Mobile from = state.Mobile;
    Account acct = (Account)from.Account;
    int id = info.ButtonID;
 
    if( id == 1 )
    {
     string input = info.GetTextEntry( 2 ).Text;     
     Account tafacc = Accounts.GetAccount( input );     
     string initialText = "";
 
     if ( tafacc == null )
     {
      initialText = String.Format( "Account: '{0}' NOT found", input );
     }
     else if ( input == "" )
     {
      initialText = "Please enter a valid Account name.";
     }
     else if ( input == acct.ToString() )
     {
      initialText = "You can't use your own account name!";
     }
     else
     {
      initialText = String.Format( "{0} Marked as Referrer", tafacc );
      acct.SetTag( "ToldAFriend", "true" );
      acct.SetTag( "Referrer", tafacc.ToString() );
     }
     from.SendGump( new TAFGump( from, initialText ) );
    }
    if ( id == 2 )
    {
     from.BeginTarget( 10, false, TargetFlags.None, new TargetCallback( TAFTarget ) );
     from.SendMessage( String.Format("Please target the character of the person who referred you to {0}", TAFShardName ) );
    }
   }
            public void TAFTarget( Mobile from, object target )
            {
             string initialText = "";
             if ( target is PlayerMobile && target != null )
             {
              Mobile friend = (Mobile)target;
              Account fracct = (Account)friend.Account;
     Account acct = (Account)from.Account;
 
     if ( fracct == acct )
     {
         initialText = "You can't be your own referrer!";
     }
     else
     {
      initialText = String.Format( "{0} Marked as Referrer", friend.Name );
      friend.SendMessage( String.Format("{0} has just marked you as referrer to {1}.", from.Name, TAFShardName ) );
      acct.SetTag( "ToldAFriend", "true" );
      acct.SetTag( "Referrer", fracct.ToString() );
     }
             }
             else
             {
              initialText = "Please select a player character.";
             }
             from.SendGump( new TAFGump( from, initialText ) );
            }
  }
   private static bool ToldAFriend( Mobile m )
        {
            Account acct=(Account)m.Account;
            bool told = Convert.ToBoolean( acct.GetTag("ToldAFriend") );
            if ( !told )
                return false;
            return true;
     }
        private static bool GotAFriend( Mobile m )
        {
         Account acct=(Account)m.Account;
            bool got = Convert.ToBoolean( acct.GetTag("GotAFriend") );
            if ( !got )
             return false;
            return true;
     }
    }
 public class ReferrerReward : HalfApron
 {
  [Constructable]
  public ReferrerReward() : base()
  {
   Name = String.Format("{0} Referral Apron", TellAFriend.TAFShardName );
   Hue = 1968;
   Attributes.DefendChance = 10;
   Resistances.Poison = 5;
  }
  public ReferrerReward(Serial serial) : base(serial)
  {
  }
  public override void Serialize(GenericWriter writer)
  {
   base.Serialize(writer);
   writer.Write((int) 0);
  }
  public override void Deserialize(GenericReader reader)
  {
   base.Deserialize(reader);
   int version = reader.ReadInt();
  }
 } 
}
 

Shadow1980

Wanderer
Hi Sunshine - you can safely remove it, the account tags will not be called unless the script is active.
I will try to reserve some time tommorow evening to look into this and post a fix.

Edit: Would you mind sending me a crashlog? A debug crashlog would be ideal but a normal one will already be helpful as well.
My email address is in my signature. (Click on my nickname)
Thanks a lot in advance!
 

Shadow1980

Wanderer
Update to v1.6 to fix the reported crash issue.

Sunshine - Thanks a lot to you and your husband for the debug crash report. I will reply to your husbands e-mail and sent you a fixed version directly so you don't have to do anything but drop it into customs.
If you could test in debug if you can make it crash again I would most appreciate it. Please let me know if there are any further problems - I will fix them as soon as possible.
 

brainless

Wanderer
It seemed to work correctly now. I entered test shard with the character I had crashing before and the system told me that my referrer would get their reward when they log in and so on. We are glad we were able to help you on this.

I didn't run the shard in debug mode though. Should I still do that? It worked okay.
 

Shadow1980

Wanderer
brainless said:
It seemed to work correctly now. I entered test shard with the character I had crashing before and the system told me that my referrer would get their reward when they log in and so on. We are glad we were able to help you on this.

I didn't run the shard in debug mode though. Should I still do that? It worked okay.

Thanks a lot, that is just fine. Running in debug wont make a difference, all it really does is provide more detailed crash reports. It's extremely useful when trying to fix issues like this. The error that caused the crash was so minor that I would have overlooked it without, so your debug crashlog was extremely useful! ;)
 

Sunshine

Wanderer
You are very welcome and we thank you for such a fast response and nice repair ....love this script and think you are a great guy ..thanks again


Have a super day
 

Shadow1980

Wanderer
Sunshine said:
You are very welcome and we thank you for such a fast response and nice repair ....love this script and think you are a great guy ..thanks again


Have a super day

Very nice words - almost makes me forget I had a crap day at work! (Internet was down and I require the internet to do my job, I had to take an employee home so both of us could actually do some work. The internet problems are really starting to annoy me.)
 

Sunshine

Wanderer
ahh I am sorry I sure hope the rest the night gets better for you. But then being such a bad day will not take much to get better I am sure.

-mentally sends commands across the ocean- Internet will act right and will be better than ever for Shadow


There now you will never have to worry agian ;)
 
Top