RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Stone delay help!

ArisBB

Sorceror
Hi all :D!

I'm creating a stone in location of character creation, that on double click, move this player to another location and make it invulnerable for 10 seconds, but i dont know work with timers.

After any trys, nothing... =(

anyone can help me with this??? thanks for all :)

Here is the code that i tryed any times.
Code:
using System;
using Server.Items;
 
namespace Server.Items
{
    public class InitStone : Item
    {
        [Constructable]
        public InitStone() : base( 3804 )
        {
            Movable = false;
            Hue = 2909;
            Name = "The World Stone";
 
        }
 
        private DateTime m_NextMove;
 
        public override void OnDoubleClick( Mobile from )
        {
            bool first = true;
            int count = 0;
 
            if (count == 0)
            {
                  from.SendMessage( "You Have 10 seconds with invulnerability to get out this location!!!!!" );
           
                from.Map = Map.Trammel;
                from.Location = new Point3D(6832, 155,0);
                        from.MoveToWorld(from.Location, from.Map);
 
                from.Blessed = true;
 
                if ( DateTime.Now < m_NextMove )
                    return;
 
                m_NextMove = DateTime.Now + TimeSpan.FromSeconds( 1.0 );
 
                count += 1;
 
                if (count == 10)
                {
                    from.Blessed = false;
                            from.FixedParticles(14170, 9, 32, 0x13AF, EffectLayer.Waist);
                }
 
            //Timer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerCallback( StopT ) );
            //{
                //from.Blessed = true;
                        //from.FixedParticles(14170, 9, 32, 0x13AF, EffectLayer.Waist);
            //}
            //private static TimeSpan ResurrectDelay = TimeSpan.FromSeconds( 2.0 );
            }
 
            else
                  from.SendMessage( "finish!!!!!!!!!!!!" );
        }
 
        /*private void StopT( Mobile from )
                {
            from.Blessed = false;
                    from.FixedParticles(14170, 9, 32, 0x13AF, EffectLayer.Waist);
                }*/
 
        public InitStone( Serial serial ) : base( serial )
        {
        }
 
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
 
            writer.Write( (int) 0 ); // version
        }
 
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
 
            int version = reader.ReadInt();
        }
    }
}
 

Aquatic Elf

Sorceror
There are a few problems with your code (which we'll get to in a moment), but other than that your code for the Timer.DelayCall, is pretty close. Since you also want to pass a parameter to the callback method, you need to use TimerStateCallback instead of TimerCallback.

Code:
Timer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerStateCallback( StopT ), from );

And you'll have to make a few changes to the signature of StopT:
Code:
private void StopT( object state )
{
    Mobile from = state as Mobile;
 
    if( from == null )
        return;
 
    from.Blessed = false;
    from.FixedParticles(14170, 9, 32, 0x13AF, EffectLayer.Waist);
}

(Just as a forewarning; I haven't tested this code)

I don't quite understand the purpose of count, although perhaps that was some testing code?

The major problem with the code is if the server happens to save and shutdown during the 10 seconds the player is blessed. The player will remain blessed (since he was Blessed during the save), but when the server comes back up, the timer will long gone.

The solution to that, would be to keep track of a players that have been blessed and serialize them, so if the rare event does occur, on a deserialize we could use that list to unbless them.
 

ArisBB

Sorceror
Hmm, thank you very much Aq. Elf, this work :D!

The problem is exactly what do you say ^^

if the server saves in this time, and shutdown, the player will be blessed forever...

any sugestion?

I thought of something like when start the server, it finds all the players and unbless they...

But... i do not know how to do so ^^
 

daat99

Moderator
Staff member
Add the code that unbless the player (check if it isn't a councelor or above first) at the end of the "deserialize" method in playermobile.cs.

As long as you don't touch the "reader" you won't risk messing it up so stay away from ANY lines that has "reader" in them when you edit the deserialize method (for this purpose that is).
 

Aquatic Elf

Sorceror
I would follow daat99's method, as that's probably easier to implement. I tend to try to keep modifications out of PlayerMobile (for good reasons mind you), but I guess that's not that much of an issue here.

You may want to add a comment onto the code you add in PlayerMobile to explain why it's there.
 

ArisBB

Sorceror
Ok! it work, the player are unblessed, but... this life bar keeps yellow =/

here is my playermobile.cs Deserialize
Code:
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
 
           switch ( version )
 {
                #region Guantlet Points
                case 32:
                    {
                        m_GauntletPoints = reader.ReadDouble();
 
                        goto case 31;
                    } 
                #endregion
                case 31:
                #region SA
                {
                    m_SSNextSeed = reader.ReadDateTime();
                    m_SSSeedExpire = reader.ReadDateTime();
                    m_SSSeedLocation = reader.ReadPoint3D();
                    m_SSSeedMap = reader.ReadMap();
                    goto case 30;
                }
                #endregion
 
                #region QueensLoyaltySystem   // Queens Loyalty System
                case 30:
                {
                    m_LevelExp = reader.ReadLong();
                    m_Exp = reader.ReadLong();
                    m_Level = reader.ReadInt();
 
                    m_ExpTitle = reader.ReadString();
 
                    goto case 29;
                }
                #endregion
                case 29:
                    {
                        m_VASTotalMonsterFame = reader.ReadInt();
                        goto case 28;
                    }
                case 28:
                    {
                        m_AutoStabled = reader.ReadStrongMobileList();
                        goto case 27;
                    }
                case 27:
                    {
                        m_AnkhNextUse = reader.ReadDateTime();
 
                        goto case 26;
                    }
                case 26:
                    {
                        #region Mondain's Legacy
                        m_Quests = QuestReader.Quests(reader, this);
                        m_Chains = QuestReader.Chains(reader);
 
                        m_Collections = new Dictionary<Collection, int>();
                        m_CollectionTitles = new List<object>();
 
                        for (int i = reader.ReadInt(); i > 0; i--)
                            m_Collections.Add((Collection)reader.ReadInt(), reader.ReadInt());
 
                        for (int i = reader.ReadInt(); i > 0; i--)
                            m_CollectionTitles.Add(QuestReader.Object(reader));
 
                        m_SelectedTitle = reader.ReadInt();
m_Peaced = reader.ReadDateTime();
                        #endregion
 
                        goto case 25;
                    }
                case 25:
                    {
                        int recipeCount = reader.ReadInt();
 
                        if (recipeCount > 0)
                        {
                            m_AcquiredRecipes = new Dictionary<int, bool>();
 
                            for (int i = 0; i < recipeCount; i++)
                            {
                                int r = reader.ReadInt();
                                if (reader.ReadBool())//Don't add in recipies which we haven't gotten or have been removed
                                    m_AcquiredRecipes.Add(r, true);
                            }
                        }
                        goto case 24;
                    }
                case 24:
                    {
                        m_LastHonorLoss = reader.ReadDeltaTime();
                        goto case 23;
                    }
                case 23:
                    {
                        m_ChampionTitles = new ChampionTitleInfo(reader);
                        goto case 22;
                    }
                case 22:
                    {
                        m_LastValorLoss = reader.ReadDateTime();
                        goto case 21;
                    }
                case 21:
                    {
                        m_ToTItemsTurnedIn = reader.ReadEncodedInt();
                        m_ToTTotalMonsterFame = reader.ReadInt();
                        goto case 20;
                    }
                case 20:
                    {
                        m_AllianceMessageHue = reader.ReadEncodedInt();
                        m_GuildMessageHue = reader.ReadEncodedInt();
 
                        goto case 19;
                    }
                case 19:
                    {
                        int rank = reader.ReadEncodedInt();
                        int maxRank = Guilds.RankDefinition.Ranks.Length - 1;
                        if (rank > maxRank)
                            rank = maxRank;
 
                        m_GuildRank = Guilds.RankDefinition.Ranks[rank];
                        m_LastOnline = reader.ReadDateTime();
                        goto case 18;
                    }
                case 18:
                    {
                        m_SolenFriendship = (SolenFriendship)reader.ReadEncodedInt();
 
                        goto case 17;
                    }
                case 17: // changed how DoneQuests is serialized
                case 16:
                    {
                        m_Quest = QuestSerializer.DeserializeQuest(reader);
 
                        if (m_Quest != null)
                            m_Quest.From = this;
 
                        int count = reader.ReadEncodedInt();
 
                        if (count > 0)
                        {
                            m_DoneQuests = new List<QuestRestartInfo>();
 
                            for (int i = 0; i < count; ++i)
                            {
                                Type questType = QuestSerializer.ReadType(QuestSystem.QuestTypes, reader);
                                DateTime restartTime;
 
                                if (version < 17)
                                    restartTime = DateTime.MaxValue;
                                else
                                    restartTime = reader.ReadDateTime();
 
                                m_DoneQuests.Add(new QuestRestartInfo(questType, restartTime));
                            }
                        }
 
                        m_Profession = reader.ReadEncodedInt();
                        goto case 15;
                    }
                case 15:
                    {
                        m_LastCompassionLoss = reader.ReadDeltaTime();
                        goto case 14;
                    }
                case 14:
                    {
                        m_CompassionGains = reader.ReadEncodedInt();
 
                        if (m_CompassionGains > 0)
                            m_NextCompassionDay = reader.ReadDeltaTime();
 
                        goto case 13;
                    }
                case 13: // just removed m_PayedInsurance list
                case 12:
                    {
                        m_BOBFilter = new Engines.BulkOrders.BOBFilter(reader);
                        goto case 11;
                    }
                case 11:
                    {
                        if (version < 13)
                        {
                            List<Item> payed = reader.ReadStrongItemList();
 
                            for (int i = 0; i < payed.Count; ++i)
                                payed[i].PayedInsurance = true;
                        }
 
                        goto case 10;
                    }
                case 10:
                    {
                        if (reader.ReadBool())
                        {
                            m_HairModID = reader.ReadInt();
                            m_HairModHue = reader.ReadInt();
                            m_BeardModID = reader.ReadInt();
                            m_BeardModHue = reader.ReadInt();
                        }
 
                        goto case 9;
                    }
                case 9:
                    {
                        SavagePaintExpiration = reader.ReadTimeSpan();
 
                        if (SavagePaintExpiration > TimeSpan.Zero)
                        {
                            BodyMod = (Female ? 184 : 183);
                            HueMod = 0;
                        }
 
                        goto case 8;
                    }
                case 8:
                    {
                        m_NpcGuild = (NpcGuild)reader.ReadInt();
                        m_NpcGuildJoinTime = reader.ReadDateTime();
                        m_NpcGuildGameTime = reader.ReadTimeSpan();
                        goto case 7;
                    }
                case 7:
                    {
                        m_PermaFlags = reader.ReadStrongMobileList();
                        goto case 6;
                    }
                case 6:
                    {
                        NextTailorBulkOrder = reader.ReadTimeSpan();
                        goto case 5;
                    }
                case 5:
                    {
                        NextSmithBulkOrder = reader.ReadTimeSpan();
                        goto case 4;
                    }
                case 4:
                    {
                        m_LastJusticeLoss = reader.ReadDeltaTime();
                        m_JusticeProtectors = reader.ReadStrongMobileList();
                        goto case 3;
                    }
                case 3:
                    {
                        m_LastSacrificeGain = reader.ReadDeltaTime();
                        m_LastSacrificeLoss = reader.ReadDeltaTime();
                        m_AvailableResurrects = reader.ReadInt();
                        goto case 2;
                    }
                case 2:
                    {
                        m_Flags = (PlayerFlag)reader.ReadInt();
                        goto case 1;
                    }
                case 1:
                    {
                        m_LongTermElapse = reader.ReadTimeSpan();
                        m_ShortTermElapse = reader.ReadTimeSpan();
                        m_GameTime = reader.ReadTimeSpan();
                        goto case 0;
                    }
                case 0:
                    {
                        if (version < 28)
                            m_AutoStabled = new List<Mobile>();
 
                    #region SA
if( version < 30 )
                    {
                        m_SSNextSeed =  m_SSSeedExpire = DateTime.Now;
                        m_SSSeedLocation = Point3D.Zero;
                    }
                    #endregion
                        break;
                    }
            }
 
if (m_RecentlyReported == null)
m_RecentlyReported = new List<Mobile>();
 
            #region QueensLoyaltySystem      // Queens Loyalty System
 
            if (version < 31)
            {
                m_LevelExp = 1000;
                m_Exp = -1000;
                m_Level = 0;
 
                m_ExpTitle = "TerMur-guest";
            }
 
            #endregion                  // End of Queens Loyalty System
 
            #region Mondain's Legacy
            if (m_Quests == null)
                m_Quests = new List<BaseQuest>();
 
            if (m_Chains == null)
                m_Chains = new Dictionary<QuestChain, BaseChain>();
 
            if (m_DoneQuests == null)
                m_DoneQuests = new List<QuestRestartInfo>();
 
            if (m_Collections == null)
                m_Collections = new Dictionary<Collection, int>();
 
            if (m_CollectionTitles == null)
                m_CollectionTitles = new List<object>();
            #endregion
 
            // Professions weren't verified on 1.0 RC0
            if (!CharacterCreation.VerifyProfession(m_Profession))
                m_Profession = 0;
 
            if (m_PermaFlags == null)
                m_PermaFlags = new List<Mobile>();
 
            if (m_JusticeProtectors == null)
                m_JusticeProtectors = new List<Mobile>();
 
            if (m_BOBFilter == null)
                m_BOBFilter = new Engines.BulkOrders.BOBFilter();
 
            if (m_GuildRank == null)
                m_GuildRank = Guilds.RankDefinition.Member;//Default to member if going from older verstion to new version (only time it should be null)
 
            if (m_LastOnline == DateTime.MinValue && Account != null)
                m_LastOnline = ((Account)Account).LastLogin;
 
            if (m_ChampionTitles == null)
                m_ChampionTitles = new ChampionTitleInfo();
 
if ( AccessLevel > AccessLevel.Player )
m_IgnoreMobiles = true;
 
            List<Mobile> list = this.Stabled;
 
            for (int i = 0; i < list.Count; ++i)
            {
                BaseCreature bc = list[i] as BaseCreature;
 
                if (bc != null)
                    bc.IsStabled = true;
            }
 
            CheckAtrophies(this);
 
            if (Hidden)//Hiding is the only buff where it has an effect that's serialized.
                AddBuff(new BuffInfo(BuffIcon.HidingAndOrStealth, 1075655));
 
                if ( AccessLevel == AccessLevel.Player ) //aris
{
   Blessed = false;
}
        }

and here is my added code
Code:
if ( AccessLevel == AccessLevel.Player ) //aris
{
   Blessed = false;
}

this are correct?
this is the best way of make it?

Thank you very much daat and elf!
 

Aquatic Elf

Sorceror
Looks good to me.

I don't know why the player's health bar would still show yellow though. If they're not blessed anymore, the only thing I can think of that would cause it, is if you set their YellowHealthbar to true earlier?
 

ArisBB

Sorceror
No i dont =/
i try this code
Code:
                if ( AccessLevel == AccessLevel.Player ) // aris
{
   Blessed = false;
YellowHealthbar = false;
}

in firt test its work, but in the two other test not =(
and now?
Thank you for help :D
 

daat99

Moderator
Staff member
Try to change the lines order, first change the yellow health bar and then change the blessed status.

If that doesn't work than I would try this too:
Code:
Blessed = true;
YellowHealthbar = false;
Blessed = false;

Just a quick question, what is the command to "unbless" a player in-game (as a GM)?
 

ArisBB

Sorceror
Hmm, good idea daat but... dont work =/
and i try this
Code:
if ( AccessLevel == AccessLevel.Player ) // aris
{
   Blessed = true;
YellowHealthbar = true;
Blessed = false;
YellowHealthbar = false;
}
no results... =(
i cant think in nothing more =/
but thanks for help :D
 

ArisBB

Sorceror
Good... i change this code to it
Code:
                if ( AccessLevel == AccessLevel.Player ) // aris
{
Say( "BLESS" );
SendMessage( "BLESS" );
   Blessed = true;
YellowHealthbar = true;
Say( "UNN" );
SendMessage( "UNN" );
Blessed = false;
YellowHealthbar = false;
Say( "UNBLESS" );
SendMessage( "UNBLESS" );
}

and in login the player say nothing and no messages =/
but this unbless lol
dont urderstad this
 

ArisBB

Sorceror
i dont total uderstand your question...
unbless command is [mortal and bless is [immortal
is this you like know?
 

daat99

Moderator
Staff member
This is what I meant but this doesn't help much after all.

Try removing the code you added and leave it as:

Code:
YellowHealthbar = false;
Blessed = false;

See if it still unbless players.
 

Vorspire

Knight
Clean Timers are fun timers and easier to use - you don't have to specify a named method (in your case 'StopT') and you don't have to define an object state argument (in your case 'from').

.NET 2.0
Code:
Timer.DelayCall(TimeSpan.FromSeconds(10), delegate()
{
	if (from != null && !from.Deleted && from.Blessed && from.AccessLevel == AccessLevel.Player)
	{
		from.Blessed = false;
		from.YellowHealthbar = false;
		from.Delta(MobileDelta.Noto);
	}
});

Note the 'delegate', this allows you to define an anonymous function in placement of declaring an instance member in the class to handle it.

Delegates can also be replaced with Lambda expressions if using .NET 4.0:
Code:
Timer.DelayCall(TimeSpan.FromSeconds(10), () =>
{
	if (from != null && !from.Deleted && from.Blessed && from.AccessLevel == AccessLevel.Player)
	{
		from.Blessed = false;
		from.YellowHealthbar = false;
		from.Delta(MobileDelta.Noto);
	}
});

I know you solved your problem, stick with what's working and consider taking this advice for the future should you or others need it :)
 

ArisBB

Sorceror
like this?
Code:
public override void OnDoubleClick( Mobile from )
{
 from.SendMessage( "You Have 60 seconds with invulnerability to get out this location!!!!!" );
 
 from.Say( "You Have 60 seconds with invulnerability to get out this location!!!!!" );
 
from.Map = Map.Trammel;
from.Location = new Point3D(6762, 2106, 0);
               from.MoveToWorld(from.Location, from.Map);
 
   from.FixedParticles(14170, 5, 15, 0x13AF, EffectLayer.Waist);
 
from.Blessed = true;
 
Timer.DelayCall(TimeSpan.FromSeconds(10), () =>
{
if (from != null && !from.Deleted && from.Blessed && from.AccessLevel == AccessLevel.Player)
{
from.Blessed = false;
from.YellowHealthbar = false;
from.Delta(MobileDelta.Noto);
}
});
 
}
do not work =/

line 31 ")" invalid
line 31 ")" invalid
line 31 ")" expected
line 31 ")" expected
line 31 ";" expected
line 39 ")" invalid
 

Vorspire

Knight
Read my post again, the code you used was a .NET 4.0 example (for those who compile with 4.0), use the first example and it should work fine - you edited right, just used the wrong version support.

The only difference is this:

delegate() { }

() => { }
 

Vorspire

Knight
Any idea?

[invul

I think? It toggles Blessed on/off

Could always use
[self set blessed false

I think toggling blessed true/false resulting in no health-bar color change is a recent bug? AFAIK it always worked fine and refreshed properly, but recently I've seen this behaviour too, worth looking into it I guess.
 
Top