I've been typing away at custom sets of armor, and a few of my players want me to make some custom Ranger Armor. I've got it setup to require Dexterity instead of Strength.

I want to make a check in the playermobile OnDamage to see if the player is wearing anything with my base class : DexRangerArmor. And if so, calculate a dodge chance and charge some stamina if successful.

I've seen in playermobile: EquipSnapshot :

public List<Item> EquipSnapshot { get { return m_EquipSnapshot; } }

I'm guessing this creates a list of current equipment. How can I use this to check for my custom armor class? Is there another way?
 
There's the OrcBrute but you'll have to code it to check each layer for an item

Code:
public override bool IsEnemy(Mobile m)
        {
            if (m.Player && m.FindItemOnLayer(Layer.Helm) is OrcishKinMask)
                return false;

            return base.IsEnemy(m);
        }

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

            Item item = aggressor.FindItemOnLayer(Layer.Helm);

            if (item is OrcishKinMask)
            {
                AOS.Damage(aggressor, 50, 0, 100, 0, 0, 0);
                item.Delete();
                aggressor.FixedParticles(0x36BD, 20, 10, 5044, EffectLayer.Head);
                aggressor.PlaySound(0x307);
            }
        }
 
Wow, didn't even think of checking the Orc Mask! Very good Idea. Time to fiddle. Also, can I reference a base class? or must it be a specific item? Could I do typeof(baseclass) in stead?

I'm testing this now:
Code:
			if (from.FindItemOnLayer(Layer.InnerTorso) is RangerChainmailChest)
			{	
				switch( Utility.Random(1))
				{
					case 0: amount = 0; from.Stam =- 10; from.Say("You dodge the attack"); from.PlaySound(0x51A); break;
				}
			}

Hrm.. This compiles, but does not work.

Here is the OnDamage Method as well:
Code:
public override void OnDamage(int amount, Mobile from, bool willKill)
		{
			int disruptThreshold;

			if (!Core.AOS)
			{
				disruptThreshold = 0;
			}
			else if (from != null && from.Player)
			{
				disruptThreshold = 18;
			}
			else
			{
				disruptThreshold = 25;
			}

			if (amount > disruptThreshold)
			{
				BandageContext c = BandageContext.GetContext(this);

				if (c != null)
				{
					c.Slip();
				}
			}

			if (Confidence.IsRegenerating(this))
			{
				Confidence.StopRegenerating(this);
			}

			WeightOverloading.FatigueOnDamage(this, amount);

			if (m_ReceivedHonorContext != null)
			{
				m_ReceivedHonorContext.OnTargetDamaged(from, amount);
			}
			if (m_SentHonorContext != null)
			{
				m_SentHonorContext.OnSourceDamaged(from, amount);
			}

			if (willKill && from is PlayerMobile)
			{
				Timer.DelayCall(TimeSpan.FromSeconds(10), ((PlayerMobile)@from).RecoverAmmo);
			}

			#region Mondain's Legacy
			if (InvisibilityPotion.HasTimer(this))
			{
				InvisibilityPotion.Iterrupt(this);
			}
			#endregion

			if (from.FindItemOnLayer(Layer.InnerTorso) is RangerChainmailChest)
			{	
				switch( Utility.Random(1))
				{
					case 0: amount = 0; from.Stam =- 10; from.Say("You dodge the attack"); from.PlaySound(0x51A); break;
				}
			}
			
			base.OnDamage(amount, from, willKill);
		}
 
Last edited:
Well in your script "from" is the one doing the damage, not the one receiving it. The PlayerMobile who is receiving the damage is referred to as "this" (since the code is running on 'this').

So you can either refer to them using:
this.FindItemOnLayer
or simply
FindItemOnLayer (we don't need to reference 'this', it's automatically assumed).

Basically:
Code:
if(from.FindItemOnLayer(Layer.InnerTorso)is RangerChainmailChest)

should be

Code:
if( FindItemOnLayer(Layer.InnerTorso)is RangerChainmailChest )
 
Yep. That was it. It's all working great now! So, could I replace the RangerChainmailChest with typeof(DexRangerChest) instead?

EDIT:

typeof(DexRangerChest) does not work. Gives me a type error. Any ideas?
 
Last edited:
I'm not sure what you're trying to do with typeof. You don't need to use it. You'd use typeof() if you knew the type and were checking something like "if( type == typeof( DexRangerChest ) )" but in this situation, we don't have a type for comparison, we have an object.

If DexRangerChest is a base class of RangerChainmailChest then you can just say
Code:
if( FindItemOnLayer(Layer.InnerTorso) is DexRangerChest )
 
Works perfectly. Thanks Jack.

I don't know much C#, and what I have learned is from users like yourself. I'm sure some of this stuff would seem obvious to someone proficient in the language. I am very grateful for the help!

I'm picking up things as I go.

For those interested here is the final result that's working:
Code:
			if (FindItemOnLayer(Layer.InnerTorso) is DexRangerChest) // Make other pieces and add || is DexRangerHelm etc..
			{	
				
				switch( Utility.Random(1))
				{
					case 0: amount = 0; this.Stam =- 10; this.Say("Dodged!"); this.PlaySound(0x51B); break;
				}
			}
 
Last edited:
Back