jayates
Member
Was wondering if someone could help me with this? This token requester is suppossed to have 8 charges and everytime you use it, it will say how many charges left. Well, it always says 7. Also, was wanting it to self delete after the charges are used up.
C#:using System; using System.Collections; using Server; using Server.Items; using Server.Mobiles; using Server.Network; namespace Server.Items { public class TokenRequester : GoldBracelet { private int m_Charges; private DateTime m_NextRecharge; private DateTime m_NextUse; private DateTime m_ActiveUntil; [Constructable] public TokenRequester() : base() { Name = "a Token Requester"; ItemID = 12122; //(Talisman) Layer = Layer.Talisman; m_NextRecharge = DateTime.Now + TimeSpan.FromHours( 1.0 ); m_Charges = 8; m_NextUse = DateTime.Now; } public override void OnDoubleClick( Mobile from ) { if ( m_NextRecharge < DateTime.Now ) { this.m_Charges = 8; m_NextRecharge = DateTime.Now + TimeSpan.FromHours( 1.0 ); } if ( (from.FindItemOnLayer( Layer.Talisman ) is TokenRequester) && m_Charges > 0 && m_NextUse < DateTime.Now ) { from.SendMessage( 0, "You blow the Token Requester and an NPC hears your call... some tokens have been bestowed upon thee! Charges left: {0}", m_Charges - 1 ); from.AddToBackpack( new Token() ); from.AddToBackpack( new Token() ); from.AddToBackpack( new Token() ); from.AddToBackpack( new Token() ); from.AddToBackpack( new Token() ); from.PlaySound( 1460 ); //horn blowing m_NextUse = DateTime.Now + TimeSpan.FromHours( 1.0 ); //FromMinutes( 1.0 ); m_Charges -= 1; } else if ( (from.FindItemOnLayer( Layer.Talisman ) is TokenRequester) && this.m_Charges > 0 ) from.SendMessage( 0, "Someone hears your request! But, they are very busy ...you must wait. Time left: {0}", m_NextUse - DateTime.Now ); else if ( from.FindItemOnLayer( Layer.Talisman ) is TokenRequester ) from.SendMessage( 0, "The Requester is very worn. Time left for self repair: {0}", m_NextRecharge - DateTime.Now ); else from.SendMessage( 0, "That must be equipped before you can use it!" ); } public TokenRequester( Serial serial ) : base( serial ) { } public override void Serialize( GenericWriter writer ) { base.Serialize( writer ); writer.Write( (int) 0 ); writer.Write( (int) m_Charges ); writer.Write( (DateTime) m_NextUse ); writer.Write( (DateTime) m_NextRecharge ); } public override void Deserialize( GenericReader reader ) { base.Deserialize( reader ); int version = reader.ReadInt(); m_Charges = reader.ReadInt(); m_NextUse = reader.ReadDateTime(); m_NextRecharge = reader.ReadDateTime(); } } }
Last edited by a moderator: