I am trying to make a Token that a player can use to grant him Temporary Immortality (Blessed) for 60 Second.
I have the script done and it compiles with no errors but it does not work as intended because it seems the the Timer is not functioning. *I have never been good with Timers*
So . . when the Token is DBL Clicked it gives a Gump from which the player can choose to use it or not. If he chooses to use it he then changes to Blessed as expected.
The Problem: He remains Blessed and never changes back to the normal UnBlessed status even after the Timer period elapses.
Can anyone see where this script is wrong?
Here is the script:
Any help is appreciated
Thanks
I have the script done and it compiles with no errors but it does not work as intended because it seems the the Timer is not functioning. *I have never been good with Timers*
So . . when the Token is DBL Clicked it gives a Gump from which the player can choose to use it or not. If he chooses to use it he then changes to Blessed as expected.
The Problem: He remains Blessed and never changes back to the normal UnBlessed status even after the Timer period elapses.
Can anyone see where this script is wrong?
Here is the script:
Code:
using System;
using Server;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
using System.Globalization;
namespace Server.Items
{
public class TokenOfImmortality: Item, IUsesRemaining
{
private int m_UsesRemaining;
private bool _ShowUsesRemaining;
[CommandProperty( AccessLevel.GameMaster )]
public int UsesRemaining
{
get{ return m_UsesRemaining; }
set{ m_UsesRemaining = value; InvalidateProperties(); }
}
[CommandProperty(AccessLevel.GameMaster)]
public virtual bool ShowUsesRemaining
{
get { return _ShowUsesRemaining; }
set
{
_ShowUsesRemaining = value;
InvalidateProperties();
}
}
[Constructable]
public TokenOfImmortality() : this( 5 )
{
}
[Constructable]
public TokenOfImmortality( int uses ) : base( 7970 )
{
Name = "Sirit Stone of Immortality";
ItemID = 7970;
LootType = LootType.Blessed;
Weight = 1.0;
Hue = 1196;
ShowUsesRemaining = true;
m_UsesRemaining = uses;
}
public TokenOfImmortality( Serial serial ) : base( serial )
{
}
public override void OnDoubleClick( Mobile from )
{
if (!IsChildOf(from.Backpack))
{
from.SendLocalizedMessage(1042664); // You must have the object in your backpack to use it.
return;
}
if ( m_UsesRemaining <= 0 )
{
this.Delete();
from.SendLocalizedMessage(1005411);
// The stone disappears
return;
}
if ( m_UsesRemaining > 0 )
{
from.SendGump(new TokenOfImmortalityGump(this));
}
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
if (m_UsesRemaining >= 0 && _ShowUsesRemaining)
{
list.Add(1060584, m_UsesRemaining.ToString(CultureInfo.InvariantCulture)); // uses remaining: ~1_val~
}
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( (int) m_UsesRemaining );
writer.Write(_ShowUsesRemaining);
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
m_UsesRemaining = reader.ReadInt();
_ShowUsesRemaining = reader.ReadBool();
}
private class TokenOfImmortalityGump : Gump
{
private TokenOfImmortality m_Tool;
public TokenOfImmortalityGump(TokenOfImmortality tool) : base( 20, 20 )
{
m_Tool = tool;
this.Closable=false;
this.Dragable=true;
this.Resizable=false;
this.AddPage(0);
this.AddBackground(7, 5, 380, 182, 2620);
this.AddAlphaRegion(19, 19, 355, 153);
this.AddItem(310, 80, 7036);
this.AddLabel(30, 30, 1152, "You can become 'Immortal' for a period of 1 minute.");
this.AddLabel(30, 52, 1152, "Would you like to enter the 'Immortal' state now?");
this.AddButton(55, 91, 10830, 10830, 1, GumpButtonType.Reply, 0);
this.AddLabel(103, 97, 1152, "Yes! Make me Immortal for 1 minute");
this.AddButton(55, 131, 10850, 10850, 2, GumpButtonType.Reply, 0);
this.AddLabel(103, 137, 1152, " No! I might use this another time");
}
public override void OnResponse(NetState state, RelayInfo info)
{
Mobile from = state.Mobile;
if ( info.ButtonID == 1 )
{
if ( (from == null) || (from.Map == null) || !(from.Alive) )
{
return;
}
if ( (from.Alive) && (from.Blessed == true) )
{
from.SendLocalizedMessage( 1010096 ); // You cannot use this in your current form.
return;
}
if ( (from.Alive) && (from.Blessed == false) )
{
from.Blessed = true;
Timer m_timer = new TempImmortalityTimer( from );
from.SendLocalizedMessage( 1112387 ); // The spirit casts its blessing upon you.
if ( m_Tool.UsesRemaining <= 1 )
{
m_Tool.Delete();
return;
}
else
{
--m_Tool.UsesRemaining;
}
}
}
if ( info.ButtonID == 2 )
{
from.SendLocalizedMessage( 1072667 ); // Hrmph. Well maybe another time then.
return;
}
}
public class TempImmortalityTimer : Timer
{
private Mobile mob;
public TempImmortalityTimer( Mobile m ) : this( m, TimeSpan.FromSeconds( 60 ) )
{
}
public TempImmortalityTimer( Mobile m, TimeSpan delay ) : base( delay )
{
mob = m;
Priority = TimerPriority.OneSecond;
}
protected override void OnTick()
{
mob.Blessed = false;
mob.SendLocalizedMessage( 1045117 ); // The blessing fades.
Stop();
}
}
}
}
}
Any help is appreciated
Thanks