Full Version : Gift Giver Question
xmlspawner >>Scripting Support >>Gift Giver Question


<< Prev | Next >>

Erica- 12-26-2006
I know this script gives one gift to only one character but would like to know if its possible that if you can set this to give all the players from one account instead of just one of the characters heres a script but cant figure out to make it for all characters in one account
CODE
using System;
using Server;
using Server.Items;

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

 public override DateTime Start{ get{ return new DateTime( 2006, 8, 16 ); } }
 public override DateTime Finish{ get{ return new DateTime( 2006, 8, 30 ); } }

 public override void GiveGift( Mobile mob )
 {
  XmasBag bag = new XmasBag();
 

  bag.DropItem( new Eggnog() );
  bag.DropItem( new Champagne() );
  bag.DropItem( new BunchOfDates() );
  bag.DropItem( new FruitCake() );
  bag.DropItem( new PileSnow() );
  bag.DropItem( new RedChampagneGlass() );
  bag.DropItem( new GreenChampagneGlass() );
  bag.DropItem( new WristWatch() );

  SeasonsGreetings greetings = new SeasonsGreetings();
  greetings.Name = "Seasons Greetings from " + mob.Name;
  bag.DropItem( greetings );

  switch ( GiveGift( mob, bag ) )
  {
   case GiftResult.Backpack:
    mob.SendMessage( 0x482, "Seasons Greetings from the team!  Gift items have been placed in your backpack." );
    break;
   case GiftResult.BankBox:
    mob.SendMessage( 0x482, "Seasons Greetings from the team!  Gift items have been placed in your bank box." );
    break;
  }
 }
}
}


ArteGordon- 12-27-2006
this is a function of the GiftGiver system, not the script. You would have to mod the system to allow giving more than one gift per account.
You could use the attachment system to keep track of who had already been given gifts.

Try this mod. In GiftGiving.cs make these changes

QUOTE

  private static void EventSink_Login( LoginEventArgs e )
  {
   Account acct = e.Mobile.Account as Account;

   if ( acct == null )
    return;

   DateTime now = DateTime.Now;

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

    if ( now < giver.Start || now >= giver.Finish )
     continue; // not in the correct timefream

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

        // ARTEGORDONMOD
        // add support for multiple gifts per account
    if ( acct.LastLogin >= giver.Start && !giver.CanGiveMultipleGifts(e.Mobile))
     continue; // already got one

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

   acct.LastLogin = 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 );

        // ARTEGORDONMOD
        // add support for multiple gifts per account
        // by default only allow one gift per account
        public virtual bool CanGiveMultipleGifts(Mobile mob)
        {
            return false;
        }

  public virtual void DelayGiveGift( TimeSpan delay, Mobile mob )
  {
   Timer.DelayCall( delay, new TimerStateCallback( DelayGiveGift_Callback ), mob );
  }


and then in your gift script do something like


QUOTE

using System;
using Server;
using Server.Items;
using Server.Engines.XmlSpawner2;

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

        public override DateTime Start { get { return new DateTime(2006, 8, 16); } }
        public override DateTime Finish { get { return new DateTime(2006, 8, 30); } }

        // ARTEGORDONMOD
        // add support for multiple gifts per account
        public override bool CanGiveMultipleGifts(Mobile mob)
        {
            // check to see if they have already been given the gift
            return XmlAttach.FindAttachment(mob, typeof(XmlData), "Xmas2006") == null;
        }

        public override void GiveGift(Mobile mob)
        {
            XmasBag bag = new XmasBag();


            bag.DropItem(new Eggnog());
            bag.DropItem(new Champagne());
            bag.DropItem(new BunchOfDates());
            bag.DropItem(new FruitCake());
            bag.DropItem(new PileSnow());
            bag.DropItem(new RedChampagneGlass());
            bag.DropItem(new GreenChampagneGlass());
            bag.DropItem(new WristWatch());

            SeasonsGreetings greetings = new SeasonsGreetings();
            greetings.Name = "Seasons Greetings from " + mob.Name;
            bag.DropItem(greetings);

            switch (GiveGift(mob, bag))
            {
                case GiftResult.Backpack:
                    mob.SendMessage(0x482, "Seasons Greetings from the team!  Gift items have been placed in your backpack.");
                    break;
                case GiftResult.BankBox:
                    mob.SendMessage(0x482, "Seasons Greetings from the team!  Gift items have been placed in your bank box.");
                    break;
            }

            // ARTEGORDONMOD
            // flag the mob as having been given the gift
            XmlAttach.AttachTo(mob, new XmlData("Xmas2006","",43200));

        }
    }
}


Individual players will get the XmlData attachment named "Xmas2006" when they are given the gift, and only players without the attachment can be given the gift.
This mod will have no effect on any standard gifts and the system will behave exactly as it used to by default.

I also set up the attachment so that it will expire after 30 days (43200 minutes) since after the gift time window passes they cant be given a gift anyway so no point in having the attachment stick around long than that.
You may also want to revise your start/end time for the gift. You have it set for August 16-30.

Erica- 12-27-2006
So what your saying is once i edit those 2 scripts each account that has 6 characters will get gifts am i correct if not explain a little more Thanks.

ArteGordon- 12-27-2006
QUOTE (Erica @ December 27, 2006 11:32 pm)
So what your saying is once i edit those 2 scripts each account that has 6 characters will get gifts am i correct if not explain a little more Thanks.

yes, every char in an account will be able to get the Xmas2006 gifts and each char will only be able to get it once. The system still works the same as usual, so the chars actually have to log in during the gift giving period. The mod simply allows you to lift the restriction on one gift per account.

Erica- 12-27-2006
Sweet Thanks just tested it works great.