Can't add BottleOfLiquor to vendors - complier can't find namespace

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
I'm trying to add an item BottleOfLiquor from \Scripts\Services\New Magincia\Distillation\Items to Waiter vendor with a line:
Add(new BeverageBuyInfo(typeof(BottleOfLiquor), Liquor.Bourbon, 7, 20, 0x99B, 0));

but I get two errors at once:
1. that the type or namespace BottleOfLiquor can't be found
2. that it's not a vaild property for Liquor, despite with [props i can set this value :-(

I tried removing the condition Liquor.Bourbon but still get the type or namespace error.
 

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
Add
C#:
using Server.Engines.Distillation;
to the top of the file if it is not there
It didnt work unfortunately - now there's another error for that line of bottleofliquor, that
VendorInfo\SBWaiter.cs(23,13): error CS1729: 'BeverageBuyInfo" doesn't have constructor which recives arguments 5.

Translating that text to English so I'm not sure how this could sound originally.
Post automatically merged:

Add
C#:
using Server.Engines.Distillation;
to the top of the file if it is not there
Partially works, seems so - I use the code
Add(new GenericBuyInfo(typeof(BottleOfLiquor), 7, 20, 0x99B, 0)) - and it seems to add buyable bollte of hkiskey (default liquor by the code)

But when I try to specify the type via
Add(new GenericBuyInfo(typeof(BottleOfLiquor), Liquor.Bourbon, 7, 20, 0x99B, 0));
I get an error with arguments:
VendorInfo\SBWaiter.cs(24,52): error CS1503: Argument 2: unable to convert "Server.Engines.Distillation.Liquor" to "int". [C:\ServUO-master\Scripts\Scripts.csproj]
VendorInfo\SBWaiter.cs(24,82): error CS1503: Argument 6: unable to convert "int" to "bool". [C:\ServUO-master\Scripts\Scripts.csproj]

I'm sure the "Liquor" is the valid property because of the code in DistillationSystem.cs
public enum Liquor
{
None,
Whiskey,
Bourbon,
...

So likely the problem is with arguments. Maybe you know something about them? I didn't yet find what each one means, loking for it.
 
Last edited:

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
I tried to follow his construction from GenericBuy.cs
C#:
    public GenericBuyInfo(Type type, int price, int amount, int itemID, int hue, object[] args, bool stacks = false)
            : this(null, type, price, amount, itemID, hue, args, stacks)
and used a line like this
Add(new GenericBuyInfo(typeof(BottleOfLiquor), 7, 20, 0x99B, 0, Liquor.Bourbon));

But the compiler still seems to try to read Liquor.Bourbon as bool :-(
 

Archaaz

Squire
Sep 17, 2016
235
93
28
I suspect that this does not work because Distillation is a separate, but related, system. Add(new GenericBuyInfo differs from Add(new BeverageBuyInfo in that Add(new BeverageBuyInfo includes the beverage type in its constructor. The beverage types from the original beverage system differ from the Distillation system.


I would suggest creating a separate item, BottleOfBourbon, as a child of BottleOfLiquor, and setting Liquor.Bourbon in that script. Then you can sell it as a separate item using Add(new GenericBuyInfo(typeof(BottleOfBourbon), 7, 20, 0x99B, 0 ));
 
  • Like
Reactions: Bonaccorso

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
I suspect that this does not work because Distillation is a separate, but related, system. Add(new GenericBuyInfo differs from Add(new BeverageBuyInfo in that Add(new BeverageBuyInfo includes the beverage type in its constructor. The beverage types from the original beverage system differ from the Distillation system.


I would suggest creating a separate item, BottleOfBourbon, as a child of BottleOfLiquor, and setting Liquor.Bourbon in that script. Then you can sell it as a separate item using Add(new GenericBuyInfo(typeof(BottleOfBourbon), 7, 20, 0x99B, 0 ));
I'm trying to do as you adviced, but now I got an unexpected problem with a new BottleofBourbon item.
Here's its code:
C#:
using Server.Items;
using System;
using Server.Engines.Craft;
using Server.Engines.Distillation;

namespace Server.Engines.Distillation
{
    public class BottleOfBourbon : BottleOfLiquor
    {
        [Constructable]
        public BottleOfBourbon()
        {
              Liquor = Bourbon;
        }
    }
}
When I try to complie it, I get an error that "Bourbon" name doesn't exist in this context. Why can it be so?

I was looking on constructor in BottleofLiquor:
C#:
[Constructable]
        public BottleOfLiquor() : this(Liquor.Whiskey, null, false, null)
        {
        }
And Bourbon is definitely in this list for Liquor property, even xmlspawner works fine with it.
 

Archaaz

Squire
Sep 17, 2016
235
93
28
Try
Code:
Liquor = Liquor.Bourbon;
or

Code:
[Constructable]
        public BottleOfBourbon() : this(Liquor.Bourbon, null, false, null)
        {
        }
 
  • Like
Reactions: Bonaccorso

Archaaz

Squire
Sep 17, 2016
235
93
28
You are most welcome. I am glad it worked. I am using RunUO and am not familiar with the Distillation system, though I hope to add it now..:). I did finally take a look at it. The reason you could not add the BottleOfLiquor to the Waiter SB script can be found in BeverageBuytInfo.cs:

Code:
BeverageBuyInfo( string name, Type type, BeverageType content, int price, int amount, int itemID, int hue )

BottleOfLiquor uses Liquor rather than BeverageType, which is used by BaseBeverage. You could probably create a new GenericBuyInfo script to accommodate BottleOfLiquor, though I think it is simpler to simply make the new BottleOfBourbon item (and any others you may want to add).
 
  • Like
Reactions: Bonaccorso

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
You are most welcome. I am glad it worked. I am using RunUO and am not familiar with the Distillation system, though I hope to add it now..:). I did finally take a look at it. The reason you could not add the BottleOfLiquor to the Waiter SB script can be found in BeverageBuytInfo.cs:

Code:
BeverageBuyInfo( string name, Type type, BeverageType content, int price, int amount, int itemID, int hue )

BottleOfLiquor uses Liquor rather than BeverageType, which is used by BaseBeverage. You could probably create a new GenericBuyInfo script to accommodate BottleOfLiquor, though I think it is simpler to simply make the new BottleOfBourbon item (and any others you may want to add).
Wow, thansk for the detaield review! Yes, it seems it's much easier to create several new objects BottleOf... than rewriting the script :) I'll go with this so far.
Didn't code for a really long time before starting with servuo.
 
  • Like
Reactions: Archaaz

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
Need help, I'm very confused now - I was able to complie and launch the game yesterday with this file, but today I tried to recomplie (by accident, isntead of launching) and I get an error, despite I changed nothing!

The weirdest thing is that I get error on loading world, not on complie:

Error:
System.Exception: Type 'Server.Engines.Distillation.BottleOfBourbon' does not have a serialization constructor
в Server.World.ReadTypes(BinaryReader tdbReader) в C:\ServUO-master\Server\World.cs:line 237
в Server.World.Load() в C:\ServUO-master\Server\World.cs:line 361
в Server.Core.Setup(String[] args) в C:\ServUO-master\Server\Main.cs:line 614
в ServUO.ServUO.Main(String[] args) в C:\ServUO-master\Application\ServUO.cs:line 10
This exception is fatal, press return to exit

I suppose it can be connected to my BottleofBourbon.cs
C#:
using Server.Items;
using System;
using Server.Engines.Craft;
using Server.Engines.Distillation;

namespace Server.Engines.Distillation
{
    public class BottleOfBourbon : BottleOfLiquor
    {
        [Constructable]
        public BottleOfBourbon()
        {
              Liquor = Liquor.Bourbon;
        }
    }
}
That's all that I have there. But when I try to add constructions like below, I get a compliation error that the namespace cant contrin it.

C#:
public BottleOfBourbon(Serial serial) : base(serial)
        {
        }

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

            writer.Write(m_IsStrong);

            writer.Write((int)m_Liquor);
            writer.Write(m_Label);
            writer.Write(m_Distiller);
        }

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

            switch (version)
            {
                case 1:
                    m_IsStrong = reader.ReadBool();
                    goto case 0;
                case 0:
                    m_Liquor = (Liquor)reader.ReadInt();
                    m_Label = reader.ReadString();
                    m_Distiller = reader.ReadMobile();

                    m_IsStrong = true;
                    break;
            }
        }
Post automatically merged:

I added some code in BottleofBourbon.cs:
C#:
using Server.Items;
using System;
using Server.Engines.Craft;
using Server.Engines.Distillation;

namespace Server.Engines.Distillation
{
    public class BottleOfBourbon : BottleOfLiquor
    {
        [Constructable]
        public BottleOfBourbon()
        {
              Liquor = Liquor.Bourbon;
        }
        
        public BottleOfBourbon(Serial serial) : base(serial)
        {
        }
    }
    
}
So far was able to complie and launch Servuo, but I got a warning there:
Core: Loading config...
Warning: Server.Engines.Distillation.BottleOfBourbon
- No Serialize() method
- No Deserialize() method

What do I still miss? :confused::rolleyes:
 
Last edited:

Archaaz

Squire
Sep 17, 2016
235
93
28
Try this:

Code:
using Server.Items;
using System;
using Server.Engines.Craft;
using Server.Engines.Distillation;

namespace Server.Engines.Distillation
{
    public class BottleOfBourbon : BottleOfLiquor
    {
        [Constructable]
        public BottleOfBourbon()
        {
              Liquor = Liquor.Bourbon;
        }

       public BottleOfBourbon( 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();
       }

    }
}
 
  • Like
Reactions: Bonaccorso

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
Try this:

Code:
using Server.Items;
using System;
using Server.Engines.Craft;
using Server.Engines.Distillation;

namespace Server.Engines.Distillation
{
    public class BottleOfBourbon : BottleOfLiquor
    {
        [Constructable]
        public BottleOfBourbon()
        {
              Liquor = Liquor.Bourbon;
        }

       public BottleOfBourbon( 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();
       }

    }
}
Thank you, it seems to work fine! You saved my scripting again :)
 
  • Like
Reactions: Archaaz

Archaaz

Squire
Sep 17, 2016
235
93
28
Happy to help and glad it worked!
Post automatically merged:

BottleOfBourbon is a child of BottleOfLiquor, thuis it inherits all props from BottleOfLiquor automatically. These do not need to be readded to serialization/deserialization in BottleOfBourbon. You would only need to do this for any new props you add to BottleOfBourbon.
 
Last edited:
  • Like
Reactions: Bonaccorso

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
Happy to help and glad it worked!
Post automatically merged:

BottleOfBourbon is a child of BottleOfLiquor, thuis it inherits all props from BottleOfLiquor automatically. These do not need to be readded to serialization/deserialization in BottleOfBourbon. You would only need to do this for any new props you add to BottleOfBourbon.
Yeah, that's where I got confused, and panicked a bit, when a game, which I didn't change after a previous play, showed me fatal error :) Didn't know such things could happen. Thanks for the explanation!
 

Archaaz

Squire
Sep 17, 2016
235
93
28
Also, take care with serialization. Improper serialization and deserialization to existing items can result in the server asking if you want to delete them when it tries to load the world. If this happens, do not answer. Note the script name and close the server, then try to find the serialization issue in the script.

An example of this would be trying to add a new prop to PlayerMobile. If not done correctly, the server will ask if you want to delete all PlayerMobiles. Not ideal to say the least...:).

I highly recommend making backups of any files you alter.
 
  • Like
Reactions: Bonaccorso

Bonaccorso

Rookie
Mar 1, 2019
78
13
8
32
Also, take care with serialization. Improper serialization and deserialization to existing items can result in the server asking if you want to delete them when it tries to load the world. If this happens, do not answer. Note the script name and close the server, then try to find the serialization issue in the script.

An example of this would be trying to add a new prop to PlayerMobile. If not done correctly, the server will ask if you want to delete all PlayerMobiles. Not ideal to say the least...:).

I highly recommend making backups of any files you alter.
Dangerous thing! And it actually asked me to delete old BottleofBourbon objects - though I wasn't against it, as there were only two in my backpack, didn't yet use them other than for testing in game. With widely used objects it could be a really bad thing.
I make weekly backups so far, but I think I really should consider making reserve copies of changed files.
 
  • Like
Reactions: Archaaz