Iomega0318

Member
ServUO Version
Publish 57
Ultima Expansion
Endless Journey
Trying to make a bag where only certain items can be dropped into it, in this example some unbreakable tools, however using the following code pulled from another bag that does something similar I receive the following error:
C#:
Errors:
 + Custom/Custom Items/Everlasting Items/EverlastingBagOfTools.cs:
    CS0119: Line 40: 'BaseEverlastingTool' is a type, which is not valid in the given context
Scripts: One or more scripts failed to compile or no script files were found.
Code:
C#:
        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (!(dropped is BaseEverlastingTool))
            {
                from.SendMessage("Only Everlasting items can be placed in this bag.");
                return false;
            }

            return base.OnDragDrop(from, dropped);
        }

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {
            if (!(dropped is BaseEverlastingTool))
            {
                from.SendMessage("Only Everlasting items can be placed in this bag.");
                return false;
            }
            return base.OnDragDropInto(from, item, p);
        }
As usual I'm sure the answer is simple for you coders out there, but any help would be appreciated :)

The items themselves are based off the BaseEverlastingTool which in turn is based off of BaseTool
 
Last edited:
Nope still comes up as "'BaseEverlastingHarvestTool' is a type, which is not valid in the given context"
 
C#:
public override bool OnDragDropInto(Mobile from, Item dropped, Point3D p)
        {
            BaseEverlastingHarvestTool beh = dropped as BaseEverlastingHarvestTool;

            if (beh != null && base.OnDragDropInto(from, dropped, p))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

Try this
 
Are you sure that the error is related to that piece of code?

The error refers to "'BaseEverlastingTool'" and not "BaseEverlastingHarvestTool", and "BaseEverlastingTool" is not even present at all in that piece of code.
 
Are you sure that the error is related to that piece of code?

The error refers to "'BaseEverlastingTool'" and not "BaseEverlastingHarvestTool", and "BaseEverlastingTool" is not even present at all in that piece of code.
You're right. I didn't notice the wrong keywords

Trying to make a bag where only certain items can be dropped into it, in this example some unbreakable tools, however using the following code pulled from another bag that does something similar I receive the following error:
C#:
Errors:
 + Custom/Custom Items/Everlasting Items/EverlastingBagOfTools.cs:
    CS0119: Line 40: 'BaseEverlastingTool' is a type, which is not valid in the given context
Scripts: One or more scripts failed to compile or no script files were found.
Code:
C#:
        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (!(dropped is BaseEverlastingHarvestTool))
            {
                from.SendMessage("Only Everlasting items can be placed in this bag.");
                return false;
            }

            return base.OnDragDrop(from, dropped);
        }

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {
            if (!(dropped is BaseEverlastingHarvestTool))
            {
                from.SendMessage("Only Everlasting items can be placed in this bag.");
                return false;
            }
            return base.OnDragDropInto(from, item, p);
        }
As usual I'm sure the answer is simple for you coders out there, but any help would be appreciated :)

The items themselves are based off the BaseEverlastingTool which in turn is based off of BaseTool
Can you upload your EverlastingBagOfTools.cs?
 
The goal is to have the following list associated with the bag:
BaseEverlastingHarvestTool
BaseEverlastingTool
EverlastingArrow
EverlastingBolt
EverlastingBandage

Here is the bag itself.
C#:
using System;
using Server;
using Server.Items;

namespace Server.Items
{
    public class EverlastingBagOfTools : Bag
    {
        public override int Hue { get { return 1153; } }

        [Constructable]
        public EverlastingBagOfTools() : this(1)
        {
            Movable = true;
            LootType = LootType.Blessed;
            Name = "A bag of Everlasting Tools";
        }

        [Constructable]
        public EverlastingBagOfTools(int amount)
        {
            DropItem(new EverlastingFletcherTools());
            DropItem(new EverlastingGargoylesAxe());
            DropItem(new EverlastingGargoylesPickaxe());
            DropItem(new EverlastingGargoylesKnife());
            DropItem(new EverlastingMalletAndChisel());
            DropItem(new EverlastingMapmakersPen());
            DropItem(new EverlastingMortarPestle());
            DropItem(new EverlastingSaw());
            DropItem(new EverlastingScribesPen());
            DropItem(new EverlastingSewingKit());
            DropItem(new EverlastingShovel());
            DropItem(new EverlastingSkillet());
            DropItem(new EverlastingBlacksmithHammer());
            DropItem(new EverlastingTinkerTools());
        }

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

        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();
        }
    }
}
 
Just minor changes,

the code you posted last is stripped, since nothing in line 40 would cause the error you had befor.

So added your drop functions back, reduced redundancy, and remove the issue that if you would have used
[add EverlastingBagOfTools 20

the it wouldnt have been blessed.
I kept the Movable = true, but tbh not sure why you added that in the first place, a bag is always movable by default.
Also the amount paramenter for the Toolbag has no effect. What did you plan to do with that?

C#:
using System;
using Server;

namespace Server.Items
{
    public class EverlastingBagOfTools : Bag
    {
        public override int Hue { get { return 1153; } }
        public override string DefaultName { get { return "A bag of Everlasting Tools"; } }

        [Constructable]
        public EverlastingBagOfTools() : this(1)
        { }

        [Constructable]
        public EverlastingBagOfTools(int amount)
        {
            Movable = true;
            LootType = LootType.Blessed;

            DropItem(new EverlastingFletcherTools());
            DropItem(new EverlastingGargoylesAxe());
            DropItem(new EverlastingGargoylesPickaxe());
            DropItem(new EverlastingGargoylesKnife());
            DropItem(new EverlastingMalletAndChisel());
            DropItem(new EverlastingMapmakersPen());
            DropItem(new EverlastingMortarPestle());
            DropItem(new EverlastingSaw());
            DropItem(new EverlastingScribesPen());
            DropItem(new EverlastingSewingKit());
            DropItem(new EverlastingShovel());
            DropItem(new EverlastingSkillet());
            DropItem(new EverlastingBlacksmithHammer());
            DropItem(new EverlastingTinkerTools());
        }

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

        private bool DropCheckEverlastingTool(Mobile from, Item item)
        {
            if (item is BaseEverlastingTool)
                return true;

            from.SendMessage("Only Everlasting items can be placed in this bag.");
            return false;
        }

        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (!DropCheckEverlastingTool(from, dropped))
                return false;

            return base.OnDragDrop(from, dropped);
        }

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {
            if (!DropCheckEverlastingTool(from, item))
                return false;

            return base.OnDragDropInto(from, item, p);
        }

        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();
        }
    }
}
 
I recommend you use universal storage keys

 
Yes I have universal storage keys, but these items have no uses hence the everlasting.
Just minor changes,

the code you posted last is stripped, since nothing in line 40 would cause the error you had befor.

So added your drop functions back, reduced redundancy, and remove the issue that if you would have used
[add EverlastingBagOfTools 20

the it wouldnt have been blessed.
I kept the Movable = true, but tbh not sure why you added that in the first place, a bag is always movable by default.
Also the amount paramenter for the Toolbag has no effect. What did you plan to do with that?

C#:
using System;
using Server;

namespace Server.Items
{
    public class EverlastingBagOfTools : Bag
    {
        public override int Hue { get { return 1153; } }
        public override string DefaultName { get { return "A bag of Everlasting Tools"; } }

        [Constructable]
        public EverlastingBagOfTools() : this(1)
        { }

        [Constructable]
        public EverlastingBagOfTools(int amount)
        {
            Movable = true;
            LootType = LootType.Blessed;

            DropItem(new EverlastingFletcherTools());
            DropItem(new EverlastingGargoylesAxe());
            DropItem(new EverlastingGargoylesPickaxe());
            DropItem(new EverlastingGargoylesKnife());
            DropItem(new EverlastingMalletAndChisel());
            DropItem(new EverlastingMapmakersPen());
            DropItem(new EverlastingMortarPestle());
            DropItem(new EverlastingSaw());
            DropItem(new EverlastingScribesPen());
            DropItem(new EverlastingSewingKit());
            DropItem(new EverlastingShovel());
            DropItem(new EverlastingSkillet());
            DropItem(new EverlastingBlacksmithHammer());
            DropItem(new EverlastingTinkerTools());
        }

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

        private bool DropCheckEverlastingTool(Mobile from, Item item)
        {
            if (item is BaseEverlastingTool)
                return true;

            from.SendMessage("Only Everlasting items can be placed in this bag.");
            return false;
        }

        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (!DropCheckEverlastingTool(from, dropped))
                return false;

            return base.OnDragDrop(from, dropped);
        }

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {
            if (!DropCheckEverlastingTool(from, item))
                return false;

            return base.OnDragDropInto(from, item, p);
        }

        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();
        }
    }
}
TBH I copied that bag from another script and just changed the items dropped into it, so no idea why it was setup that way. And yeah I just posted the base bag without the edits posted in the first post. I took what you made and changed it just a little to remove the unneeded bits and add the rest of the items in the list, but other than that works great, thank you!

C#:
using System;
using Server;

namespace Server.Items
{
    public class EverlastingBagOfTools : Bag
    {
        public override int Hue { get { return 1153; } }
        public override string DefaultName { get { return "A bag of Everlasting Tools"; } }

        [Constructable]
        public EverlastingBagOfTools()
        {
            LootType = LootType.Blessed;

            DropItem(new EverlastingFletcherTools());
            DropItem(new EverlastingGargoylesAxe());
            DropItem(new EverlastingGargoylesPickaxe());
            DropItem(new EverlastingGargoylesKnife());
            DropItem(new EverlastingMalletAndChisel());
            DropItem(new EverlastingMapmakersPen());
            DropItem(new EverlastingMortarPestle());
            DropItem(new EverlastingSaw());
            DropItem(new EverlastingScribesPen());
            DropItem(new EverlastingSewingKit());
            DropItem(new EverlastingShovel());
            DropItem(new EverlastingSkillet());
            DropItem(new EverlastingBlacksmithHammer());
            DropItem(new EverlastingTinkerTools());
        }

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

        private bool DropCheckEverlastingTool(Mobile from, Item item)
        {
            if ((item is BaseEverlastingHarvestTool) || (item is BaseEverlastingTool) || (item is EverlastingArrow) || (item is EverlastingBolt) || (item is EverlastingBandage))
                return true;

            from.SendMessage("Only Everlasting items can be placed in this bag.");
            return false;
        }

        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (!DropCheckEverlastingTool(from, dropped))
                return false;

            return base.OnDragDrop(from, dropped);
        }

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {
            if (!DropCheckEverlastingTool(from, item))
                return false;

            return base.OnDragDropInto(from, item, p);
        }

        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();
        }
    }
}
 
Last edited:

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back