public void Despawn()
{
Delete();
}

public class SpawnTime : Timer
{
public static void Initialize()
{
new SpawnTime().Start();
}

public SpawnTime() : base(TimeSpan.FromMinutes(60))
{
Priority = TimerPriority.OneMinute;
}

public static void OnTick()
{
DemonicSamurai.Despawn();
}
}

Theres the relevent parts of the code. I'm trying to make a mobile only live for 60 minutes, it just keeps erroring out with that error, or "error CS0120: An object reference is required for the non-static field, method, or property 'Mobile.Delete()'" if I set it to public static void Despawn(). I'm guessing I need to pass something from the OnTick to the Despawn, but I have no idea the easiest way to do what I am trying. And I just know this is going to be something really easy to solve.
 
Shouldn't Delete be a method of an object?
Try deleting the base object.

Delete the base object:
public void Despawn()
{
  base.Delete();
}
 
Well the error is because you are trying to call instance method .Despawn() on class DemonicSamurai inside static method. To be able to call Despawn you need class instance, an object.

I think you'd be better to create regular non-static SpawnTimer class with parameters as you need and store that SpawnTimer instance on the field inside DemonicSamurai class. When creating DemonicSamurai instance in constructor you create instance of SpawnTimer and it will Despawn mobile when time comes.

Something similar is done here ServUO/ServUO

There is private class SpawnTimer inside RSQEggSac class.
 
Necroing my old post. Been back to fighting with this for the last couple of days (my coding time has gone from 8+ hours a day, to maybe an hour >.>)


public new void OnCreate()
{
base.OnCreate();

m_TTL = DateTime.Now + TimeSpan.FromSeconds(3600);
}

public override void OnThink()
{
base.OnThink();

if (DateTime.UtcNow > m_TTL)
{
this.Delete();
}
}

Thats the code now, but it is automatically deleting the mob as soon as it spawns, and I cant figure out why.
 
Change
m_TTL = DateTime.Now + TimeSpan.FromSeconds(3600);
to
m_TTL = DateTime.UtcNow + TimeSpan.FromSeconds(3600);
 
Back