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!

[RUO 2.0 RCX] Stone of Rebirth

Vorspire

Knight
[RUO 2.0 RCX] Stone of Rebirth

Somone was asking for help with a similar item in the Script Support forum.. So many posts all say "Edit the PlayerMobile" hehe.. This proves that you can work "outside of the box" if you just dig deep enough into the Core Documentation.

This script is extremely simple;

1 Blessed AutoResStone
1 Player Death Event Sink

Basically, when you die, if this stone is in your pack, it should resurrect you instantly with a message of rebirth.

[Stone Of Rebirth - Basic]
Code:
using System;
using Server;
using Server.Items;
using Server.Mobiles;

namespace Server.Items
{
    public class AutoResStone : Item
    {
        public static void Initialize()
        {
            EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_Death);
        }

        private static void EventSink_Death(PlayerDeathEventArgs e)
        {
            PlayerMobile owner = e.Mobile as PlayerMobile;

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive)
                    return;

                if (owner.Backpack == null || owner.Backpack.Deleted)
                    return;

                AutoResStone stone = owner.Backpack.FindItemByType(typeof(AutoResStone)) as AutoResStone;

                if (stone != null && !stone.Deleted)
                {
                    owner.SendMessage("Your stone of rebirth has saved you from the farplane.");
                    owner.Resurrect();
                }
            }
        }

        [Constructable]
        public AutoResStone()
            : base(0x1870)
        {
            Name = "Stone Of Rebirth";
            LootType = LootType.Blessed;
        }

        public AutoResStone(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();

            switch (version)
            {
                case 0: { } break;
            }
        }

    }
}

[Stone Of Rebirth - With Editable Delay]
Code:
using System;
using Server;
using Server.Items;
using Server.Mobiles;

namespace Server.Items
{
    public class AutoResStone : Item
    {
        private Timer m_Timer;
        private TimeSpan m_Delay = TimeSpan.Zero;

        [CommandProperty(AccessLevel.GameMaster)]
        public TimeSpan Delay { get { return m_Delay; } set { m_Delay = value; } }

        public static void Initialize()
        {
            EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_Death);
        }

        private static void EventSink_Death(PlayerDeathEventArgs e)
        {
            PlayerMobile owner = e.Mobile as PlayerMobile;

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive)
                    return;

                if (owner.Backpack == null || owner.Backpack.Deleted)
                    return;

                AutoResStone stone = owner.Backpack.FindItemByType(typeof(AutoResStone)) as AutoResStone;

                if (stone != null && !stone.Deleted)
                {
                    stone.CountDown(owner);
                }
            }
        }

        [Constructable]
        public AutoResStone()
            : base(0x1870)
        {
            Name = "Stone Of Rebirth";
            LootType = LootType.Blessed;
        }

        public AutoResStone(Serial serial)
            : base(serial)
        { }

        public void CountDown(PlayerMobile owner)
        {
            m_Timer = Timer.DelayCall(m_Delay, new TimerStateCallback(Resurrect_OnTick), new object[] { owner });
        }

        private void Resurrect_OnTick(object state)
        {
            object[] states = (object[])state;
            PlayerMobile owner = (PlayerMobile)states[0];

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive)
                    return;

                owner.SendMessage("Your stone of rebirth has saved you from the farplane.");
                owner.Resurrect();
            }
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)0); // version 

            writer.Write( (TimeSpan) m_Delay );
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
                case 0: { m_Delay = reader.ReadTimeSpan(); } break;
            }
        }

    }
}

[Stone Of Rebirth - With Editable Delay, Charges and Full Stat Refresh]
With thanks to: Lord_Greyworlf, Nockar and M_0_h
Code:
using System;
using Server;
using Server.Items;
using Server.Mobiles;

namespace Server.Items
{
    public class AutoResStone : Item
    {
        private int m_Charges = 1;

        [CommandProperty( AccessLevel.GameMaster )]
        public int Charges
        {
            get { return m_Charges; }
            set { m_Charges = value; InvalidateProperties(); }
        }

        private Timer m_Timer;
        private TimeSpan m_Delay = TimeSpan.Zero;

        [CommandProperty(AccessLevel.GameMaster)]
        public TimeSpan Delay { get { return m_Delay; } set { m_Delay = value; } }
	
        public static void Initialize()
        {
            EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_Death);
        }

        private static void EventSink_Death(PlayerDeathEventArgs e)
        {
            PlayerMobile owner = e.Mobile as PlayerMobile;

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive)
                    return;

                if (owner.Backpack == null || owner.Backpack.Deleted)
                    return;

                AutoResStone stone = owner.Backpack.FindItemByType(typeof(AutoResStone)) as AutoResStone;

                if (stone != null && !stone.Deleted)
                {
                    stone.CountDown(owner);
                }
            }
        }

        [Constructable]
        public AutoResStone() : this( 1 )
        { }

        [Constructable]
        public AutoResStone(int charges) 
            : base(0x1870) 
        {
            m_Charges = charges;

            Name = "Stone Of Rebirth";
            LootType = LootType.Blessed;
            
            Weight = 1.0;
        }

        public AutoResStone(Serial serial)
            : base(serial)
        { }

        private void CountDown(PlayerMobile owner)
        {
            m_Timer = Timer.DelayCall(m_Delay, new TimerStateCallback(Resurrect_OnTick), new object[] { owner });
        }

        private void Resurrect_OnTick(object state)
        {
            object[] states = (object[])state;
            PlayerMobile owner = (PlayerMobile)states[0];

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive || m_Charges < 1)
                    return;

                owner.SendMessage("Your stone of rebirth has saved you from the farplane.");
                owner.Resurrect();

                owner.Hits = owner.HitsMax;
                owner.Stam = owner.StamMax;
                owner.Mana = owner.ManaMax; 

                m_Charges--;

                InvalidateProperties();
            }
        }

        public override void GetProperties( ObjectPropertyList list )
        {
            base.GetProperties( list );

            list.Add(String.Format("{0} Charges", m_Charges));
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write( (int) 0 ); // version

            writer.Write( (TimeSpan) m_Delay );
            writer.Write( (int) m_Charges );            
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
                case 0: 
                {
                     m_Delay = reader.ReadTimeSpan();
                     m_Charges = reader.ReadInt();
                } break;
            }
        }

    }
}
 

Lokai

Knight
Nice script. One suggestion...make a check for null backpack to prevent null reference exception, just in case:

if (owner.Backpack != null)
... then do the rest of the script.
 

Vorspire

Knight
Lokai;772564 said:
Nice script. One suggestion...make a check for null backpack to prevent null reference exception, just in case:

if (owner.Backpack != null)
... then do the rest of the script.

Sorry, i'm just used to the way i have things set up, Backpack NEVER returns null for me, if a backpack is deleted, it is automagically replaced and is never null.

However, i have updated the scripts with your sugestion :)
 

Hammerhand

Knight
No PlayerMobile.cs edits? :eek: Is this even gonna work? j/k Good to see something without it for a change. I'd + karma you, but no more karma, so..... ++ Good Job! :D
 

krazeykow

Sorceror
O' Rlly!?

... I never thought of just adding it to the event delegate, oh, I can update one of my scripts with this approach, THANKS!
 

darkoverlord

Sorceror
hmmm I like the idea. Question, I added it into Server.Items, and getting no errors but how do you add the stone? Tried [add stone and searched and didnt see it in ttttttttttttttttttttt... tried [add auto same thing.

thanks
 
it should be [add AutoResStone
This stone will auto-res...and stay in the players pack, so i dont think it could be much use as a reward item, it would make them invincible. with the one without the delay it wil res them right after they die, so you see a corpse by you, but you are still standing...which is why i was wanting to know how i could make one that would consume when used.
 

darkoverlord

Sorceror
Tried that [add AutoResStone..I get amessage "Nothing matched your search terms...." Do I have the script in the wrong spot for it to work? Its in Server.items Im not getting any error messages so it compiles fine... just isnt creating the stone which makes me think something isnt right.

thanks

deryk
 
darkoverlord;774394 said:
Tried that [add AutoResStone..I get amessage "Nothing matched your search terms...." Do I have the script in the wrong spot for it to work? Its in Server.items Im not getting any error messages so it compiles fine... just isnt creating the stone which makes me think something isnt right.

thanks

deryk

Is your Custom folder in your scripts folder?
 

darkoverlord

Sorceror
its in server.scripts.custom there is a folder in there named "customs" but its not in there... Just odd that no error messages yet its not working either.

thanks

deryk
 

darkoverlord

Sorceror
still nada... I put it into the customs folder and reloaded my server logged my admin toon in and still cant create the stone. Now inside my customs folder is ML New and SE folders... should it be in one of those folders? This is a brand new server, with only Nero's Distro and the Druid scripts loaded.

thanks again
deryk
 
This is where my customs folder is, and really the easiest/best place to put it in my opinon. It needs to be in your runuo directory, in the scripts folder, so itll be loaded along with all the other scripts in the server.

Desktop\RunUO-2.0-RC2\Scripts\Custom


And since no one would answer my question... i figured it out and am here to help!

Code:
using System;
using Server;
using Server.Items;
using Server.Mobiles;

namespace Server.Items
{
    public class AutoResStone : Item
    {
        public static void Initialize()
        {
            EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_Death);
        }

        private static void EventSink_Death(PlayerDeathEventArgs e)
        {
            PlayerMobile owner = e.Mobile as PlayerMobile;

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive)
                    return;

                if (owner.Backpack == null || owner.Backpack.Deleted)
                    return;

                AutoResStone stone = owner.Backpack.FindItemByType(typeof(AutoResStone)) as AutoResStone;

                if (stone != null && !stone.Deleted)
                {
                    stone.CountDown(owner);
                }
            }
        }

        private Timer m_Timer;
        private TimeSpan m_Delay = TimeSpan.Zero;

        [CommandProperty(AccessLevel.GameMaster)]
        public TimeSpan Delay { get { return m_Delay; } set { m_Delay = value; } }

        [Constructable]
        public AutoResStone()
            : base(0x1870)
        {
            Name = "Stone Of Rebirth";
            LootType = LootType.Blessed;
        }

        public AutoResStone(Serial serial)
            : base(serial)
        {

        }

        public void CountDown(PlayerMobile owner)
        {
            m_Timer = Timer.DelayCall(m_Delay, new TimerStateCallback(Resurrect_OnTick), new object[] { owner });
        }

        private void Resurrect_OnTick(object state)
        {
            object[] states = (object[])state;
            PlayerMobile owner = (PlayerMobile)states[0];

            if (owner != null && !owner.Deleted)
            {
                if (owner.Alive)
                    return;

                owner.SendMessage("Your stone of rebirth has saved you from the farplane.");
                owner.Resurrect();
                Delete();
            }
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)1); // version 

            writer.Write((TimeSpan)m_Delay);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
                case 1: { m_Delay = reader.ReadTimeSpan(); } goto case 0;
                case 0: { } break;
            }
        }

    }
}

That is the stone with a delay that will delete itself AFTER being used. (I have no set delay on this)

NOW...Since i have the delete working the way i want it to..how do i set the blasted delay? it isnt working.....
 

Tassyon T

Wanderer
This line determines your delay:

Code:
        private TimeSpan m_Delay = TimeSpan.Zero;

Look up TimeSpan in the documentation and/or core scripts to see how to alter it.

To find documentation for it... go to google.com and search for...

"runuo documentation timespan"

To download the core files, go to http://www.runuo.com/forums/downloads.php?
 
Alright, thanks! Had just opened BaseHealer.cs and found
Code:
		private static TimeSpan ResurrectDelay = TimeSpan.FromSeconds( 2.0 );
just before reading your post, so thanks, helped me know what to look for.

Trying to put a gump on it, was assuming resurrectgump would work, but i cant get it to work, that way the players would be able to choose to use it or not, since if they have a friend there that can res then it wouldnt be need to be used.
Any ideas?

*goes back to fiddling with it*

I have decided a gump would be annoying, so I've given up on that and decided to make it ondoubleclick....

*goes back to fiddling with it*
 

Vorspire

Knight
bleedingspiderlegs;774473 said:
*goes back to fiddling with it*

I have decided a gump would be annoying, so I've given up on that and decided to make it ondoubleclick....

*goes back to fiddling with it*

How can a player double click it when they are dead and it's in their pack? :D
 
Top