This part of my code compiles and works ok, it combines both scrolls etc. problem is it doesn't delete the targeted scroll. So you end up with combined scroll and original. This is my version of a Level up scroll. How would I write this to delete the targeted scroll in my pack?

Here is the section of code...

if (target is LevelUpScroll)
{
LevelUpScroll c = (LevelUpScroll)target;
from.SendMessage("You combine both Scrolls to create a new one");
c = new LevelUpScroll(m_Scroll.Value + m_Scroll.Value);
from.AddToBackpack(c);
m_Scroll.Delete(); (This is the line of code that is wrong)
}
else
{
from.SendMessage("Invalid Target Type. Levelable Weapons, Armor, and Clothing only!");
 
Assuming your targeting code is on the original levelup scroll...

Change to
Code:
this.Delete();
 
That won't compile Lokai, tried it... TY for an answer tho. Here is the entire script so you can see why, and maybe how to fix my problem...

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Mobiles;
using Server.Misc;
using Server.Items;
using Server.Gumps;
using Server.Targeting;
using Server.Targets;
namespace Server.Items
{
    public class LevelUpScroll : Item
    {
        private int m_Value;
        [CommandProperty(AccessLevel.GameMaster)]
        public int Value
        {
            get
            {
                return m_Value;
            }
        }
      
        [Constructable]
        public LevelUpScroll(int value) : base(0x14F0)
        {
            Weight = 1.0;
            Name = "Item Level Deed";
            Hue = 0x64;
            LootType = LootType.Cursed;
            m_Value = value;
        }
      
        public override void AddNameProperty(ObjectPropertyList list)
        {
            list.Add("an Item Level Deed (+{0} max levels)", m_Value);
        }
      
        public override void OnSingleClick(Mobile from)
        {
            base.LabelTo(from, "an Item Level Deed (+{0} max levels)", m_Value);
        }

        public LevelUpScroll(Serial serial) : base(serial)
        {
        }
      
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0); // version
            //Version 0
            writer.Write((int)m_Value);
        }
      
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
            switch (version)
            {
                case 0:
                {
                    m_Value = reader.ReadInt();
                    break;
                }
            }
        }
      
        public override void OnDoubleClick(Mobile from)
        {
            if (!IsChildOf(from.Backpack))
            {
                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
                return;
            }
            else
            {
                from.SendMessage("Which item would you like to level up?");
                from.Target = new LevelItemTarget(this); // Call our target
            }
        }
    }
  
    public class LevelItemTarget : Target
    {
        private LevelUpScroll m_Scroll;
        public LevelItemTarget(LevelUpScroll scroll) : base(-1, false, TargetFlags.None)
        {
            this.m_Scroll = scroll;
        }
      
        protected override void OnTarget(Mobile from, object target)
        {
            if (target is Mobile)
            {
                from.SendMessage("This deed cannot be applied to that!");
            }
            else if (target is Item)
            {
                Item item = (Item)target;
                if (item.RootParent != from || !item.IsChildOf(from.Backpack)) // Make sure its in their pack or they are wearing it
                {
                    from.SendMessage("The item must be in your pack to level it up.");
                }
                else
                {
                    if (target is ILevelable)
                    {
                        ILevelable b = (ILevelable)target;
                        if ((b.MaxLevel + m_Scroll.Value) > LevelItems.MaxLevelsCap)
                        {
                            from.SendMessage("The level on this item is already too high to use this deed!");
                        }
                        else
                        {
                            b.MaxLevel += m_Scroll.Value;
                            from.SendMessage("Your item has leveled up by " + m_Scroll.Value + " levels.");
                            m_Scroll.Delete();
                        }
                    }
                    if (target is LevelUpScroll)
                    {
                        LevelUpScroll c = (LevelUpScroll)target;
                        c = new LevelUpScroll(m_Scroll.Value + m_Scroll.Value);
                        from.SendMessage("You combine both Scrolls to create a new one");
                        from.AddToBackpack(c);
                        this.Delete();
                    }
                    else
                    {
                        from.SendMessage("Invalid Target Type.  Levelable Weapons, Armor, and Clothing only!");
                    }
                }
            }
        }
    }
}
 
Last edited by a moderator:
use codebox for posting code.

Code:
if (target is LevelUpScroll)
{
LevelUpScroll c = (LevelUpScroll)target;
from.SendMessage("You combine both Scrolls to create a new one");
from.AddToBackpack( new LevelUpScroll(m_Scroll.Value + m_Scroll.Value));
c.Delete();
}
 
I edited your code for proper formatting, since there are quite a few if/else statements, and several nested ones. If you use the code button (which looks like a plus sign in the menu above) it will allow the code to preserve the tab characters created by your code writing program.

Now that I see the code, I still have a question about it, since I do not see what an "ILevelable" is, but there is also an issue around line 122. You go from one if to another, meaning it can potentially run BOTH sections, which I am not sure you intended.

First, let's see the code that defines an "ILevelable" and we can go from there.
 
Here is the other script you asked for Lokai... This is Ilevelable.cs

Code:
using System;

namespace Server.Items
{
    /// <summary>
    /// Summary description for ILevelable.
    /// </summary>
    public interface ILevelable
    {
        int Experience{ get; set; }
        int Level{ get; set; }
        int Points{ get; set; }
        int MaxLevel { get; set; }
    }
}
 
OK. I looked closer and found that you were adding a new scroll, but only deleting one. So you start with 2, add one, delete one, and end up with 2. Here is how I would write this:

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Mobiles;
using Server.Misc;
using Server.Items;
using Server.Gumps;
using Server.Targeting;
using Server.Targets;
namespace Server.Items
{
    public class LevelUpScroll : Item
    {
        private int m_Value;
        [CommandProperty(AccessLevel.GameMaster)]
        public int Value
        {
            get
            {
                return m_Value;
            }
        }
       
        [Constructable]
        public LevelUpScroll(int value) : base(0x14F0)
        {
            Weight = 1.0;
            Name = "Item Level Deed";
            Hue = 0x64;
            LootType = LootType.Cursed;
            m_Value = value;
        }
       
        public override void AddNameProperty(ObjectPropertyList list)
        {
            list.Add("an Item Level Deed (+{0} max levels)", m_Value);
        }
       
        public override void OnSingleClick(Mobile from)
        {
            base.LabelTo(from, "an Item Level Deed (+{0} max levels)", m_Value);
        }

        public LevelUpScroll(Serial serial) : base(serial)
        {
        }
       
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0); // version
            //Version 0
            writer.Write((int)m_Value);
        }
       
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
            switch (version)
            {
                case 0:
                {
                    m_Value = reader.ReadInt();
                    break;
                }
            }
        }
       
        public override void OnDoubleClick(Mobile from)
        {
            if (!IsChildOf(from.Backpack))
            {
                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
                return;
            }
            else
            {
                from.SendMessage("Which item would you like to level up?");
                from.Target = new LevelItemTarget(this); // Call our target
            }
        }
    }
   
    public class LevelItemTarget : Target
    {
        private LevelUpScroll m_Scroll;
        public LevelItemTarget(LevelUpScroll scroll) : base(-1, false, TargetFlags.None)
        {
            this.m_Scroll = scroll;
        }
       
        protected override void OnTarget(Mobile from, object target)
        {
            if (target is Mobile)
            {
                from.SendMessage("This deed cannot be applied to that!");
            }
            else if (target is Item)
            {
                Item item = (Item)target;
                if (item.RootParent != from || !item.IsChildOf(from.Backpack)) // Make sure its in their pack or they are wearing it
                {
                    from.SendMessage("The item must be in your pack to level it up.");
                }
                else
                {
                    if (item is ILevelable)
                    {
                        ILevelable b = (ILevelable)item;
                        if ((b.MaxLevel + m_Scroll.Value) > LevelItems.MaxLevelsCap)
                        {
                            from.SendMessage("The level on this item is already too high to use this deed!");
                        }
                        else
                        {
                            b.MaxLevel += m_Scroll.Value;
                            from.SendMessage("Your item has leveled up by " + m_Scroll.Value + " levels.");
                            m_Scroll.Delete();
                        }
                    }
                    else if (item is LevelUpScroll)
                    {
                        LevelUpScroll targetScroll = (LevelUpScroll)item;
                        m_Scroll.Value += targetScroll.Value;
                        from.SendMessage("You combine both Scrolls into one");
                        m_Scroll.Delete();
                    }
                    else
                    {
                        from.SendMessage("Invalid Target. Use on a levelable Item, or on another LevelUp scroll to combine them.");
                    }
                }
            }
            else
                from.SendMessage("This deed cannot be applied to that!");
        }
    }
}

Obviously this is the key section:

Code:
                    else if (item is LevelUpScroll)
                    {
                        LevelUpScroll targetScroll = (LevelUpScroll)item;
                        m_Scroll.Value += targetScroll.Value;
                        from.SendMessage("You combine both Scrolls into one");
                        m_Scroll.Delete();
                    }

As you can see, we do not create a new scroll, but simply add the source scroll's value (m_Scroll) to the target Scroll, then delete the source.
 
Obviously this is the key section:

As you can see, we do not create a new scroll, but simply add the source scroll's value (m_Scroll) to the target Scroll, then delete the source.
You made a mistake, the target scroll will not change, and the changed original will be deleted.
 
Ah, you are correct. Change this line:

Code:
m_Scroll.Value += targetScroll.Value;

to this:

Code:
targetScroll.Value += m_Scroll.Value;

Sorry, I am not testing this, just writing on the fly.
 
Umm that line you just posted wont compile
targetScroll.Value+= m_Scroll.Value;

Here is the compiler error...

Errors:
+Items/Weapons/LevelUpscroll.cs
CS0200: Line 125: Property or indexer 'Server.Items.LevelUpScroll.Value' cannot be assigned to -- it is read only
 
you need add settings property:
Code:
 private int m_Value;
        [CommandProperty(AccessLevel.GameMaster)]
        public int Value
        {
            get
            {
                return m_Value;
            }
set
{
m_Value = value;
}
        }
 
Isn't this already at the top of the script? Or add it again in the target method?
A little confused now...
 
What he means is the Value parameter needs a "Set" method.

Add this part:

Code:
set
{
     m_Value = value;
}
 
Got it ty guys.... Ty so much for your patience Lokai and you too juzzver for your input. Been awhile for me on the scripting lol.
 
Back