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!

Timers and auto deleted item.

Rofl

Wanderer
Hi folks,

I'm trying to code my own weapon. It is a weapong that is automatically deleted (even if it is in the backpack).

This is my code:

Code:
using System;
using Server;

namespace Server.Items
{
        public class BoneCrusher : WarMace
        {
                private bool m_Decays;
                private DateTime m_DecayTime;
                private Timer m_Timer;

                public override int LabelNumber{ get{ return 1049498; } } // dark WarMace

                [Constructable]
                public BoneCrusher() : this( false )
                {
                }

                [Constructable]
                public BoneCrusher( bool decays, Point3D loc, Map map ) : this( decays )
                {
                        MoveToWorld( loc, map );
                        Effects.PlaySound( loc, map, 0x20E );
                }

                [Constructable]
                public BoneCrusher( bool decays )
                {
                        ItemID = 0x1406;
            Hue = 0x60C;
            WeaponAttributes.HitLowerDefend = 50;
            Attributes.BonusStr = 10;
            Attributes.WeaponDamage = 75;

                        if ( decays )
                        {
                                m_Decays = true;
                                m_DecayTime = DateTime.Now + TimeSpan.FromSeconds( 5.0 );

                                m_Timer = new InternalTimer( this, m_DecayTime );
                                m_Timer.Start();
                        }
                }

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

                public override void OnAfterDelete()
                {
                        if ( m_Timer != null )
                                m_Timer.Stop();

                        base.OnAfterDelete();
                }

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

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

                        writer.Write( m_Decays );

                        if ( m_Decays )
                                writer.WriteDeltaTime( m_DecayTime );
                }

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

                        int version = reader.ReadInt();

                        switch ( version )
                        {
                                case 0:
                                {
                                        m_Decays = reader.ReadBool();

                                        if ( m_Decays )
                                        {
                                                m_DecayTime = reader.ReadDeltaTime();

                                                m_Timer = new InternalTimer( this, m_DecayTime );
                                                m_Timer.Start();
                                        }

                                        break;
                                }
                        }
                }

                private class InternalTimer : Timer
                {
                        private Item m_Item;

                        public InternalTimer( Item item, DateTime end ) : base( end - DateTime.Now )
                        {
                                m_Item = item;
                        }

                        protected override void OnTick()
                        {
                                m_Item.Delete();
                        }
                }
        }
}

Why is not the item bein deleted?

Thanks.

PS: If you have any similar script or idea, could you help me?
 

Attachments

  • warmace.cs
    3.4 KB · Views: 3

AlphaDragon

Sorceror
I have a script that will make mobs auto delete. but its after a certain time?
its a timer incorporated into the mob script itself.
Dont know if it will work but you can check it out.
or get idea from the egg laying chicken.

If you want I can post what I have. It started with someone wanting a egg laying chicken and I got it to work on other mobs that were like the infecting zombe and morphing mobs.
With the help of several people it seems to have worked on several occations.

Just let me know.
 

Rofl

Wanderer
Of course, It would help. One friend made a auto delete for mobs, but I think It is not useful for items.
 

AlphaDragon

Sorceror
Should work same as mob. when its created. ect. Look at the timer to see if it helps.
My code is messsssyyyyy but it works for what I wanted. and seems ok. but I am no programmer.
I can tell you somewhat what is what and what it does if you have questions.
There was a mixture of where I got the ideas from:
Someone made a multiplier zombie - but could not make it delete the zombies - gave me partal idea.
someone had a horse that pooped - seemed to work for another idea for someone that was looking to make a egg laying chicken but could not get it to do it. with the poop script and help from a few others I was able to make the egg laying chicken.

With the Experance of learning those I was able to incorporate it into mobs.

There is also a timer in there to make mobs say things as they move.

and now I think it will help with what you need. ;)

See how good it is to help eachother.. :D

Code:
  Timer SelfDeleteTimer = new InternalSelfDeleteTimer(this);
Code:
        public class InternalSelfDeleteTimer: Timer
        {
            private IncredibleHulk Mare;
            //Line Below This: (TimeSpan.FromSeconds (this is where u adjust how long it takes till the egg drops)
            public InternalSelfDeleteTimer(Mobile p): base( TimeSpan.FromSeconds( 3600.0), TimeSpan.FromSeconds( 3601.0))//time 1.0 - 1800.0 meens will drop evey 1/2 hour
              {
                Priority = TimerPriority.FiftyMS;
                Mare = ((IncredibleHulk) p);
            }
            protected override void OnTick()
            {
                if (Mare.Map != Map.Internal)
                {
                    Effects.PlaySound( Mare.Location, Mare.Map, 0x16a);//Can change number of sound played 0x16a = DragonScream
                    Mare.PublicOverheadMessage( MessageType.Regular, 62, true, "YOU ARE WEAK!" );//FYI: Mare.PublicOverheadMessage( MessageType.Regular, 62 this is for the hue colot, true is for cursive, "Cluck" );
                    Mare.Delete();
                    this.Stop();
                }
                else
                    {
                    Effects.PlaySound( Mare.Location, Mare.Map, 130);//Can change number of sound played, 130 = Moose sound
                    Mare.PublicOverheadMessage( MessageType.Regular, 38, true, "Spawning on internal Map. Tell a GM." );
                }
            }
        }
Code:
      public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            Timer SelfDeleteTimer = new InternalSelfDeleteTimer(this);
            SelfDeleteTimer.Start();
        }

Whole script so you can see how I did it.
Code:
using System;
using Server;
using Server.Misc;
using Server.Network;
using System.Collections;
using Server.Items;
using Server.Targeting;

namespace Server.Mobiles
{
    [CorpseName( "the incredible hulk's corpse" )]
    public class IncredibleHulk : BaseCreature
        {
        public override bool ShowFameTitle{ get{ return false; } }
        private static bool m_Talked; // flag to prevent spam
        string[] kfcsay = new string[] // things to say while greating
            {
            "HULK SMASH!",
            };
        [Constructable]
        public IncredibleHulk () : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
            {
            Name = "the incredible hulk";
            Body = 83;
            BaseSoundID = 0x16a;//was 427
            Hue = 2212;
            SetStr( 666, 666 );
            SetDex( 545, 566 );
            SetInt( 46, 70 );
            SetHits( 1400, 4200 );
            SetDamage( 30, 35 );
            SetDamageType( ResistanceType.Physical, 100 );
            SetResistance( ResistanceType.Physical, 100 );
            SetResistance( ResistanceType.Fire, 80 );
            SetResistance( ResistanceType.Cold, 80 );
            SetResistance( ResistanceType.Poison, 100 );
            SetResistance( ResistanceType.Energy, 90 );
            SetSkill( SkillName.MagicResist, 125.1, 140.0 );
            SetSkill( SkillName.Tactics, 90.1, 100.0 );
            SetSkill( SkillName.Wrestling, 100.0, 120.0 );
            Fame = 20000;
            Karma = -20000;
            VirtualArmor = 80;
            PackGem(10);
            Timer SelfDeleteTimer = new InternalSelfDeleteTimer(this);
            SelfDeleteTimer.Start();
        }

        public IncredibleHulk( Serial serial ) : base( serial )
            {
            }
        public override void OnMovement( Mobile m, Point3D oldLocation )
            {
            if( m_Talked == false )
            {
                if ( m.InRange( this, 5 ) )
                {
                    m_Talked = true;
                    Effects.PlaySound( m.Location, m.Map, 0x16a);//Can change number of sound played 0x16a = DragonScream
                    SayRandom( kfcsay, this );
                    this.Move( GetDirectionTo( m.Location ) );
                    // Start timer to prevent spam
                    SpamTimer t = new SpamTimer();
                    t.Start();
                }
            }
        }
        private class SpamTimer : Timer
        {
            public SpamTimer() : base( TimeSpan.FromSeconds( 4 ) )
            {
                Priority = TimerPriority.OneSecond;
            }
            protected override void OnTick()
            {
                m_Talked = false;
            }
          }
        private static void SayRandom( string[] say, Mobile m )
        {
            m.Say( say[Utility.Random( say.Length )] );
        }
        public override bool OnBeforeDeath()
            {
            PackItem(new IncredibleHulkStatuette());
            PackGold(1000, 1500);
            return base.OnBeforeDeath();//NOT SURE?????
        }

        public override void GenerateLoot()
            {
            AddLoot( LootPack.Rich, 2 );
            }
        public override bool CanRummageCorpses{ get{ return true; } }
        public override Poison PoisonImmune{ get{ return Poison.Regular; } }
        public override int TreasureMapLevel{ get{ return 5; } }
        public override int Meat{ get{ return 2; } }

        public class InternalSelfDeleteTimer: Timer
        {
            private IncredibleHulk Mare;
            //Line Below This: (TimeSpan.FromSeconds (this is where u adjust how long it takes till the egg drops)
            public InternalSelfDeleteTimer(Mobile p): base( TimeSpan.FromSeconds( 3600.0), TimeSpan.FromSeconds( 3601.0))//time 1.0 - 1800.0 meens will drop evey 1/2 hour
              {
                Priority = TimerPriority.FiftyMS;
                Mare = ((IncredibleHulk) p);
            }
            protected override void OnTick()
            {
                if (Mare.Map != Map.Internal)
                {
                    Effects.PlaySound( Mare.Location, Mare.Map, 0x16a);//Can change number of sound played 0x16a = DragonScream
                    Mare.PublicOverheadMessage( MessageType.Regular, 62, true, "YOU ARE WEAK!" );//FYI: Mare.PublicOverheadMessage( MessageType.Regular, 62 this is for the hue colot, true is for cursive, "Cluck" );
                    Mare.Delete();
                    this.Stop();
                }
                else
                    {
                    Effects.PlaySound( Mare.Location, Mare.Map, 130);//Can change number of sound played, 130 = Moose sound
                    Mare.PublicOverheadMessage( MessageType.Regular, 38, true, "Spawning on internal Map. Tell a GM." );
                }
            }
        }
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
        }
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            Timer SelfDeleteTimer = new InternalSelfDeleteTimer(this);
            SelfDeleteTimer.Start();
        }
    }
}
 

Rofl

Wanderer
Code:
  CS0246: Line 85: The type or namespace name 'IncredibleHulkStatuette' could
not be found (are you missing a using directive or an assembly reference?)
    CS1502: Line 85: The best overloaded method match for 'Server.Mobiles.BaseCr
eature.PackItem(Server.Item)' has some invalid arguments
    CS1503: Line 85: Argument '1': cannot convert from 'IncredibleHulkStatuette'
to 'Server.Item'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

By the way, funny script :D
 

AlphaDragon

Sorceror
you can just put a // in the begining of line 85. to rem it out.
Cause that part I didnt send you
it was mainly for you to see the codeing of the timer
 

bauer5152

Wanderer
Hi folks,

I'm trying to code my own weapon. It is a weapong that is automatically deleted (even if it is in the backpack).

This is my code:

Code:
using System;
using Server;

namespace Server.Items
{
        public class BoneCrusher : WarMace
        {
                private bool m_Decays;
                private DateTime m_DecayTime;
                private Timer m_Timer;

                public override int LabelNumber{ get{ return 1049498; } } // dark WarMace

                [Constructable]
                public BoneCrusher() : this( false )
                {
                }

                [Constructable]
                public BoneCrusher( bool decays, Point3D loc, Map map ) : this( decays )
                {
                        MoveToWorld( loc, map );
                        Effects.PlaySound( loc, map, 0x20E );
                }

                [Constructable]
                public BoneCrusher( bool decays )
                {
                        ItemID = 0x1406;
            Hue = 0x60C;
            WeaponAttributes.HitLowerDefend = 50;
            Attributes.BonusStr = 10;
            Attributes.WeaponDamage = 75;

                        if ( decays )
                        {
                                m_Decays = true;
                                m_DecayTime = DateTime.Now + TimeSpan.FromSeconds( 5.0 );

                                m_Timer = new InternalTimer( this, m_DecayTime );
                                m_Timer.Start();
                        }
                }

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

                public override void OnAfterDelete()
                {
                        if ( m_Timer != null )
                                m_Timer.Stop();

                        base.OnAfterDelete();
                }

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

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

                        writer.Write( m_Decays );

                        if ( m_Decays )
                                writer.WriteDeltaTime( m_DecayTime );
                }

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

                        int version = reader.ReadInt();

                        switch ( version )
                        {
                                case 0:
                                {
                                        m_Decays = reader.ReadBool();

                                        if ( m_Decays )
                                        {
                                                m_DecayTime = reader.ReadDeltaTime();

                                                m_Timer = new InternalTimer( this, m_DecayTime );
                                                m_Timer.Start();
                                        }

                                        break;
                                }
                        }
                }

                private class InternalTimer : Timer
                {
                        private Item m_Item;

                        public InternalTimer( Item item, DateTime end ) : base( end - DateTime.Now )
                        {
                                m_Item = item;
                        }

                        protected override void OnTick()
                        {
                                m_Item.Delete();
                        }
                }
        }
}

Why is not the item bein deleted?

Thanks.

PS: If you have any similar script or idea, could you help me?

Thanks you for the post.
__________________
Watch Zookeeper Online Free
 
Top