Iomega0318

Member
Lets take sockets for example, when you spawn an item in the world the XML Socket is attached or you can attach it with a socket hammer, etc. Is there a way to hard code that XML attachment in the script so when I spawn the item in the world it is always the same?

So for example, I spawn a special shield in the game I don't want to randomly attach the socket XML as it is random, I always want to attach 5 sockets.

Hope that makes sense, let me know if you need more explanation.

1665192366731.png
 
Not 100% on specifics and not at the PC at the moment, but it would be something along the lines of this;

XmlAttach:
XmlSocketable sock = (XmlSocketable)XmlAttach.FindAttachment(item, typeof (XmlSocketable));

if (sock == null)
{
    XmlAttach.AttachTo(item, new XmlSocketable());
}

if (sock != null)
{
    sock.MaxSockets = 1;
    sock.ResourceQuantity = 75;
    //etc.
}

It would be something like that though might be a bit different for XmlSocketable, not sure since I've never messed with Sockets.

**Edit**
When in doubt, Ctrl+Shift+F in Visual Studio is your friend and in this case so is the XmlSpawner Extras files from previous releases. The examples would at least give you a rough idea of how to go about various ways of using XmlSpawners both in-game and through code.
 
Would that just go in like this?
C#:
        [Constructable]
        public PlateShield()
        {
            Hue = 2498;

            ArmorAttributes.SelfRepair = 10;

            XmlSocketable sock = (XmlSocketable)XmlAttach.FindAttachment(PlateShield, typeof(XmlSocketable));

            if (sock == null)
            {
                XmlAttach.AttachTo(PlateShield, new XmlSocketable());
            }

            if (sock != null)
            {
                sock.MaxSockets = 5;
                sock.ResourceQuantity = 75;
                //etc.
            }

        }
Because with that I get this:
C#:
'PlateShield' is a type, which is not valid in the given context'

Not entirely sure where to place that code haha

Also nice I didn't know VS had a search in files feature.
 
Yes, you should be able to place it in the Constructable, however instead of calling PlateShield you would want to use the keyword this since, as the error states, PlateShield is a general type rather than the specific item you're attaching to.
 
Yes, you should be able to place it in the Constructable, however instead of calling PlateShield you would want to use the keyword this since, as the error states, PlateShield is a general type rather than the specific item you're attaching to.
doh!

Hmm, it did compile and semi-work, it applied a MaxSockets of 0 though instead of 5.
 
Not sure if this will work, but try placing it inside of where it's the code that adds the attachment, something like;

In the Attachment:
XmlAttach.AttachTo(PlateShield, new XmlSocketable()
{
    MaxSockets = 1, ResourceQuantity = 75
});

**Edit**
Or you may need to add it inside of the () like XmlSockletable(MaxSockets 5, ResourceQuantity 75). Although this is most likely the wrong way of wording it even if it does belong in (). I'm honestly not sure since I've never messed with setting XmlAttachment properties through code that didn't come predefined and meant to stay the same.
 
Last edited:
C#:
Oct 8, 2022
Add bookmark
#3
Would that just go in like this?
C#:
        [Constructable]
        public PlateShield()
        {
            Hue = 2498;

            ArmorAttributes.SelfRepair = 10;

            XmlSocketable sock = (XmlSocketable)XmlAttach.FindAttachment(this, typeof(XmlSocketable));

            if (sock == null)
            {
                XmlAttach.AttachTo(this, new XmlSocketable());
            }

            if (sock != null)
            {
                sock.MaxSockets = 5;
                sock.ResourceQuantity = 75;
                //etc.
            }

        }
 
Yes that's how I put it into mine.

Next one I'm trying to do is set the required level for the equipment but I can't figure out how to set that value manually.. any help with that would be greatly appreciated, here is the Level Script for reference.
 

Attachments

  • LevelEquipXMLDynamic.cs
    51.3 KB · Views: 4
So I seem to be able to set the value using the following, but in game it shows both being required the level I set AND the level dynamically set..
so confused here haha..
1669438708743.png
C#:
using System;
using Server;
using Server.Engines.XmlSpawner2;
using Server.Mobiles;

namespace Server.Items
{
    public class NewbieArms : LeatherArms
    {
        private int m_RequiredLevel = 1;
        [CommandProperty(AccessLevel.GameMaster)]
        public int RequiredLevel
        {
            get { return m_RequiredLevel; }
            set { m_RequiredLevel = value; }
        }

        [Constructable]
        public NewbieArms()
        {
            Name = "Newbie Arms";
            Hue = 1910;
            LootType = LootType.Newbied;
            Attributes.AttackChance = 5;
            Attributes.BonusMana = 5;
            Attributes.BonusStam = 5;
            Attributes.BonusHits = 5;
            Attributes.Luck = 50;
            Attributes.WeaponDamage = 5;
            Attributes.SpellDamage = 5;
            Attributes.LowerRegCost = 10;
            MaxHitPoints = 200;
            HitPoints = 200;
            PhysicalBonus = 5;
            FireBonus = 5;
            ColdBonus = 5;
            PoisonBonus = 5;
            EnergyBonus = 5;
        }

        public override bool OnEquip(Mobile from)
        {
            XMLPlayerLevelAtt weap1 = (XMLPlayerLevelAtt)XmlAttach.FindAttachment(from, typeof(XMLPlayerLevelAtt));
            if (weap1 != null && weap1.Levell >= RequiredLevel && from is PlayerMobile)
            {
                return true;
            }
            else
            {
                if (from is PlayerMobile)
                {
                    from.SendMessage("You do not meet the level requirement for this Armor.");
                    return false;
                }
            }
            return true;
        }

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

            list.Add("<BASEFONT COLOR=#7FCAE7>Required Level: <BASEFONT COLOR=#7FCAE7>{0}<BASEFONT COLOR=#FFFFFF>", m_RequiredLevel);
        }

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

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write((int)m_RequiredLevel);
            writer.Write( (int) 0 );
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize( reader );
            m_RequiredLevel = reader.ReadInt();
            int version = reader.ReadInt();
        }

    }
}
 
So I seem to be able to set the value using the following, but in game it shows both being required the level I set AND the level dynamically set..
so confused here haha..
View attachment 20849
C#:
using System;
using Server;
using Server.Engines.XmlSpawner2;
using Server.Mobiles;

namespace Server.Items
{
    public class NewbieArms : LeatherArms
    {
        private int m_RequiredLevel = 1;
        [CommandProperty(AccessLevel.GameMaster)]
        public int RequiredLevel
        {
            get { return m_RequiredLevel; }
            set { m_RequiredLevel = value; }
        }

        [Constructable]
        public NewbieArms()
        {
            Name = "Newbie Arms";
            Hue = 1910;
            LootType = LootType.Newbied;
            Attributes.AttackChance = 5;
            Attributes.BonusMana = 5;
            Attributes.BonusStam = 5;
            Attributes.BonusHits = 5;
            Attributes.Luck = 50;
            Attributes.WeaponDamage = 5;
            Attributes.SpellDamage = 5;
            Attributes.LowerRegCost = 10;
            MaxHitPoints = 200;
            HitPoints = 200;
            PhysicalBonus = 5;
            FireBonus = 5;
            ColdBonus = 5;
            PoisonBonus = 5;
            EnergyBonus = 5;
        }

        public override bool OnEquip(Mobile from)
        {
            XMLPlayerLevelAtt weap1 = (XMLPlayerLevelAtt)XmlAttach.FindAttachment(from, typeof(XMLPlayerLevelAtt));
            if (weap1 != null && weap1.Levell >= RequiredLevel && from is PlayerMobile)
            {
                return true;
            }
            else
            {
                if (from is PlayerMobile)
                {
                    from.SendMessage("You do not meet the level requirement for this Armor.");
                    return false;
                }
            }
            return true;
        }

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

            list.Add("<BASEFONT COLOR=#7FCAE7>Required Level: <BASEFONT COLOR=#7FCAE7>{0}<BASEFONT COLOR=#FFFFFF>", m_RequiredLevel);
        }

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

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write((int)m_RequiredLevel);
            writer.Write( (int) 0 );
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize( reader );
            m_RequiredLevel = reader.ReadInt();
            int version = reader.ReadInt();
        }

    }
}
I'm going to guess you have m_RequiredLevel in BaseArmor.cs GetProperties
Just remove it from this script in particular and that should resolve the issue
 
I'm going to guess you have m_RequiredLevel in BaseArmor.cs GetProperties
Just remove it from this script in particular and that should resolve the issue
Dumb it down for me a little Zero.. I pulled the changes for this script from the examples in the Level System.
Also the goal is to force it to require level 1, but level 5 is being set by the dynamic xml attachment.

I've also tried the following but haven't been able to figure it out:
C#:
            XmlAttach.AttachTo(this, new LevelEquipXMLDynamic()
            {
                //ArmorRequiredLevel1
            });

**EDIT**
Well not exactly how I wanted to solve it but I was able to go into the dynamic xml attachment script where it gets applied and just added a list of items to exclude from the attachment being added to.
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back