Lemke

Member
Hello,just asking the correct way to add atachment inside a script (deed).I adviced how to add a simple atachment in treasure map decoder:
Example code:
C#:
TMapDecoderXmlAtt tmd = (TMapDecoderXmlAtt)XmlAttach.FindAttachment(item, typeof(TMapDecoderXmlAtt));
            
            if ( tmd == null &&  this.Uses > 0 )
            {
                XmlAttach.AttachTo(item, new TMapDecoderXmlAtt());
                this.Uses--;
                this.InvalidateProperties();
Now i wish to use atachment from the XML atachments resource,example (XML weapon attribute):
C#:
using System;
using Server;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using System.Reflection;

namespace Server.Engines.XmlSpawner2
{
    public class XmlWeaponAbility : XmlAttachment
    {
        private WeaponAbility m_Ability = null;    // default data

        public WeaponAbility WeaponAbility
        {
            get { return m_Ability;  }
            set { m_Ability = value;  }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public string Ability
        {
            get
            {
                if (m_Ability != null)
                {
                    return m_Ability.GetType().Name;
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (value != null)
                {
                    FieldInfo finfo = typeof(WeaponAbility).GetField(value);
                    if (finfo != null && finfo.IsStatic && finfo.FieldType == typeof(WeaponAbility))
                    {
                        try
                        {
                            m_Ability = (WeaponAbility)finfo.GetValue(null);
                        }
                        catch { }
                    }
                }
                else
                {
                    m_Ability = null;
                }
            }
        }


        // These are the various ways in which the message attachment can be constructed. 
        // These can be called via the [addatt interface, via scripts, via the spawner ATTACH keyword.
        // Other overloads could be defined to handle other types of arguments
      
        // a serial constructor is REQUIRED
        public XmlWeaponAbility(ASerial serial) : base(serial)
        {
        }

        [Attachable]
        public XmlWeaponAbility(string weaponability)
        {
            Ability = weaponability;
        }

        [Attachable]
        public XmlWeaponAbility(string name, string weaponability)
        {
            Name = name;
            Ability = weaponability;
        }

        [Attachable]
        public XmlWeaponAbility(string name, string weaponability, double expiresin)
        {
            Name = name;
            Ability = weaponability;
            Expiration = TimeSpan.FromMinutes(expiresin); //

        }

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

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

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

            int version = reader.ReadInt();
            // version 0
            Ability = reader.ReadString();
        }

        public override string OnIdentify(Mobile from)
        {
            if(from == null || from.AccessLevel == AccessLevel.Player) return null;

            if(Expiration > TimeSpan.Zero)
            {
                return String.Format("{2}: Weapon ability {0} expires in {1} mins", Ability, Expiration.TotalMinutes, Name);
            }
            else
            {
                return String.Format("{1}: Weapon ability {0}", Ability, Name);
            }
        }
    }
}
Can anyone write here the way to add atachment to an item when target it from a deed?Thank you!
 
Hello,just asking the correct way to add atachment inside a script (deed).I adviced how to add a simple atachment in treasure map decoder:
Example code:
C#:
TMapDecoderXmlAtt tmd = (TMapDecoderXmlAtt)XmlAttach.FindAttachment(item, typeof(TMapDecoderXmlAtt));
           
            if ( tmd == null &&  this.Uses > 0 )
            {
                XmlAttach.AttachTo(item, new TMapDecoderXmlAtt());
                this.Uses--;
                this.InvalidateProperties();
Now i wish to use atachment from the XML atachments resource,example (XML weapon attribute):
C#:
using System;
using Server;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using System.Reflection;

namespace Server.Engines.XmlSpawner2
{
    public class XmlWeaponAbility : XmlAttachment
    {
        private WeaponAbility m_Ability = null;    // default data

        public WeaponAbility WeaponAbility
        {
            get { return m_Ability;  }
            set { m_Ability = value;  }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public string Ability
        {
            get
            {
                if (m_Ability != null)
                {
                    return m_Ability.GetType().Name;
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (value != null)
                {
                    FieldInfo finfo = typeof(WeaponAbility).GetField(value);
                    if (finfo != null && finfo.IsStatic && finfo.FieldType == typeof(WeaponAbility))
                    {
                        try
                        {
                            m_Ability = (WeaponAbility)finfo.GetValue(null);
                        }
                        catch { }
                    }
                }
                else
                {
                    m_Ability = null;
                }
            }
        }


        // These are the various ways in which the message attachment can be constructed.
        // These can be called via the [addatt interface, via scripts, via the spawner ATTACH keyword.
        // Other overloads could be defined to handle other types of arguments
     
        // a serial constructor is REQUIRED
        public XmlWeaponAbility(ASerial serial) : base(serial)
        {
        }

        [Attachable]
        public XmlWeaponAbility(string weaponability)
        {
            Ability = weaponability;
        }

        [Attachable]
        public XmlWeaponAbility(string name, string weaponability)
        {
            Name = name;
            Ability = weaponability;
        }

        [Attachable]
        public XmlWeaponAbility(string name, string weaponability, double expiresin)
        {
            Name = name;
            Ability = weaponability;
            Expiration = TimeSpan.FromMinutes(expiresin); //

        }

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

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

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

            int version = reader.ReadInt();
            // version 0
            Ability = reader.ReadString();
        }

        public override string OnIdentify(Mobile from)
        {
            if(from == null || from.AccessLevel == AccessLevel.Player) return null;

            if(Expiration > TimeSpan.Zero)
            {
                return String.Format("{2}: Weapon ability {0} expires in {1} mins", Ability, Expiration.TotalMinutes, Name);
            }
            else
            {
                return String.Format("{1}: Weapon ability {0}", Ability, Name);
            }
        }
    }
}
Can anyone write here the way to add atachment to an item when target it from a deed?Thank you!
Hey Lem, can you tell me what you are aiming to accomplish? What is your goal? Besides adding an attachment via a deed...is there a reason you want to do this? It is possible there could be easier ways to do it, unless it [has to be a deed].

Really the only thing you need to focus on is the OnTarget method for the deed, as that is where you look for the Attachment and Add it if it does not exist. I used this for a weapon enhancement system:
C#:
protected override void OnTarget(Mobile from, object target)
{
    if (m_Deed.Deleted || m_Deed.RootParent != from)
    {
        from.SendMessage("You cannot enhance that with this deed.");
        return;
    }

    if (target is Saber)
    {
        saber item = (Saber)target;

        if (item is Saber)
        {
            if (((Saber)item).WeaponAttributes.HitFireball >= 50 && ((Saber)item).WeaponAttributes.ResistFireBonus >= 70 || ((Saber)item).TimesEmpowered > 1)
            {
                from.SendMessage("That Saber has already been ehanced.");
            }
            else
            {
                ((Saber)item).WeaponAttributes.HitFireball += Utility.RandomMinMax(25, 50);
                ((Saber)item).WeaponAttributes.ResistFireBonus += Utility.RandomMinMax(50, 70);

                if (((Saber)item).TimesEmpowered == 1)
                {
                    XmlAttach.AttachTo( item, new TMapDecoderXmlAtt() ) //<-- Attachment is added.
                    ((Saber)item).TimesEmpowered += 2;
                    from.SendMessage("Your Saber has now been fully enhanced.");
                    return;
                }
                else
                {
                    XmlAttach.AttachTo( item, new TMapDecoderXmlAtt() ) //<-- Attachment is added.
                    ((Saber)item).TimesEmpowered +=1;
                    from.SendMessage("Your Saber can only be enhanced with one more deed.");
                }
                from.SendMessage("This deed has enhanced your Saber.");
                m_Deed.Delete();
            }
        }
    }
    else
    {
        from.SendMessage("You cannot enhance that.");
    }
}
In the center, you can see an If/Else section, which adds the attachment if it is not present and has not exceeded the maximum number of enhancements. Otherwise the attachment is not added.
Feel free to PM me if you would like more detailed support. ;)
 
Sorry bad reply lol.
Im asking about the core xmlspawner core examples of attachments.There are tons of them.Sin título.png
In the case i want to add a weapon ability temporary attach,whats the code to add?
Here the core constructor:

C#:
public XmlWeaponAbility(string name, string weaponability, double expiresin)
        {
            Name = name;
            Ability = weaponability;
            Expiration = TimeSpan.FromMinutes(expiresin);

        }
 
Sorry bad reply lol.
Im asking about the core xmlspawner core examples of attachments.There are tons of them.View attachment 19401
In the case i want to add a weapon ability temporary attach,whats the code to add?
Here the core constructor:

C#:
public XmlWeaponAbility(string name, string weaponability, double expiresin)
        {
            Name = name;
            Ability = weaponability;
            Expiration = TimeSpan.FromMinutes(expiresin);

        }
No worries ;)
But in that case, it is like this:

XmlAttach.AttachTo( this, new XmlWeaponAbility( "Cat Scratch Fever", "BleedAttack", 10 ) );

//this (the Item), newXmlWeaponAbility (AttachmentType)("string Name" ("Cat Scratch Fever"), "string WeaponAbilityName" ("BleedAttack"), Integer (double) minutes) The WeaponAbilityName needs to match the WeaponAbility you are wanting to add.
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back