brennoncraig
Member
How would I go about doing this? If anyone could share it would be much appreciated.
Thanks
Thanks
I did something like this for my Steward script. I just store a List<PlayerMobile> on the Steward, and a timer that resets every 24 hours, clearing the List when it ticks. If someone tries to get the item from them, it checks if they are in the List, and if not it gives them the item and adds them to the List. I feel like this is easier than storing a different DateTime for each Player. So, rather than having to wait 24 hours to use it next, in the Steward, it simply resets everyone each 24 hours. This means someone could get one as the timer is about to expire then get another one, but it's still fair, since they only got 1 during each 24 hour period. If you have a daily restart on your server, you don't even need a timer, and you don't need to Serialize the List. It will just reset every day the shard resets.
I just store a List<PlayerMobile> on the Steward
private List<PlayerMobile> mPlayers;
public List<PlayerMobile> Players
{
get { return mPlayers; }
set { mPlayers = value; }
}
and a timer that resets every 24 hours, clearing the List when it ticks.
private MyTimer myTimer;
private class MyTimer : Timer
{
private Steward mSteward;
public MyTimer(Steward steward) : base(TimeSpan.FromHours(24.0))
{
mSteward = steward;
}
protected override void OnTick()
{
mSteward.Players = new List<PlayerMobile>();
}
it checks if they are in the List, and if not it gives them the item and adds them to the List
if (mPlayers.Contains(pm))
{
pm.SendMessage("You have already received an item from this Steward today.");
return;
}
if (pm.AddToBackpack(Backpack.Items[Utility.Random(Backpack.Items.Count)]))
{
pm.SendLocalizedMessage(1072223); // An item has been placed in your backpack.
mPlayers.Add(pm);
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.