JGreen

Member
I am going to try my first hand at adding a new tag in player mobile.

I need a little run down some things.

what does this do

C#:
public static List<PlayerMobile> Instances { get; private set; }

        static PlayerMobile()
        {
            Instances = new List<PlayerMobile>(0x1000);
        }

Do i list my tag in
PlayerFlag

I am trying to follow this but pretty stumped a guide on it would be very helpful.
 
It is not clear what you mean and what you want to do, and why you need a flag.
Add more information what do you need to do?
 
I would like to make it. you cant use a item without say reading a book. But I am not sure how to do that. I was tyring to follow the code for glass blowng. But when i used that code i could blow glass as well as use the item i made.
 
That's easy. If you want use player flags, you need next:
Add your CustomFlag to public enum PlayerFlag : ulong enumerable list.
If you see, that last flag on list ending on DisabledPvpWarning = 0x80000000 value, you need add new hex value with your properti, when your value must be last value + 1bit value), it's be:
C#:
...
        Unused = 0x08000000,
        ToggleCutTopiaries = 0x10000000,
        HasValiantStatReward = 0x20000000,
        RefuseTrades = 0x40000000,
        DisabledPvpWarning = 0x80000000,
        CustomFlag = 0x100000000 // we added one zero here, coz previous bit lenght is full
...

Now we need add public property for our Flag for to change his value:
C#:
        [CommandProperty(AccessLevel.GameMaster)]
        public bool CustomFlag { get { return GetFlag(PlayerFlag.CustomFlag); } set { SetFlag(PlayerFlag.CustomFlag, value); } }

If your enum values with your CustomFlag = 32 values, all is ok, but if you using latest version of ServuUO, then you will encounter a bug when saving and reading a world where your value will not be saved correctly. This is due to the fact that in servuo for PlayerFlags, the ulong type is used, which = 64 bits (respectively, 64 fields can be entered in this list), but next it saves and reads in int, which = 32 bits, respectively, all that we have specified over 32 entries, will not be able to correctly save or read changes in the enum list - what would be a bug.
So we need change next:
Find public override void Serialize(GenericWriter writer) method, and find in it writen value of PlayerFlags:
C#:
writer.Write((int)m_Flags);
Change it to:
C#:
writer.Write((ulong)m_Flags);

Do same for read method public override void Deserialize(GenericReader reader), find in it:
C#:
m_Flags = (PlayerFlag)reader.ReadInt();
and change it to:
C#:
m_Flags = (PlayerFlag)reader.ReadULong();

Now it's work correctly.

For finish you need add your custom item, where you can add OnDoubleClick methon, when you can change CustomFlag property as you need:
C#:
 pm.CustomFlag = true;
Look Scripts\Items\Consumables\GlassblowingBook.cs for example.
 
I forgot warning you. When you do changes(except add) on serialization/deserialization, first need to set serialization changes, after that need run server and make save. Now you can same do changes in deserialization method.
otherwise, the server will start with a deserialization error, because it will try to read the modified object at a time when a different object type is written in the saves.
 
thank you i was almost finished with my book and was going to play with this. I would destroyed my world hehe
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back