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!

Guards

Kathrina

Wanderer
killable gards new errors

Errors:
+ Mobiles/Guards/ArcherGuard.cs:
CS0103: Line 23: The name 'SetStats' does not exist in the current context
CS0103: Line 337: The name 'm_Owner' does not exist in the current context
CS0103: Line 342: The name 'm_Owner' does not exist in the current context
CS0103: Line 342: The name 'm_Owner' does not exist in the current context
CS0103: Line 347: The name 'm_Owner' does not exist in the current context
CS0103: Line 352: The name 'm_Owner' does not exist in the current context
CS0103: Line 355: The name 'm_Owner' does not exist in the current context
CS0103: Line 357: The name 'm_Owner' does not exist in the current context
CS0103: Line 358: The name 'm_Owner' does not exist in the current context
CS0103: Line 360: The name 'm_Owner' does not exist in the current context
+ Mobiles/Guards/WarriorGuard.cs:
CS0103: Line 25: The name 'SetStr' does not exist in the current context
CS0103: Line 26: The name 'SetDex' does not exist in the current context
CS0103: Line 27: The name 'SetInt' does not exist in the current context
CS0103: Line 29: The name 'SetHits' does not exist in the current context
CS0103: Line 329: The name 'm_Owner' does not exist in the current context
CS0103: Line 332: The name 'm_Owner' does not exist in the current context
CS0103: Line 334: The name 'm_Owner' does not exist in the current context
CS0103: Line 335: The name 'm_Owner' does not exist in the current context
CS0103: Line 337: The name 'm_Owner' does not exist in the current context
now what did i do i tell yah i prob shouldn't mess with any more

and i never learn
 

Greystar

Wanderer
Yes there is alot of stuff in the guards that makes them confusing. It will take some time to figure out what it does... But stick with it and when you get it working you will REALLY feel like you accomplished something. People will be willing to help you and yes the [ code ] [ /code ] tags are you friend anytime you want to post code. Also post error along with code and a marker as to where your code line number starts at since we won't always have the same code as you do. I'll also put in where I can but since I'm not using 2.0's code I'd have to look at what you are offering and I'm not currently running a shard so I might not be prompt at posting an answer and my answer might not compile without bugs or errors.
 

Kathrina

Wanderer
Greystar;704834 said:
Yes there is alot of stuff in the guards that makes them confusing. It will take some time to figure out what it does... But stick with it and when you get it working you will REALLY feel like you accomplished something. People will be willing to help you and yes the [ code ] [ /code ] tags are you friend anytime you want to post code. Also post error along with code and a marker as to where your code line number starts at since we won't always have the same code as you do. I'll also put in where I can but since I'm not using 2.0's code I'd have to look at what you are offering and I'm not currently running a shard so I might not be prompt at posting an answer and my answer might not compile without bugs or errors.

thank you for letting me know about the [ code] it took me a minute to realize what you were talking about but i still don't understand the code and error. please remember the killable guards is the first time i ever even looked at a script much less messed with one.

what i mean by scraping is i think i messed with some stuff on it that i shouldn't have.

i'm still working on the project i just have to start over.

thanks all of you for the help you've been giving. i was almost afraid to ask for help. but i really could use it or i might blow up the computer.:D
 

Kathrina

Wanderer
help i don't understand this error

does any one know what this means

Code:
Errors:
 + Mobiles/Guards/ArcherGuard.cs:
    CS0246: Line 10: The type or namespace name 'Corpsename' could not be found
(are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.

this is my script so far if that helps
Code:
using System;
using System.Collections;
using Server;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
    [Corpsename("an archerguard corpse")]
    public class ArcherGuard : BaseGuard
    {
        private Timer m_AttackTimer, m_IdleTimer;

        private Mobile m_Focus;

        [Constructable]
        public ArcherGuard()
            : this(null)
        {
        }

        public ArcherGuard(Mobile target)
            : base(target)
		{
			InitStats( 100, 125, 25 );
			Title = "the guard";

			SetDamage( 32, 40 );

			SpeechHue = Utility.RandomDyedHue();

			Hue = Utility.RandomSkinHue();

			if ( Female = Utility.RandomBool() )
			{
				Body = 0x191;
				Name = NameList.RandomName( "female" );
			}
			else
			{
				Body = 0x190;
				Name = NameList.RandomName( "male" );
			}

			new Horse().Rider = this;

			AddItem( new StuddedChest() );
			AddItem( new StuddedArms() );
			AddItem( new StuddedGloves() );
			AddItem( new StuddedGorget() );
			AddItem( new StuddedLegs() );
			AddItem( new Boots() );
			AddItem( new SkullCap() );

			Bow bow = new Bow();

			bow.Movable = true;
			bow.Crafter = this;
			bow.Quality = WeaponQuality.Exceptional;

			AddItem( bow );

			Container pack = new Backpack();

			pack.Movable = false;

			Arrow arrows = new Arrow( 250 );

			arrows.LootType = LootType.Newbied;

			pack.DropItem( arrows );
			pack.DropItem( new Gold( 10, 25 ) );

			AddItem( pack );

			Skills[SkillName.Anatomy].Base = 120.0;
			Skills[SkillName.Tactics].Base = 120.0;
			Skills[SkillName.Archery].Base = 120.0;
			Skills[SkillName.MagicResist].Base = 120.0;
			Skills[SkillName.DetectHidden].Base = 100.0;

			Fame = 1000
			Karma = -2000

			this.NextCombatTime = DateTime.Now + TimeSpan.FromSeconds( 0.5 );
			this.Focus = target;
		}

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

        public override bool OnBeforeDeath()
        {
            if (m_Focus != null && m_Focus.Alive)
                new AvengeTimer(m_Focus).Start(); // If a guard dies, one more guard will spawn

            return base.OnBeforeDeath();
        }
        public override bool AlwaysMurderer { get { return true; } }
        public override bool ShowFameTitle { get { return false; } }

        public override void AggressiveAction(PlayerMobile aggressor, bool criminal)
        {
            base.AggressiveAction(aggressor, criminal);
        }

        [CommandProperty(AccessLevel.GameMaster)]
        public override Mobile Focus
        {
            get
            {
                return m_Focus;
            }
            set
            {
                if (Deleted)
                    return;

                Mobile oldFocus = m_Focus;

                if (oldFocus != value)
                {
                    m_Focus = value;

                    if (value != null)
                        this.AggressiveAction(value);

                    Combatant = value;

                    if (oldFocus != null && !oldFocus.Alive)
                        Say("Thou hast suffered thy punishment, scoundrel.");

                    if (value != null)
                        Say(500131); // Thou wilt regret thine actions, swine!

                    if (m_AttackTimer != null)
                    {
                        m_AttackTimer.Stop();
                        m_AttackTimer = null;
                    }

                    if (m_IdleTimer != null)
                    {
                        m_IdleTimer.Stop();
                        m_IdleTimer = null;
                    }

                    if (m_Focus != null)
                    {
                        m_AttackTimer = new AttackTimer(this);
                        m_AttackTimer.Start();
                        ((AttackTimer)m_AttackTimer).DoOnTick();
                    }
                    else
                    {
                        m_IdleTimer = new IdleTimer(this);
                        m_IdleTimer.Start();
                    }
                }
                else if (m_Focus == null && m_IdleTimer == null)
                {
                    m_IdleTimer = new IdleTimer(this);
                    m_IdleTimer.Start();
                }
            }
        }

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

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

            writer.Write(m_Focus);
        }

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

            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        m_Focus = reader.ReadMobile();

                        if (m_Focus != null)
                        {
                            m_AttackTimer = new AttackTimer(this);
                            m_AttackTimer.Start();
                        }
                        else
                        {
                            m_IdleTimer = new IdleTimer(this);
                            m_IdleTimer.Start();
                        }

                        break;
                    }
            }
        }

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

            if (m_IdleTimer != null)
            {
                m_IdleTimer.Stop();
                m_IdleTimer = null;
            }

            base.OnAfterDelete();
        }

        private class AvengeTimer : Timer
        {
            private Mobile m_Focus;

            public AvengeTimer(Mobile focus)
                : base(TimeSpan.FromSeconds(2.5), TimeSpan.FromSeconds(1.0), 3) // After 2.5 seconds, one guard will spawn every 1.0 second, three times
            {
                m_Focus = focus;
            }

            protected override void OnTick()
            {
                BaseGuard.Spawn(m_Focus, m_Focus, 1, true);
            }
        }

        private class AttackTimer : Timer
        {
            private ArcherGuard m_Owner;
            //	private bool m_Shooting;

            public AttackTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(0.25), TimeSpan.FromSeconds(0.1))
            {
                m_Owner = owner;
            }

            public void DoOnTick()
            {
                OnTick();
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                m_Owner.Criminal = true;
                m_Owner.Kills = +1;
                m_Owner.Stam = m_Owner.StamMax;

                Mobile target = m_Owner.Focus;

                if (target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target)))
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }
                else if (m_Owner.Weapon is Fists)
                {
                    m_Owner.Kill();
                    Stop();
                    return;
                }

                if (target != null && m_Owner.Combatant != target)
                    m_Owner.Combatant = target;

                if (target == null)
                {
                    Stop();
                }

                if (target is BaseCreature)
                    ((BaseCreature)target).NoKillAwards = true;

                target.Damage(target.HitsMax, m_Owner);
                target.Kill(); // just in case, maybe Damage is overriden on some shard

                if (target.Corpse != null && !target.Player)
                    target.Corpse.Delete();

                m_Owner.Focus = null;
                Stop();
            }/*else if ( !m_Owner.InRange( target, 20 ) )
				{
					m_Shooting = false;
					m_Owner.Focus = null;
				}
				else if ( !m_Owner.InLOS( target ) )
				{
					m_Shooting = false;
					TeleportTo( target );
				}
				else if ( !m_Owner.CanSee( target ) )
				{
					m_Shooting = false;

					if ( !m_Owner.InRange( target, 2 ) )
					{
						if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
							TeleportTo( target );
					}
					else
					{
						if ( !m_Owner.UseSkill( SkillName.DetectHidden ) && Utility.Random( 50 ) == 0 )
							m_Owner.Say( "Reveal!" );
					}
				}
				else
				{
					if ( m_Shooting && (TimeToSpare() || OutOfMaxDistance( target )) )
						m_Shooting = false;
					else if ( !m_Shooting && InMinDistance( target ) )
						m_Shooting = true;

					if ( !m_Shooting )
					{
						if ( m_Owner.InRange( target, 1 ) )
						{
							if ( !m_Owner.Move( (Direction)(m_Owner.GetDirectionTo( target ) - 4) | Direction.Running ) && OutOfMaxDistance( target ) ) // Too close, move away
								RunTo( target );
						}
						else if ( !m_Owner.InRange( target, 2 ) )
						{
							if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
								RunTo( target );
						}
					}
				}*/
        }

        private bool TimeToSpare()
        {
            return (m_Owner.NextCombatTime - DateTime.Now) > TimeSpan.FromSeconds(1.0);
        }

        private bool OutOfMaxDistance(Mobile target)
        {
            return !m_Owner.InRange(target, m_Owner.Weapon.MaxRange);
        }

        private bool InMinDistance(Mobile target)
        {
            return m_Owner.InRange(target, 4);
        }

        private void RunTo(Mobile target)
        {
            Point3D from = m_Owner.Location;
            Point3D to = target.Location;

            m_Owner.Location = to;

            Effects.SendLocationParticles(EffectItem.Create(from, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
            Effects.SendLocationParticles(EffectItem.Create(to, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 5023);

            m_Owner.PlaySound(0x1FE);
        }

        private class IdleTimer : Timer
        {
            private ArcherGuard m_Owner;
            private int m_Stage;

            public IdleTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.5))
            {
                m_Owner = owner;
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                if ((m_Stage++ % 4) == 0 || !m_Owner.Move(m_Owner.Direction))
                    m_Owner.Direction = (Direction)Utility.Random(8);

                if (m_Stage > 16)
                {
                    Effects.SendLocationParticles(EffectItem.Create(m_Owner.Location, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
                    m_Owner.PlaySound(0x1FE);

                    m_Owner.Delete();
                }
            }
        }
    }
}

:confused:
 

Nature Boy

Wanderer
TMSTKSBK;704683 said:
Note: [code ] [/code] tags are your friend...
Yeah, :), please dont be afraid of them, they are pretty helpful little guys and they dont bite that hard, more like puppy bites. :D and then I see you used them...soooo...okay anyway, your error report is well, vey direct and obvious,it tels you exactly what the problem is:
Errors:
+ Mobiles/Guards/ArcherGuard.cs:
CS0246: Line 10: The type or namespace name 'Corpsename' could not be found
(are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
Code:
[COLOR="Blue"]Line  1:[/COLOR] using System;
[COLOR="blue"]Line  2:[/COLOR] using System.Collections;
[COLOR="blue"]Line  3:[/COLOR] using Server;
[COLOR="blue"]Line  4:[/COLOR] using Server.Misc;
[COLOR="blue"]Line  5:[/COLOR] using Server.Items;
[COLOR="blue"]Line  6:[/COLOR] using Server.Mobiles;
[COLOR="blue"]Line  7: [/COLOR]
[COLOR="blue"]Line  8:[/COLOR] [COLOR="Red"]namespace [/COLOR]Server.Mobiles
[COLOR="blue"]Line  9: [/COLOR]{
[COLOR="blue"]Line 10:[/COLOR]     [[COLOR="red"]Corpsename[/COLOR]("an archerguard corpse")]
try CorpseName. :)
The greatest strides come from learning to read error reports
 

Kathrina

Wanderer
well good news is i got rid of a few more errors on my own.:)
bad news is i'm stuck and it's prob somthing obvious again but i have tried everything i can think of.:(
...but then with my small knowledge of scripts that can't be a big list...
anyway here it is and the new script
Code:
Errors:
 + Mobiles/Guards/ArcherGuard.cs:
    CS0103: Line 29: The name 'SetDamage' does not exist in the current context
    CS0103: Line 347: The name 'm_Owner' does not exist in the current context
    CS0103: Line 352: The name 'm_Owner' does not exist in the current context
    CS0103: Line 352: The name 'm_Owner' does not exist in the current context
    CS0103: Line 357: The name 'm_Owner' does not exist in the current context
    CS0103: Line 362: The name 'm_Owner' does not exist in the current context
    CS0103: Line 365: The name 'm_Owner' does not exist in the current context
    CS0103: Line 367: The name 'm_Owner' does not exist in the current context
    CS0103: Line 368: The name 'm_Owner' does not exist in the current context
    CS0103: Line 370: The name 'm_Owner' does not exist in the current context
Code:
using System;
using System.Collections;
using Server;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
    [CorpseName( "an archerguard corpse" )]
    public class ArcherGuard : BaseGuard
    {
        private Timer m_AttackTimer, m_IdleTimer;

        private Mobile m_Focus;

        [Constructable]
        public ArcherGuard()
            : this(null)
        {
        }

        public ArcherGuard(Mobile target)
            : base(target)
		{
			InitStats( 100, 125, 25 );
			Title = "the guard";

			[COLOR="Red"]SetDamage( 32, 40 );[/COLOR]
			SpeechHue = Utility.RandomDyedHue();

			Hue = Utility.RandomSkinHue();

			if ( Female = Utility.RandomBool() )
			{
				Body = 0x191;
				Name = NameList.RandomName( "female" );
			}
			else
			{
				Body = 0x190;
				Name = NameList.RandomName( "male" );
			}

			new Horse().Rider = this;

			AddItem( new StuddedChest() );
			AddItem( new StuddedArms() );
			AddItem( new StuddedGloves() );
			AddItem( new StuddedGorget() );
			AddItem( new StuddedLegs() );
			AddItem( new Boots() );
			AddItem( new SkullCap() );

			Bow bow = new Bow();

			bow.Movable = true;
			bow.Crafter = this;
			bow.Quality = WeaponQuality.Exceptional;

			AddItem( bow );

			Container pack = new Backpack();

			pack.Movable = false;

			Arrow arrows = new Arrow( 250 );

			arrows.LootType = LootType.Newbied;

			pack.DropItem( arrows );
			pack.DropItem( new Gold( 10, 25 ) );

			AddItem( pack );

			Skills[SkillName.Anatomy].Base = 120.0;
			Skills[SkillName.Tactics].Base = 120.0;
			Skills[SkillName.Archery].Base = 120.0;
			Skills[SkillName.MagicResist].Base = 120.0;
			Skills[SkillName.DetectHidden].Base = 100.0;

			Fame = 1000;
            Karma = -2000;

			this.NextCombatTime = DateTime.Now + TimeSpan.FromSeconds( 0.5 );
			this.Focus = target;
		}

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

        public override bool OnBeforeDeath()
        {
            if (m_Focus != null && m_Focus.Alive)
                new AvengeTimer(m_Focus).Start(); // If a guard dies, one more guard will spawn

            return base.OnBeforeDeath();
        }
        public override bool ShowFameTitle { get { return false; } }

        [CommandProperty(AccessLevel.GameMaster)]
        public override Mobile Focus
        {
            get
            {
                return m_Focus;
            }
            set
            {
                if (Deleted)
                    return;

                Mobile oldFocus = m_Focus;

                if (oldFocus != value)
                {
                    m_Focus = value;

                    if (value != null)
                        this.AggressiveAction(value);

                    Combatant = value;

                    if (oldFocus != null && !oldFocus.Alive)
                        Say("Thou hast suffered thy punishment, scoundrel.");

                    if (value != null)
                        Say(500131); // Thou wilt regret thine actions, swine!

                    if (m_AttackTimer != null)
                    {
                        m_AttackTimer.Stop();
                        m_AttackTimer = null;
                    }

                    if (m_IdleTimer != null)
                    {
                        m_IdleTimer.Stop();
                        m_IdleTimer = null;
                    }

                    if (m_Focus != null)
                    {
                        m_AttackTimer = new AttackTimer(this);
                        m_AttackTimer.Start();
                        ((AttackTimer)m_AttackTimer).DoOnTick();
                    }
                    else
                    {
                        m_IdleTimer = new IdleTimer(this);
                        m_IdleTimer.Start();
                    }
                }
                else if (m_Focus == null && m_IdleTimer == null)
                {
                    m_IdleTimer = new IdleTimer(this);
                    m_IdleTimer.Start();
                }
            }
        }

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

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

            writer.Write(m_Focus);
        }

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

            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        m_Focus = reader.ReadMobile();

                        if (m_Focus != null)
                        {
                            m_AttackTimer = new AttackTimer(this);
                            m_AttackTimer.Start();
                        }
                        else
                        {
                            m_IdleTimer = new IdleTimer(this);
                            m_IdleTimer.Start();
                        }

                        break;
                    }
            }
        }

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

            if (m_IdleTimer != null)
            {
                m_IdleTimer.Stop();
                m_IdleTimer = null;
            }

            base.OnAfterDelete();
        }

        private class AvengeTimer : Timer
        {
            private Mobile m_Focus;

            public AvengeTimer(Mobile focus)
                : base(TimeSpan.FromSeconds(2.5), TimeSpan.FromSeconds(1.0), 3) // After 2.5 seconds, one guard will spawn every 1.0 second, three times
            {
                m_Focus = focus;
            }

            protected override void OnTick()
            {
                BaseGuard.Spawn(m_Focus, m_Focus, 1, true);
            }
        }

        private class AttackTimer : Timer
        {
            private ArcherGuard m_Owner;
            //	private bool m_Shooting;

            public AttackTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(0.25), TimeSpan.FromSeconds(0.1))
            {
                m_Owner = owner;
            }

            public void DoOnTick()
            {
                OnTick();
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                m_Owner.Criminal = true;
                m_Owner.Kills = +1;
                m_Owner.Stam = m_Owner.StamMax;

                Mobile target = m_Owner.Focus;

                if (target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target)))
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }
                else if (m_Owner.Weapon is Fists)
                {
                    m_Owner.Kill();
                    Stop();
                    return;
                }

                if (target != null && m_Owner.Combatant != target)
                    m_Owner.Combatant = target;

                if (target == null)
                {
                    Stop();
                }

                if (target is BaseCreature)
                    ((BaseCreature)target).NoKillAwards = true;

                target.Damage(target.HitsMax, m_Owner);
                target.Kill(); // just in case, maybe Damage is overriden on some shard

                if (target.Corpse != null && !target.Player)
                    target.Corpse.Delete();

                m_Owner.Focus = null;
                Stop();
            }/*else if ( !m_Owner.InRange( target, 20 ) )
				{
					m_Shooting = false;
					m_Owner.Focus = null;
				}
				else if ( !m_Owner.InLOS( target ) )
				{
					m_Shooting = false;
					TeleportTo( target );
				}
				else if ( !m_Owner.CanSee( target ) )
				{
					m_Shooting = false;

					if ( !m_Owner.InRange( target, 2 ) )
					{
						if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
							TeleportTo( target );
					}
					else
					{
						if ( !m_Owner.UseSkill( SkillName.DetectHidden ) && Utility.Random( 50 ) == 0 )
							m_Owner.Say( "Reveal!" );
					}
				}
				else
				{
					if ( m_Shooting && (TimeToSpare() || OutOfMaxDistance( target )) )
						m_Shooting = false;
					else if ( !m_Shooting && InMinDistance( target ) )
						m_Shooting = true;

					if ( !m_Shooting )
					{
						if ( m_Owner.InRange( target, 1 ) )
						{
							if ( !m_Owner.Move( (Direction)(m_Owner.GetDirectionTo( target ) - 4) | Direction.Running ) && OutOfMaxDistance( target ) ) // Too close, move away
								RunTo( target );
						}
						else if ( !m_Owner.InRange( target, 2 ) )
						{
							if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
								RunTo( target );
						}
					}
				}*/
        }

        private bool TimeToSpare()
        {
            [COLOR="red"]return (m_Owner.NextCombatTime - DateTime.Now) > TimeSpan.FromSeconds(1.0);[/COLOR]        }

        private bool OutOfMaxDistance(Mobile target)
        {
            
             [COLOR="red"]return !m_Owner.InRange(target, m_Owner.Weapon.MaxRange);[/COLOR]
        }

        private bool InMinDistance(Mobile target)
        {
             [COLOR="red"]return m_Owner.InRange(target, 4);[/COLOR]
        }

        private void RunTo(Mobile target)
        {
            [COLOR="red"]Point3D from = m_Owner.Location;[/COLOR]
            Point3D to = target.Location;

            [COLOR="red"]m_Owner.Location = to;[/COLOR]
            [COLOR="red"]Effects.SendLocationParticles(EffectItem.Create(from, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
            Effects.SendLocationParticles(EffectItem.Create(to, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 5023);

            m_Owner.PlaySound(0x1FE); [/COLOR]
            }

        private class IdleTimer : Timer
        {
            private ArcherGuard m_Owner;
            private int m_Stage;

            public IdleTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.5))
            {
                m_Owner = owner;
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                if ((m_Stage++ % 4) == 0 || !m_Owner.Move(m_Owner.Direction))
                    m_Owner.Direction = (Direction)Utility.Random(8);

                if (m_Stage > 16)
                {
                    Effects.SendLocationParticles(EffectItem.Create(m_Owner.Location, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
                    m_Owner.PlaySound(0x1FE);

                    m_Owner.Delete();
                }
            }
        }
    }
}

Any ideas i don't understand. I did it just like another script that is working fine. :confused:


it looks as though i messed up the tabs when i tryed to highlight it sorry
 

Kathrina

Wanderer
Kyler;705031 said:
well the error is m_owner so i suppose its not the right thing to put

but that was what was there for the normal guards i didn't change anything but the instakill there. what else could possibly go there and how did i mess that up
:confused:
 

Greystar

Wanderer
Kathrina;705168 said:
but that was what was there for the normal guards i didn't change anything but the instakill there. what else could possibly go there and how did i mess that up
:confused:

Well the SetDamage error is probably becuase BaseGuard doesn't inherit from BaseCreature so it doesn't exist.


As fat as why m_Owner doesn't work I'm not to sure at this point.
 

Kathrina

Wanderer
good news/bad news with the guards

great news i fixed my errors so i can get the shard running with them.:D

bad news even though i took out what i thought was the teliporting they are still teliport in and out. i even set a spawner for them and they are teliporting. they don't stay spawned they teliport out after a few minutes.

Then when i had my co-owner stat up a player char enough to be an experianced char and test them when he did kill them instead of droping a corpse he would teleport out.

the final prob i have is that he isn't acting like an archer. he wonders around ignoring the crimanal except shooting arows at him but doesn't ingage i think i can salve this prob but i haven't been able to at this time

any ideas i would be greatfull
here is the script so far
Code:
using System;
using System.Collections;
using Server;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
    [CorpseName( "an archerguard corpse" )]
    public class ArcherGuard : BaseGuard
    {
        private Timer m_AttackTimer, m_IdleTimer;

        private Mobile m_Focus;

        [Constructable]
        public ArcherGuard()
            : this(null)
        {
        }

        public ArcherGuard(Mobile target)
            : base(target)
		{
			InitStats( 200, 150, 25 );
			Title = "the guard";

			SpeechHue = Utility.RandomDyedHue();

			Hue = Utility.RandomSkinHue();

			if ( Female = Utility.RandomBool() )
			{
				Body = 0x191;
				Name = NameList.RandomName( "female" );
			}
			else
			{
				Body = 0x190;
				Name = NameList.RandomName( "male" );
			}

			new Horse().Rider = this;

			AddItem( new StuddedChest() );
			AddItem( new StuddedArms() );
			AddItem( new StuddedGloves() );
			AddItem( new StuddedGorget() );
			AddItem( new StuddedLegs() );
			AddItem( new Boots() );
			AddItem( new SkullCap() );

			Bow bow = new Bow();

			bow.Movable = true;
			bow.Crafter = this;
			bow.Quality = WeaponQuality.Exceptional;

			AddItem( bow );

			Container pack = new Backpack();

			pack.Movable = false;

			Arrow arrows = new Arrow( 250 );

			arrows.LootType = LootType.Newbied;

			pack.DropItem( arrows );
			pack.DropItem( new Gold( 10, 25 ) );

			AddItem( pack );

			Skills[SkillName.Anatomy].Base = 120.0;
			Skills[SkillName.Tactics].Base = 120.0;
			Skills[SkillName.Archery].Base = 120.0;
			Skills[SkillName.MagicResist].Base = 120.0;
			Skills[SkillName.DetectHidden].Base = 100.0;

			Fame = 1000;
            Karma = -2000;

			this.NextCombatTime = DateTime.Now + TimeSpan.FromSeconds( 0.5 );
			this.Focus = target;
		}

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

        public override bool OnBeforeDeath()
        {
            if (m_Focus != null && m_Focus.Alive)
                new AvengeTimer(m_Focus).Start(); // If a guard dies, one more guard will spawn

            return base.OnBeforeDeath();
        }
        public override bool ShowFameTitle { get { return false; } }

        [CommandProperty(AccessLevel.GameMaster)]
        public override Mobile Focus
        {
            get
            {
                return m_Focus;
            }
            set
            {
                if (Deleted)
                    return;

                Mobile oldFocus = m_Focus;

                if (oldFocus != value)
                {
                    m_Focus = value;

                    if (value != null)
                        this.AggressiveAction(value);

                    Combatant = value;

                    if (oldFocus != null && !oldFocus.Alive)
                        Say("Thou hast suffered thy punishment, scoundrel.");

                    if (value != null)
                        Say(500131); // Thou wilt regret thine actions, swine!

                    if (m_AttackTimer != null)
                    {
                        m_AttackTimer.Stop();
                        m_AttackTimer = null;
                    }

                    if (m_IdleTimer != null)
                    {
                        m_IdleTimer.Stop();
                        m_IdleTimer = null;
                    }

                    if (m_Focus != null)
                    {
                        m_AttackTimer = new AttackTimer(this);
                        m_AttackTimer.Start();
                        ((AttackTimer)m_AttackTimer).DoOnTick();
                    }
                    else
                    {
                        m_IdleTimer = new IdleTimer(this);
                        m_IdleTimer.Start();
                    }
                }
                else if (m_Focus == null && m_IdleTimer == null)
                {
                    m_IdleTimer = new IdleTimer(this);
                    m_IdleTimer.Start();
                }
            }
        }

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

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

            writer.Write(m_Focus);
        }

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

            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        m_Focus = reader.ReadMobile();

                        if (m_Focus != null)
                        {
                            m_AttackTimer = new AttackTimer(this);
                            m_AttackTimer.Start();
                        }
                        else
                        {
                            m_IdleTimer = new IdleTimer(this);
                            m_IdleTimer.Start();
                        }

                        break;
                    }
            }
        }

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

            if (m_IdleTimer != null)
            {
                m_IdleTimer.Stop();
                m_IdleTimer = null;
            }

            base.OnAfterDelete();
        }

        private class AvengeTimer : Timer
        {
            private Mobile m_Focus;

            public AvengeTimer(Mobile focus)
                : base(TimeSpan.FromSeconds(2.5), TimeSpan.FromSeconds(1.0), 3) // After 2.5 seconds, one guard will spawn every 1.0 second, three times
            {
                m_Focus = focus;
            }

            protected override void OnTick()
            {
                BaseGuard.Spawn(m_Focus, m_Focus, 1, true);
            }
        }

        private class AttackTimer : Timer
        {
            private ArcherGuard m_Owner;
            //	private bool m_Shooting;

            public AttackTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(0.25), TimeSpan.FromSeconds(0.1))
            {
                m_Owner = owner;
            }

            public void DoOnTick()
            {
                OnTick();
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                m_Owner.Criminal = true;
                m_Owner.Kills = +1;
                m_Owner.Stam = m_Owner.StamMax;

                Mobile target = m_Owner.Focus;

                if (target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target)))
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }
                else if (m_Owner.Weapon is Fists)
                {
                    m_Owner.Kill();
                    Stop();
                    return;
                }

                if (target != null && m_Owner.Combatant != target)
                    m_Owner.Combatant = target;

                if (target == null)
                {
                    Stop();
                }

                if (target is BaseCreature)
                    ((BaseCreature)target).NoKillAwards = true;

                target.Damage(target.HitsMax, m_Owner);
                target.Kill(); // just in case, maybe Damage is overriden on some shard

                if (target.Corpse != null && !target.Player)
                    target.Corpse.Delete();

                m_Owner.Focus = null;
                Stop();
            }/*else if ( !m_Owner.InRange( target, 20 ) )
				{
					m_Shooting = false;
					m_Owner.Focus = null;
				}
				else if ( !m_Owner.InLOS( target ) )
				{
					m_Shooting = false;
					TeleportTo( target );
				}
				else if ( !m_Owner.CanSee( target ) )
				{
					m_Shooting = false;

					if ( !m_Owner.InRange( target, 2 ) )
					{
						if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
							TeleportTo( target );
					}
					else
					{
						if ( !m_Owner.UseSkill( SkillName.DetectHidden ) && Utility.Random( 50 ) == 0 )
							m_Owner.Say( "Reveal!" );
					}
				}
				else
				{
					if ( m_Shooting && (TimeToSpare() || OutOfMaxDistance( target )) )
						m_Shooting = false;
					else if ( !m_Shooting && InMinDistance( target ) )
						m_Shooting = true;

					if ( !m_Shooting )
					{
						if ( m_Owner.InRange( target, 1 ) )
						{
							if ( !m_Owner.Move( (Direction)(m_Owner.GetDirectionTo( target ) - 4) | Direction.Running ) && OutOfMaxDistance( target ) ) // Too close, move away
								RunTo( target );
						}
						else if ( !m_Owner.InRange( target, 2 ) )
						{
							if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
								RunTo( target );
						}
					}
				}*/
        }

        private class IdleTimer : Timer
        {
            private ArcherGuard m_Owner;
            private int m_Stage;

            public IdleTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.5))
            {
                m_Owner = owner;
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                if ((m_Stage++ % 4) == 0 || !m_Owner.Move(m_Owner.Direction))
                    m_Owner.Direction = (Direction)Utility.Random(8);

                if (m_Stage > 16)
                {
                    Effects.SendLocationParticles(EffectItem.Create(m_Owner.Location, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
                    m_Owner.PlaySound(0x1FE);

                    m_Owner.Delete();
                }
            }
        }
    }
}
:confused:

i think i almost have them done thanks to all of you ;)
 

Greystar

Wanderer
Kathrina;705495 said:
great news i fixed my errors so i can get the shard running with them.:D

bad news even though i took out what i thought was the teliporting they are still teliport in and out. i even set a spawner for them and they are teliporting. they don't stay spawned they teliport out after a few minutes.

Then when i had my co-owner stat up a player char enough to be an experianced char and test them when he did kill them instead of droping a corpse he would teleport out.

the final prob i have is that he isn't acting like an archer. he wonders around ignoring the crimanal except shooting arows at him but doesn't ingage i think i can salve this prob but i haven't been able to at this time

any ideas i would be greatfull
here is the script so far
Code:
using System;
using System.Collections;
using Server;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
    [CorpseName( "an archerguard corpse" )]
    public class ArcherGuard : BaseGuard
    {
        private Timer m_AttackTimer, m_IdleTimer;

        private Mobile m_Focus;

        [Constructable]
        public ArcherGuard()
            : this(null)
        {
        }

        public ArcherGuard(Mobile target)
            : base(target)
		{
			InitStats( 200, 150, 25 );
			Title = "the guard";

			SpeechHue = Utility.RandomDyedHue();

			Hue = Utility.RandomSkinHue();

			if ( Female = Utility.RandomBool() )
			{
				Body = 0x191;
				Name = NameList.RandomName( "female" );
			}
			else
			{
				Body = 0x190;
				Name = NameList.RandomName( "male" );
			}

			new Horse().Rider = this;

			AddItem( new StuddedChest() );
			AddItem( new StuddedArms() );
			AddItem( new StuddedGloves() );
			AddItem( new StuddedGorget() );
			AddItem( new StuddedLegs() );
			AddItem( new Boots() );
			AddItem( new SkullCap() );

			Bow bow = new Bow();

			bow.Movable = true;
			bow.Crafter = this;
			bow.Quality = WeaponQuality.Exceptional;

			AddItem( bow );

			Container pack = new Backpack();

			pack.Movable = false;

			Arrow arrows = new Arrow( 250 );

			arrows.LootType = LootType.Newbied;

			pack.DropItem( arrows );
			pack.DropItem( new Gold( 10, 25 ) );

			AddItem( pack );

			Skills[SkillName.Anatomy].Base = 120.0;
			Skills[SkillName.Tactics].Base = 120.0;
			Skills[SkillName.Archery].Base = 120.0;
			Skills[SkillName.MagicResist].Base = 120.0;
			Skills[SkillName.DetectHidden].Base = 100.0;

			Fame = 1000;
            Karma = -2000;

			this.NextCombatTime = DateTime.Now + TimeSpan.FromSeconds( 0.5 );
			this.Focus = target;
		}

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

        public override bool OnBeforeDeath()
        {
            if (m_Focus != null && m_Focus.Alive)
                new AvengeTimer(m_Focus).Start(); // If a guard dies, one more guard will spawn

            return base.OnBeforeDeath();
        }
        public override bool ShowFameTitle { get { return false; } }

        [CommandProperty(AccessLevel.GameMaster)]
        public override Mobile Focus
        {
            get
            {
                return m_Focus;
            }
            set
            {
                if (Deleted)
                    return;

                Mobile oldFocus = m_Focus;

                if (oldFocus != value)
                {
                    m_Focus = value;

                    if (value != null)
                        this.AggressiveAction(value);

                    Combatant = value;

                    if (oldFocus != null && !oldFocus.Alive)
                        Say("Thou hast suffered thy punishment, scoundrel.");

                    if (value != null)
                        Say(500131); // Thou wilt regret thine actions, swine!

                    if (m_AttackTimer != null)
                    {
                        m_AttackTimer.Stop();
                        m_AttackTimer = null;
                    }

                    if (m_IdleTimer != null)
                    {
                        m_IdleTimer.Stop();
                        m_IdleTimer = null;
                    }

                    if (m_Focus != null)
                    {
                        m_AttackTimer = new AttackTimer(this);
                        m_AttackTimer.Start();
                        ((AttackTimer)m_AttackTimer).DoOnTick();
                    }
                    else
                    {
                        m_IdleTimer = new IdleTimer(this);
                        m_IdleTimer.Start();
                    }
                }
                else if (m_Focus == null && m_IdleTimer == null)
                {
                    m_IdleTimer = new IdleTimer(this);
                    m_IdleTimer.Start();
                }
            }
        }

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

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

            writer.Write(m_Focus);
        }

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

            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        m_Focus = reader.ReadMobile();

                        if (m_Focus != null)
                        {
                            m_AttackTimer = new AttackTimer(this);
                            m_AttackTimer.Start();
                        }
                        else
                        {
                            m_IdleTimer = new IdleTimer(this);
                            m_IdleTimer.Start();
                        }

                        break;
                    }
            }
        }

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

            if (m_IdleTimer != null)
            {
                m_IdleTimer.Stop();
                m_IdleTimer = null;
            }

            base.OnAfterDelete();
        }

        private class AvengeTimer : Timer
        {
            private Mobile m_Focus;

            public AvengeTimer(Mobile focus)
                : base(TimeSpan.FromSeconds(2.5), TimeSpan.FromSeconds(1.0), 3) // After 2.5 seconds, one guard will spawn every 1.0 second, three times
            {
                m_Focus = focus;
            }

            protected override void OnTick()
            {
                BaseGuard.Spawn(m_Focus, m_Focus, 1, true);
            }
        }

        private class AttackTimer : Timer
        {
            private ArcherGuard m_Owner;
            //	private bool m_Shooting; //<-- Uncomment this

            public AttackTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(0.25), TimeSpan.FromSeconds(0.1))
            {
                m_Owner = owner;
            }

            public void DoOnTick()
            {
                OnTick();
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                m_Owner.Criminal = true;
                m_Owner.Kills = +1;
                m_Owner.Stam = m_Owner.StamMax;

                Mobile target = m_Owner.Focus;

                if (target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target)))
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }
                else if (m_Owner.Weapon is Fists)
                {
                    [COLOR="Red"]m_Owner.Kill();[/COLOR]//This will kill the guard if they are not armed.
                    Stop();
                    return;
                }

                if (target != null && m_Owner.Combatant != target)
                    m_Owner.Combatant = target;

                if (target == null)
                {
                    Stop();
                }

                if (target is BaseCreature)
                    ((BaseCreature)target).NoKillAwards = true;

[COLOR="red"]                target.Damage(target.HitsMax, m_Owner); //<-- this does max hps in damage to target
                target.Kill(); // just in case, maybe Damage is overriden on some shard <<-- This autokilsl the target[/COLOR]
                if (target.Corpse != null && !target.Player)
                    target.Corpse.Delete();

                m_Owner.Focus = null;
                Stop();
            }[COLOR="red"]/*else if ( !m_Owner.InRange( target, 20 ) )
				{
					m_Shooting = false;
					m_Owner.Focus = null;
				}
				else if ( !m_Owner.InLOS( target ) )
				{
					m_Shooting = false;
					TeleportTo( target );
				}
				else if ( !m_Owner.CanSee( target ) )
				{
					m_Shooting = false;

					if ( !m_Owner.InRange( target, 2 ) )
					{
						if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
							TeleportTo( target );
					}
					else
					{
						if ( !m_Owner.UseSkill( SkillName.DetectHidden ) && Utility.Random( 50 ) == 0 )
							m_Owner.Say( "Reveal!" );
					}
				}
				else
				{
					if ( m_Shooting && (TimeToSpare() || OutOfMaxDistance( target )) )
						m_Shooting = false;
					else if ( !m_Shooting && InMinDistance( target ) )
						m_Shooting = true;

					if ( !m_Shooting )
					{
						if ( m_Owner.InRange( target, 1 ) )
						{
							if ( !m_Owner.Move( (Direction)(m_Owner.GetDirectionTo( target ) - 4) | Direction.Running ) && OutOfMaxDistance( target ) ) // Too close, move away
								RunTo( target );
						}
						else if ( !m_Owner.InRange( target, 2 ) )
						{
							if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
								RunTo( target );
						}
					}
				}*/[/COLOR]   //this bracket of code is for the archer stuff
     }

[COLOR="red"]        private class IdleTimer : Timer
        {
            private ArcherGuard m_Owner;
            private int m_Stage;

            public IdleTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.5))
            {
                m_Owner = owner;
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                if ((m_Stage++ % 4) == 0 || !m_Owner.Move(m_Owner.Direction))
                    m_Owner.Direction = (Direction)Utility.Random(8);

                if (m_Stage > 16)
                {
                    Effects.SendLocationParticles(EffectItem.Create(m_Owner.Location, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
                    m_Owner.PlaySound(0x1FE);

                    m_Owner.Delete(); //<-- this despawns the mobile if they have not target
                }
            }
        }[/COLOR]//<-- this makes them wander and despawn if have no target
    }
}
:confused:

i think i almost have them done thanks to all of you ;)

take a look at the stuff I colored and added comments too... that might help you make them shoot like archers and maybe help to keep them from auto despawning if you get it to work the way you want. Also the guards won't target criminals unless they are called by the shopkeepers that code is in BaseCreature if I recall correctly. So there is many places guards are tied in.
 

Kathrina

Wanderer
:mad: ok now what i still can't get them to drop a corps and they still teleport out after a while but now they hang around a minute after they reach 0 hitpoints before teleporting out. what am i missing?:confused:
base guard
Code:
using System;
using System.Collections;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
	public abstract class BaseGuard : Mobile
	{
		public static void Spawn( Mobile caller, Mobile target )
		{
			Spawn( caller, target, 1, true );
		}

		public static void Spawn( Mobile caller, Mobile target, int amount, bool onlyAdditional )
		{
			if ( target == null || target.Deleted )
				return;

			foreach ( Mobile m in target.GetMobilesInRange( 15 ) )
			{
				if ( m is BaseGuard )
				{
					BaseGuard g = (BaseGuard)m;

					if ( g.Focus == null ) // idling
					{
						g.Focus = target;

						--amount;
					}
					else if ( g.Focus == target && !onlyAdditional )
					{
						--amount;
					}
				}
			}

			while ( amount-- > 0 )
				caller.Region.MakeGuard( target );
		}

		public BaseGuard( Mobile target )
		{
			if ( target != null )
			{
				Location = target.Location;
				Map = target.Map;

				Effects.SendLocationParticles( EffectItem.Create( Location, Map, EffectItem.DefaultDuration ), 0x3728, 10, 10, 5023 );
			}
		}

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

		public override bool OnBeforeDeath()
		{
			Effects.SendLocationParticles( EffectItem.Create( Location, Map, EffectItem.DefaultDuration ), 0x3728, 10, 10, 2023 );

			PlaySound( 0x1FE );

			return false;
		}

		public abstract Mobile Focus{ get; set; }

		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();
		}
	}
}
killable archer
Code:
using System;
using System.Collections;
using Server;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
    [CorpseName( "an archerguard corpse" )]
    public class ArcherGuard : BaseGuard
    {
        private Timer m_AttackTimer, m_IdleTimer;

        private Mobile m_Focus;

        [Constructable]
        public ArcherGuard()
            : this(null)
        {
        }

        public ArcherGuard(Mobile target)
            : base(target)
		{
			InitStats( 100, 125, 25 );
			Title = "the guard";

			SpeechHue = Utility.RandomDyedHue();

			Hue = Utility.RandomSkinHue();

			if ( Female = Utility.RandomBool() )
			{
				Body = 0x191;
				Name = NameList.RandomName( "female" );
			}
			else
			{
				Body = 0x190;
				Name = NameList.RandomName( "male" );
			}

			new Horse().Rider = this;

			AddItem( new StuddedChest() );
			AddItem( new StuddedArms() );
			AddItem( new StuddedGloves() );
			AddItem( new StuddedGorget() );
			AddItem( new StuddedLegs() );
			AddItem( new Boots() );
			AddItem( new SkullCap() );

			Bow bow = new Bow();

			bow.Movable = true;
			bow.Crafter = this;
			bow.Quality = WeaponQuality.Exceptional;

			AddItem( bow );

			Container pack = new Backpack();

			pack.Movable = false;

			Arrow arrows = new Arrow( 250 );

			arrows.LootType = LootType.Newbied;

			pack.DropItem( arrows );
			pack.DropItem( new Gold( 10, 25 ) );

			AddItem( pack );

			Skills[SkillName.Anatomy].Base = 120.0;
			Skills[SkillName.Tactics].Base = 120.0;
			Skills[SkillName.Archery].Base = 120.0;
			Skills[SkillName.MagicResist].Base = 120.0;
			Skills[SkillName.DetectHidden].Base = 100.0;

			Fame = 1000;
            Karma = -2000;

			this.NextCombatTime = DateTime.Now + TimeSpan.FromSeconds( 0.5 );
			this.Focus = target;
		}

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

        public override bool OnBeforeDeath()
        {
            if (m_Focus != null && m_Focus.Alive)
                new AvengeTimer(m_Focus).Start(); // If a guard dies, one more guard will spawn

            return base.OnBeforeDeath();
        }
        public override bool ShowFameTitle { get { return false; } }

        [CommandProperty(AccessLevel.GameMaster)]
        public override Mobile Focus
        {
            get
            {
                return m_Focus;
            }
            set
            {
                if (Deleted)
                    return;

                Mobile oldFocus = m_Focus;

                if (oldFocus != value)
                {
                    m_Focus = value;

                    if (value != null)
                        this.AggressiveAction(value);

                    Combatant = value;

                    if (oldFocus != null && !oldFocus.Alive)
                        Say("Thou hast suffered thy punishment, scoundrel.");

                    if (value != null)
                        Say(500131); // Thou wilt regret thine actions, swine!

                    if (m_AttackTimer != null)
                    {
                        m_AttackTimer.Stop();
                        m_AttackTimer = null;
                    }

                    if (m_IdleTimer != null)
                    {
                        m_IdleTimer.Stop();
                        m_IdleTimer = null;
                    }

                    if (m_Focus != null)
                    {
                        m_AttackTimer = new AttackTimer(this);
                        m_AttackTimer.Start();
                        ((AttackTimer)m_AttackTimer).DoOnTick();
                    }
                    else
                    {
                        m_IdleTimer = new IdleTimer(this);
                        m_IdleTimer.Start();
                    }
                }
                else if (m_Focus == null && m_IdleTimer == null)
                {
                    m_IdleTimer = new IdleTimer(this);
                    m_IdleTimer.Start();
                }
            }
        }

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

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

            writer.Write(m_Focus);
        }

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

            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        m_Focus = reader.ReadMobile();

                        if (m_Focus != null)
                        {
                            m_AttackTimer = new AttackTimer(this);
                            m_AttackTimer.Start();
                        }
                        else
                        {
                            m_IdleTimer = new IdleTimer(this);
                            m_IdleTimer.Start();
                        }

                        break;
                    }
            }
        }

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

            if (m_IdleTimer != null)
            {
                m_IdleTimer.Stop();
                m_IdleTimer = null;
            }

            base.OnAfterDelete();
        }

        private class AvengeTimer : Timer
        {
            private Mobile m_Focus;

            public AvengeTimer(Mobile focus)
                : base(TimeSpan.FromSeconds(2.5), TimeSpan.FromSeconds(1.0), 3) // After 2.5 seconds, one guard will spawn every 1.0 second, three times
            {
                m_Focus = focus;
            }

            protected override void OnTick()
            {
                BaseGuard.Spawn(m_Focus, m_Focus, 1, true);
            }
        }

        private class AttackTimer : Timer
        {
            private ArcherGuard m_Owner;
            //	private bool m_Shooting;

            public AttackTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(0.25), TimeSpan.FromSeconds(0.1))
            {
                m_Owner = owner;
            }

            public void DoOnTick()
            {
                OnTick();
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                m_Owner.Criminal = true;
                m_Owner.Kills = +1;
                m_Owner.Stam = m_Owner.StamMax;

                Mobile target = m_Owner.Focus;

                if (target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful(target)))
                {
                    m_Owner.Focus = null;
                    Stop();
                    return;
                }
                else if (m_Owner.Weapon is Fists)
                {
                    m_Owner.Kill();
                    Stop();
                    return;
                }

                if (target != null && m_Owner.Combatant != target)
                    m_Owner.Combatant = target;

                if (target == null)
                {
                    Stop();
                }

                if (target is BaseCreature)
                    ((BaseCreature)target).NoKillAwards = true;

                target.Damage(target.HitsMax, m_Owner);
                target.Kill(); // just in case, maybe Damage is overriden on some shard

                if (target.Corpse != null && !target.Player)
                    target.Corpse.Delete();

                m_Owner.Focus = null;
                Stop();
            }/*else if ( !m_Owner.InRange( target, 20 ) )
				{
					m_Shooting = false;
					m_Owner.Focus = null;
				}
				else if ( !m_Owner.InLOS( target ) )
				{
					m_Shooting = false;
					TeleportTo( target );
				}
				else if ( !m_Owner.CanSee( target ) )
				{
					m_Shooting = false;

					if ( !m_Owner.InRange( target, 2 ) )
					{
						if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
							TeleportTo( target );
					}
					else
					{
						if ( !m_Owner.UseSkill( SkillName.DetectHidden ) && Utility.Random( 50 ) == 0 )
							m_Owner.Say( "Reveal!" );
					}
				}
				else
				{
					if ( m_Shooting && (TimeToSpare() || OutOfMaxDistance( target )) )
						m_Shooting = false;
					else if ( !m_Shooting && InMinDistance( target ) )
						m_Shooting = true;

					if ( !m_Shooting )
					{
						if ( m_Owner.InRange( target, 1 ) )
						{
							if ( !m_Owner.Move( (Direction)(m_Owner.GetDirectionTo( target ) - 4) | Direction.Running ) && OutOfMaxDistance( target ) ) // Too close, move away
								RunTo( target );
						}
						else if ( !m_Owner.InRange( target, 2 ) )
						{
							if ( !m_Owner.Move( m_Owner.GetDirectionTo( target ) | Direction.Running ) && OutOfMaxDistance( target ) )
								RunTo( target );
						}
					}
				}*/
        }

        private class IdleTimer : Timer
        {
            private ArcherGuard m_Owner;
            private int m_Stage;

            public IdleTimer(ArcherGuard owner)
                : base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.5))
            {
                m_Owner = owner;
            }

            protected override void OnTick()
            {
                if (m_Owner.Deleted)
                {
                    Stop();
                    return;
                }

                if ((m_Stage++ % 4) == 0 || !m_Owner.Move(m_Owner.Direction))
                    m_Owner.Direction = (Direction)Utility.Random(8);

                if (m_Stage > 16)
                {
                    Effects.SendLocationParticles(EffectItem.Create(m_Owner.Location, m_Owner.Map, EffectItem.DefaultDuration), 0x3728, 10, 10, 2023);
                    m_Owner.PlaySound(0x1FE);

                    m_Owner.Delete();
                }
            }
        }
    }
}
thank you for your help these guys are headach inducers.;)
 

Nature Boy

Wanderer
Code:
using System;
using System.Collections;
using Server;
using Server.Misc;
using Server.Items;
using Server.Mobiles;

namespace Server.Mobiles
{
    [CorpseName( "an archerguard corpse" )]
    public class ArcherGuard : [COLOR="Red"]BaseGuard[/COLOR]

The problem may be that your guards are a child class of the parent namespace BaseGuard so...your guards will do what their daddy tells them unless you override the parent class. When you override the parent class, in that method is where you will have to add the corpse drop instead of poofing out. Look through your BaseGuard and see what the method used is for making them teleport in and out and thats what you will have to override. FUN FUN FUN
 

Tomahawk

Wanderer
Wouldn't it jsut be easier to c reate a different mobile that would patrol around the streets than editing the actual guard scripts?
 

Greystar

Wanderer
Tomahawk;705924 said:
Wouldn't it jsut be easier to c reate a different mobile that would patrol around the streets than editing the actual guard scripts?

Yes and No... If you want to keep the functionality of guards then it would be more accurate to edit the existing guards. If you just wanted wandering mobiles who acted like guards you should disable guards all together and write new mobiles... but why duplicate something that exists when you can change it instead.

Now as far as the previous post before this one. It should still inherit from BaseGuard but BaseGuard should be made to inherit from BaseCreature currently if I recall currectly it inherits from Mobile. Also there is code in there that makes it so that guards delete there corpse when they die I think. Atleast in the new version, it may have been that way in the old version but may have been one of the first things I changed. It was a while ago that I wrote it and its been a really long time since I even bothered to look at a "stock" version of the guard stuff.
 
Top