jayates

Member
Was wondering if someone could help me with my script? Here's what i'm wanting it to do. There's an Empty Flavor Vial and depending on which flavoring you have in your backpack it'll give you the one you want. Here's my script just needing some help to get it to work.
using System; using Server; using Server.Gumps; using Server.Network; using System.Collections; using Server.Multis; using Server.Mobiles; namespace Server.Items { public class EmptyFlavorVial : Item { [Constructable] public EmptyFlavorVial() : this( null ) { } [Constructable] public EmptyFlavorVial ( string name ) : base (3620) //vial { Name = "an Empty Flavor Vial"; LootType = LootType.Blessed; Hue = 0; } public EmptyFlavorVial ( Serial serial ) : base ( serial ) { } public override void OnDoubleClick( Mobile p ) { Item a = p.Backpack.FindItemByType( typeof(FlavorOne), 10 ); if ( a != null ) { p.AddToBackpack( new FlavoredVialOne() ); a.Delete(); p.SendMessage( "You successfully combined the flavors with the vial!" ); this.Delete(); } } Item a = p.Backpack.FindItemByType( typeof(FlavorTwo), 10 ); if ( a != null ) { p.AddToBackpack( new FlavoredVialTwo() ); a.Delete(); p.SendMessage( "You successfully combined the flavors with the vial!" ); this.Delete(); } } Item a = p.Backpack.FindItemByType( typeof(FlavorThree), 10 ); if ( a != null ) { p.AddToBackpack( new FlavoredVialThree() ); a.Delete(); p.SendMessage( "You successfully combined the flavors with the vial!" ); this.Delete(); } else { p.SendMessage( "You are missing the correct flavors!" ); } } public override void Serialize ( GenericWriter writer) { base.Serialize ( writer ); writer.Write ( (int) 0); } public override void Deserialize( GenericReader reader ) { base.Deserialize ( reader ); int version = reader.ReadInt(); } } }
 
Well I see 1 flaw, and redundant code parts, but it would still work in general?

So what is your issue here?

and please use the CODE tag not the ICODE one :)
 
Here's the errors:
CS1519: Line 48: Invalid token 'if' in class, struct, or interface member declaration
CS1519: Line 48: Invalid token '!=' in class, struct, or interface member declaration
CS1519: Line 51: Invalid token '(' in class, struct, or interface member declaration
CS1520: Line 51: Method must have a return type
CS1002: Line 51: ; expected
CS1519: Line 52: Invalid token '(' in class, struct, or interface member declaration
CS1519: Line 53: Invalid token '(' in class, struct, or interface member declaration
CS1520: Line 54: Method must have a return type
CS0116: Line 58: A namespace cannot directly contain members such as fields or methods
CS1518: Line 62: Expected class, delegate, enum, interface, or struct
CS1022: Line 66: Type or namespace definition, or end-of-file expected
Post automatically merged:

C#:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using System.Collections;
using Server.Multis;
using Server.Mobiles;


namespace Server.Items
{

    public class EmptyFlavorVial : Item
    {
        [Constructable]
        public EmptyFlavorVial() : this( null )
        {
        }

        [Constructable]
        public EmptyFlavorVial ( string name ) : base (3702)
        {
            Name = "a Bag For Secrets";
            LootType = LootType.Blessed;
            Hue = 0;
        }

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

              
        public override void OnDoubleClick( Mobile p )

        {
            Item a = p.Backpack.FindItemByType( typeof(FlavorOne), 10 );
            if ( a != null )
            {
                p.AddToBackpack( new FlavoredVialOne() );
                a.Delete();
                p.SendMessage( "You successfully combined the flavors with the vial!" );
                this.Delete();
            }  //add for each deleted item
        else
            {
                p.SendMessage( "You are missing the correct flavors!" );
            }
        }
    
        
            Item b = p.Backpack.FindItemByType( typeof(FlavorTwo), 10 );
            if ( b != null )
            {
                p.AddToBackpack( new FlavoredVialTwo() );
                b.Delete();
                p.SendMessage( "You successfully combined the flavors with the vial!" );
                this.Delete();
            }  //add for each deleted item           
            else
            {
                p.SendMessage( "You are missing the correct flavors!" );
            }
        }
        
            Item c = p.Backpack.FindItemByType( typeof(FlavorThree), 10 );
            if ( c != null )
            {
                p.AddToBackpack( new FlavoredVialThree() );
                c.Delete();
                p.SendMessage( "You successfully combined the flavors with the vial!" );
                this.Delete();
            }  //add for each deleted item           
            else
            {
                p.SendMessage( "You are missing the correct flavors!" );
            }
        }   
        public override void Serialize ( GenericWriter writer)
        {
            base.Serialize ( writer );

            writer.Write ( (int) 0);
        }

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

            int version = reader.ReadInt();
        }
    }
}
Post automatically merged:

Here's the script again with all 3 sections. Not sure how to combine all sections to make the script work. Upon dblclicking the Empty Flavor Vial depending on which flavor vial is in your backpack you'll get vial 1, 2, or 3.
 
Last edited:
Well the first problem is that you have a closing bracket at line 48 and 63 wich are not supposed to be there.
But we will go over the whole script in a bit, so that it may help you or other people in the future.

highlighted errors:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using System.Collections;
using Server.Multis;
using Server.Mobiles;


namespace Server.Items
{

    public class EmptyFlavorVial : Item
    {
        [Constructable]
        public EmptyFlavorVial() : this( null )
        {
        }

        [Constructable]
        public EmptyFlavorVial ( string name ) : base (3702)
        {
            Name = "a Bag For Secrets";
            LootType = LootType.Blessed;
            Hue = 0;
        }

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

              
        public override void OnDoubleClick( Mobile p )

        {
            Item a = p.Backpack.FindItemByType( typeof(FlavorOne), 10 );
            if ( a != null )
            {
                p.AddToBackpack( new FlavoredVialOne() );
                a.Delete();
                p.SendMessage( "You successfully combined the flavors with the vial!" );
                this.Delete();
            }  //add for each deleted item
        else
            {
                p.SendMessage( "You are missing the correct flavors!" );
            }
        }
    
        
            Item b = p.Backpack.FindItemByType( typeof(FlavorTwo), 10 );
            if ( b != null )
            {
                p.AddToBackpack( new FlavoredVialTwo() );
                b.Delete();
                p.SendMessage( "You successfully combined the flavors with the vial!" );
                this.Delete();
            }  //add for each deleted item           
            else
            {
                p.SendMessage( "You are missing the correct flavors!" );
            }
        }
        
            Item c = p.Backpack.FindItemByType( typeof(FlavorThree), 10 );
            if ( c != null )
            {
                p.AddToBackpack( new FlavoredVialThree() );
                c.Delete();
                p.SendMessage( "You successfully combined the flavors with the vial!" );
                this.Delete();
            }  //add for each deleted item           
            else
            {
                p.SendMessage( "You are missing the correct flavors!" );
            }
        }   
        public override void Serialize ( GenericWriter writer)
        {
            base.Serialize ( writer );

            writer.Write ( (int) 0);
        }

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

            int version = reader.ReadInt();
        }
    }
}

Fixing those brackets that gave you the error message, you will end up with:
fixed brackets:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using System.Collections;
using Server.Multis;
using Server.Mobiles;

namespace Server.Items
{   
    public class EmptyFlavorVial : Item
    {
        [Constructable]
        public EmptyFlavorVial() : this(null)
        {
        }

        [Constructable]
        public EmptyFlavorVial(string name) : base(3702)
        {
            Name = "a Bag For Secrets";
            LootType = LootType.Blessed;
            Hue = 0;
        }

        public EmptyFlavorVial(Serial serial) : base(serial)
        {
        }
        
        public override void OnDoubleClick(Mobile p)
        {
            Item a = p.Backpack.FindItemByType(typeof(FlavorOne), 10);
            if (a != null)
            {
                p.AddToBackpack(new FlavoredVialOne());
                a.Delete();
                p.SendMessage("You successfully combined the flavors with the vial!");
                this.Delete();
            }  //add for each deleted item
            else
            {
                p.SendMessage("You are missing the correct flavors!");
            }

            Item b = p.Backpack.FindItemByType(typeof(FlavorTwo), 10);
            if (b != null)
            {
                p.AddToBackpack(new FlavoredVialTwo());
                b.Delete();
                p.SendMessage("You successfully combined the flavors with the vial!");
                this.Delete();
            }  //add for each deleted item           
            else
            {
                p.SendMessage("You are missing the correct flavors!");
            }

            Item c = p.Backpack.FindItemByType(typeof(FlavorThree), 10);
            if (c != null)
            {
                p.AddToBackpack(new FlavoredVialThree());
                c.Delete();
                p.SendMessage("You successfully combined the flavors with the vial!");

                this.Delete();

            }  //add for each deleted item           
            else
            {
                p.SendMessage("You are missing the correct flavors!");
            }
        }
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)0);
        }

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

            int version = reader.ReadInt();
        }
    }
}

However looking over the code, there are a few more flaws and actually bugs. So lets address these too quickly ;)

Flaw number one is that you have an separate constructor that gives you a name value, wich you never use. So we can just remove that / combine it with the default constructor.

Flaw number two, you are setting the Name of the Item. This isnt an issue in general, but I personally find it cleaner to override the DefaultName property, since you can then reset the name to the default one and all instances of the Item will change the name, if you change it there.

Flaw number three, you have a lot of redundance in your code wich makes it more work to maintain for yourself

Bug number one, you are deleting the found flavor items, but if you have lets say 33 of one kind, you will delete all. In cases like this its easier to use the Consume method after checking if there are enough items on the stack. Or you can use a different method, we will get to that in a bit ;)

Bug number two, you never check if you already created a flavor vial. In other words you can create up to three of those, with 1 empty vial

Bug number three, I cant find any reference to an FindItemByType(typeof(FlavorOne), 10) unless it is newish and not in the copy of the server software I run atm.

Bug number four, you never check if the Vial is in your backpack or at least in range. Additionally if it would be locked down in someone elses house you could still use it.

So a version that has all this addressed could look like this
Code:
namespace Server.Items
{
    public class EmptyFlavorVial : Item
    {
        public override string DefaultName => "a Bag For Secrets";

        [Constructable]
        public EmptyFlavorVial() : base(3702)
        {
            LootType = LootType.Blessed;
            Hue = 0;
        }

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

        private int CheckGrouping(Item a, Item b)
        {
            return b.Hue.CompareTo(a.Hue);
        }

        public override void OnDoubleClick(Mobile p)
        {
            if (!IsChildOf(p.Backpack) && !p.InRange(GetWorldLocation(), 2))
            {
                p.SendLocalizedMessage(500446); // That is too far away.
                return;
            }

            if (!Movable)
            {
                p.SendLocalizedMessage(1010449); // You may not use this object while it is locked down.
                return;
            }

            var success = false;

            if ((success = p.Backpack.ConsumeTotalGrouped(typeof(FlavorOne), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlavoredVialOne());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(FlavorTwo), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlavoredVialTwo());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(FlavorThree), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlavoredVialThree());
            }

            if (success)
            {
                p.SendMessage("You successfully combined the flavors with the vial!");
                Delete();
            }
            else
            {
                p.SendMessage("You are missing the correct flavors!");
            }
        }

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

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

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back