ZeroLife

Initiate
Hi, I have been trying to make craftable level items for my shard using the level items feature built into XMLspawner2. I have been able to do it by creating a custom duplicate of each item and then adding those to my crafting gump. For example, this is my LevelAxe.cs. Its the same as the base Axe.cs with the addition of the XmlAttach line:

Code:
using System;
using System.Collections.Generic;
using Server.Engines.Craft;
using Server.Engines.XmlSpawner2;

namespace Server.Items
{
    [FlipableAttribute(0xF49, 0xF4a)]
    public class LevelAxe : BaseAxe
    {
        [Constructable]
        public LevelAxe()
            : base(0xF49)
        {
            this.Weight = 4.0;
			XmlAttach.AttachTo(this, new XmlLevelItem());
			Name = "Level Axe";
        }

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

        public override WeaponAbility PrimaryAbility
        {
            get
            {
                return WeaponAbility.CrushingBlow;
            }
        }
        public override WeaponAbility SecondaryAbility
        {
            get
            {
                return WeaponAbility.Dismount;
            }
        }
        public override int AosStrengthReq
        {
            get
            {
                return 35;
            }
        }
        public override int AosMinDamage
        {
            get
            {
                return 14;
            }
        }
        public override int AosMaxDamage
        {
            get
            {
                return 17;
            }
        }
        public override int AosSpeed
        {
            get
            {
                return 37;
            }
        }
        public override float MlSpeed
        {
            get
            {
                return 3.00f;
            }
        }
        public override int OldStrengthReq
        {
            get
            {
                return 35;
            }
        }
        public override int OldMinDamage
        {
            get
            {
                return 6;
            }
        }
        public override int OldMaxDamage
        {
            get
            {
                return 33;
            }
        }
        public override int OldSpeed
        {
            get
            {
                return 37;
            }
        }
        public override int InitMinHits
        {
            get
            {
                return 31;
            }
        }
        public override int InitMaxHits
        {
            get
            {
                return 110;
            }
        }
        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();
        }
    }
}

My question is, is there an easier way to do this? I am a noob to c# but I am trying my best to use these scripts to customize my shard.
 
I'm not sure to understand well what you want to do, but what about adding your XMLAttach directly in the BaseWeapon constructor, then all your weapons will have one...

Another way, you got for example in BaseWeapon, at the bottom of the file, the OnCraft method, in wich you can make a test, and add or not your xmlattach.
 
What I am trying to do is add the ability for players to craft levelable items, while still being able to craft non- level items as well.
 
You could still have craftable non-level items if you edit BaseWeapon like Gargouille suggested. To determine if a weapon is level or non-level you could add an overridable bool variable on BaseWeapon that is defaulted to false. Put a check on that variable wherever you plan to add the xml attachment. Then in the specific weapon scripts that you want to have leveling, override your bool variable and set it to true. Make sense?
 
Oh, and to make new weapon scripts craftable by players, you could edit the blacksmithy definitions in the file DefBlacksmithy.cs in a few places. Around line 258 or so you should see regions of items being added to crafting with the function AddCraft. To add a custom item I think it goes something like this:
Code:
AddCraft(typeof(LevelAxe), 1011082, "Level Axe", 45.0, 73.3, typeof(IronIngot), 1044036, 15);
If you look at the code for the AddCraft function you can figure out what each argument is used for.
 
Okay I kind of get it. I would write a method of BaseWeapon to determine whether or not to attach the XML. Say if I created the method called MakeLevel, I could implement that into the AddCraft method in DefBlacksmithy? Would I just add the ObectType as typeof(Axe.MakeLevel)? Sorry I am still pretty noob to C# syntax. I am learning this as I go.
 
You should probably stick to adding the xml attachment in BaseWeapon somewhere, probably in constructor method of BaseWeapon. Make sure you use an if statement checking your bool variable before adding the xml attachment. The constructor method will be called upon every time any weapon is created, crafted or not. You will still need to create new weapon scripts for your levelable items, and in those scripts override your bool to true. Or you could edit existing item scripts and override your bool variable to true for them as well.
 
Adding an override in each script/class inheriting from BaseWeapon should be a lot of work, I think you should consider to avoid that and place all your new stuff in BaseWeapon.

Of course it really depends on the way you need Levels to be attribute : if you want for example a dagguer to have Level1, then you will need to edit Dagguer, but if you want for example a level for every weapontype regarding to the crafter skill, then edit the OnCraft method, no use to add new types ini the craftDefs...

Add for example something like :
Code:
private int m_Level;
		public int Level
		{
			get { this.PlayerConstructed?m_Level:0; }
			set { m_Level = value;}
		}

And then in OnCraft something like :
Code:
if(from.Skills[SkillName.BlackSmithy].Value>50)
m_Level = 1;
 
Sorry to awaken an old thread. I'm looking to make it possible to have every weapon/armor in game have the level attach on it already, i read above that this could be done but I'm not sure how to do it. In the base weapon / armor scripts, what would I add to allow every weapon and armor , crafted or not have the level attribute on it?
 
Hello everyone, how to make it so that when crafting weapons marked with marks, it becomes leveled? Or how to make a leveled weapon scroll. That is, if you have an ordinary weapon with a scroll, you can turn it into a leveled one.
 

Attachments

  • BaseWeapon.cs
    151.6 KB · Views: 3

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back