Here is a working one. It allows the user to do an insta hit every ten seconds. You can easily edit the time between hits by changing this line:
[code:1]
InstaHit = DateTime.Now + new TimeSpan( 0, 0, 0, 10 );
[/code:1]
To get the code working, you have to change the players class. To do, open up \Scripts\Misc\CharacterCreation.cs, find the following:
[code:1]
private static Mobile CreateMobile( Account a )
{
for ( int i = 0; i < 5; ++i )
if ( a == null )
return a = new Mobile();
return null;
}
[/code:1]
And change it to:
[code:1]
private static Mobile CreateMobile( Account a )
{
for ( int i = 0; i < 5; ++i )
if ( a == null )
return a = new MyMobile();
return null;
}
[/code:1]
And you have to add the mobile's code. Create a new *.cs file, and paste this into it:
[code:1]
using System;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server.Misc
{
public class MyMobile : Mobile
{
private static Timer m_Timer;
public static string InstaHitVar = Convert.ToString( DateTime.Now );
private static DateTime InstaHit = DateTime.Now;
public MyMobile()
{
InstaHitVar = Convert.ToString( DateTime.Now );
}
public MyMobile( Serial serial ) : base( serial )
{
}
private class InternalTimer : Timer
{
private Mobile m_Owner;
public InternalTimer( Mobile owner ) : base( TimeSpan.FromSeconds( 0.1 ), TimeSpan.FromSeconds( 0.2 ) )
{
m_Owner = owner;
}
protected override void OnTick()
{
m_Owner.NextCombatTime = DateTime.Now;
InstaHit = DateTime.Now + new TimeSpan( 0, 0, 0, 10 );
m_Timer.Stop();
}
}
public override bool OnEquip( Item item )
{
if ( item.Layer == Layer.TwoHanded || item.Layer == Layer.FirstValid )
{
//this.SendMessage( "It's a weapon!" );
if ( DateTime.Now >= InstaHit )
{
//this.SendMessage( "InstaHit activated!" );
m_Timer = new InternalTimer( this );
m_Timer.Stop();
m_Timer.Delay = TimeSpan.FromSeconds( 0.2 ); // Optional
m_Timer.Start();
}
}
return true;
}
public override void OnDelete()
{
m_Timer.Stop();
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( (string) InstaHitVar);
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
InstaHitVar = reader.ReadString();
break;
}
}
}
}
}
[/code:1]