ServUO Version
Publish 57
Ultima Expansion
Endless Journey
I can't seem to find the system I used, but it allows gift giving on a yearly bases based on dates. Anyways, trying to add the following and it's not working it compiles but does nothing:
C#:
using System;
using Server;
using Server.Items;
using Server.Gumps;
using Server.Accounting;

namespace Server.Misc
{
    public class VeteranRewards : GiftGiver
    {
        public static void Initialize()
        {
            GiftGiving.Register( new VeteranRewards() );
        }

        public override DateTime Start{ get{ return new DateTime( 1980, 1, 1); } }
        public override DateTime Finish{ get{ return new DateTime( 1980, 12, 31 ); } }
        //public override TimeSpan MinimumAge { get { return TimeSpan.FromSeconds(1); } }

        public override void GiveGift( Mobile mob )
        {
            int hue;

            switch (Utility.Random(21)) // Random number 0 to 20 inclusive
            {
                case 0: hue = Utility.RandomMinMax(1, 1058); break;
                case 1: hue = Utility.RandomMinMax(1102, 1177); break;
                case 2: hue = Utility.RandomMinMax(1190, 1196); break;
                case 3: hue = Utility.RandomMinMax(1201, 1289); break;
                case 4: hue = Utility.RandomMinMax(1301, 1378); break;
                case 5: hue = Utility.RandomMinMax(1401, 1454); break;
                case 6: hue = Utility.RandomMinMax(1458, 1463); break;
                case 7: hue = Utility.RandomMinMax(1501, 1554); break;
                case 8: hue = Utility.RandomMinMax(1601, 1654); break;
                case 9: hue = Utility.RandomMinMax(1701, 1779); break;
                case 10: hue = Utility.RandomMinMax(1801, 1908); break;
                case 11: hue = Utility.RandomMinMax(2001, 2067); break;
                case 12: hue = Utility.RandomMinMax(2101, 2130); break;
                case 13: hue = Utility.RandomMinMax(2201, 2224); break;
                case 14: hue = Utility.RandomMinMax(2301, 2318); break;
                case 15: hue = Utility.RandomMinMax(2401, 2430); break;
                case 16: hue = Utility.RandomMinMax(2498, 2644); break;
                case 17: hue = Utility.RandomMinMax(2651, 2662); break;
                case 18: hue = Utility.RandomMinMax(2671, 2718); break;
                case 19: hue = Utility.RandomMinMax(2958, 2970); break;
                default: hue = Utility.RandomList(2947, 2949, 2951, 2952, 2953, 2955, 2956); break;
            }

            GiftBox box = new GiftBox();
            box.Hue = hue;

            box.DropItem( new FireworksWand() );

            BirthdayCakeGift bc = new BirthdayCakeGift();
            bc.Hue = hue;
            bc.Name = "Test Cake!";
            box.DropItem( bc );

            Account acct = mob.Account as Account;

            if (acct == null)
                return;

            if (acct != null)
            {
                TimeSpan ts = (DateTime.UtcNow - acct.Created);
                if (ts.TotalDays > 3)
                {
                    bool pack = GiveGift(mob, box);
                    mob.SendGump(new GiftPackageGump(pack, "Veteran Rewards!"));
                }
            }
        }
    }
}
I have my date set to this:
C#:
        public override DateTime Start{ get{ return new DateTime( 1980, 1, 1 ); } }
        public override DateTime Finish{ get{ return new DateTime( 1980, 12, 31 ); } }
Here is the gift giving code.
C#:
using System;
using System.Collections.Generic;
using Server.Accounting;
using Server.Gumps;
using Server.Mobiles;
using Server.Items;
using Server.Network;

namespace Server.Misc
{
    public enum GiftResult
    {
        Backpack,
        BankBox
    }

    public class GiftGiving
    {
        private static readonly List<GiftGiver> m_Givers = new List<GiftGiver>();
        public static void Register(GiftGiver giver)
        {
            m_Givers.Add(giver);
        }

        public static void Initialize()
        {
            EventSink.Login += new LoginEventHandler(EventSink_Login);
        }

        private static void EventSink_Login(LoginEventArgs e)
        {
            Account acct = e.Mobile.Account as Account;
            PlayerMobile pm = (PlayerMobile) e.Mobile;
          
            int Minute = DateTime.Now.Minute;
            int Hour = DateTime.Now.Hour;
            int Day = DateTime.Now.Day;
            int Month = DateTime.Now.Month;
            int Year = DateTime.Now.Year;
          
            int GS_Month = 0;
            int GS_Day = 0;
            int GF_Month = 0;
            int GF_Day = 0;
            DateTime GS_Giver = DateTime.Now;

            if (acct == null)
                return;

            DateTime now = DateTime.UtcNow;

            for (int i = 0; i < m_Givers.Count; ++i)
            {
                GiftGiver giver = m_Givers[i];

                GS_Month = giver.Start.Month;
                GS_Day = giver.Start.Day;
                GF_Month = giver.Finish.Month;
                GF_Day = giver.Finish.Day;
                GS_Giver = new DateTime( Year, GS_Month, GS_Day );
              
                if ( giver.Start.Year == 1980)
                {
                    // if you want this to go on every year with zero maintenance
                    if ((GS_Month <= GF_Month) && (Month < GS_Month || Month > GF_Month)) continue; //wrong months
                    if ((GS_Month > GF_Month) && (Month < GS_Month && Month > GF_Month)) continue; //wrong months
                    if (Month == GS_Month && Day < GS_Day) continue; // right month, wrong day
                    if (Month == GF_Month && Day > GF_Day) continue; // right month, wrong day
                }
                else
                {
                    if (now < giver.Start || now >= giver.Finish)
                        continue; // not in the correct timefream
                }

                if (acct.Created > (GS_Giver - giver.MinimumAge))  //(giver.Start - giver.MinimumAge))
                    continue; // newly created account

                //if (acct.LastLogin >= giver.Start)
                if (pm.LastOnline >= GS_Giver)
                    continue; // already got one

                giver.DelayGiveGift(TimeSpan.FromSeconds(5.0), e.Mobile);

            }

            //acct.LastLogin = now;
            pm.LastOnline = now;
        }
    }

    public abstract class GiftGiver
    {
        public virtual TimeSpan MinimumAge
        {
            get
            {
                return TimeSpan.FromDays(30.0);
            }
        }
        public abstract DateTime Start { get; }
        public abstract DateTime Finish { get; }
        public abstract void GiveGift(Mobile mob);

        public virtual void DelayGiveGift(TimeSpan delay, Mobile mob)
        {
            Timer.DelayCall(delay, new TimerStateCallback(DelayGiveGift_Callback), mob);
        }
      
        protected virtual void DelayGiveGift_Callback(object state)
        {
            this.GiveGift((Mobile)state);
        }
      
        public virtual bool GiveGift( Mobile mob, Item item )
        {
            if ( mob.PlaceInBackpack( item ) )
            {
                if ( !WeightOverloading.IsOverloaded( mob ) )
                    return true;
            }

            mob.BankBox.DropItem( item );
            return false;
        }
    
    }
}

namespace Server.Gumps
{
    public class GiftPackageGump : Gump
    {
        public GiftPackageGump(bool ToBackpack, string HolidayMessage) : base( 100, 100 )
        {
            string destination = (ToBackpack ? "Backpack":"Bank Box");
            this.Closable=true;
            this.Disposable=true;
            this.Dragable=true;
            this.Resizable=false;
            this.AddPage(0);
            this.AddBackground(100, 100, 400, 80, 9200);
            this.AddHtml(100, 110, 400, 35, (String.Format("<CENTER><BIG><BASEFONT SIZE=7 COLOR=#FFFF00>{0}<BASEFONT COLOR=#000000></BIG></CENTER>",HolidayMessage)), false, false);
            //this.AddLabel(342, 210, 1259, @"Happy Holidays!!");
            this.AddLabel(229, 137, 1149, @"A Gift Package has been");
            this.AddImage(106, 105, 10461);
            this.AddLabel(229, 155, 1149, @"added to your " + destination + "!");
            this.AddImage(425, 105, 10461);
        }
      
        public override void OnResponse(NetState sender, RelayInfo info)
        {
        }
    }
}
 
Last edited:
No it was a gift giving system modification from here, it was a mod to the base gift giving system that is already in place.
 
So....what is it you're wanting?
An automatic, reoccurring gift giving system? So you can set up holidays and birthdays to give out gifts...and not have to modify the script each year?

I could hook you up with something like that. You'd have to modify it to fit your server (as it's for my older RunUO shard)....but the code hasn't changed that much. I believe I even documented it okay (I'd have to recheck).

If your interested...
 
No that I already have, I was trying to get it to read the account age as well and provide a gift to you based on that, I ended up having to duplicate the gift giving system and remove most of the date checks then add the account age checks in but I was actually able to get this working :)

I wanted it to run year round and check the account age but the dates were throwing the script off and causing it to not work so I ended up removing those checks and left the rest of the system in tact.
 
Back