RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

LiftItemDupe to copy special Item properties in mobile.cs (server mod)

fwiffo

Sorceror
In mobile.cs, you have to put this at the beginning of course:
Code:
using System.Reflection;

and, using actual SVN code, you have to mod the LiftItemDupe as this:
Code:
public static Item LiftItemDupe( Item oldItem, int amount )
{
    Item item;
    try
    {
        item = (Item)Activator.CreateInstance( oldItem.GetType() );
    }
    catch
    {
        Console.WriteLine( "Warning: 0x{0:X}: Item must have a zero paramater constructor to be separated from a stack. '{1}'.", oldItem.Serial.Value, oldItem.GetType().Name );
        return null;
    }
/*            item.Visible = oldItem.Visible;
            item.Movable = oldItem.Movable;
            item.LootType = oldItem.LootType;
            item.Direction = oldItem.Direction;
            item.Hue = oldItem.Hue;
            item.ItemID = oldItem.ItemID;
            item.Location = oldItem.Location;
            item.Layer = oldItem.Layer;
            item.Name = oldItem.Name;
            item.Weight = oldItem.Weight;
 
            item.Amount = oldItem.Amount - amount;
            item.Map = oldItem.Map;
 
            oldItem.Amount = amount;
            oldItem.OnAfterDuped( item );*/
 
            if( oldItem.Parent is Mobile )
            {
                ((Mobile)oldItem.Parent).AddItem( item );
            }
            else if( oldItem.Parent is Item )
            {
                ((Item)oldItem.Parent).AddItem( item );
            }
 
            item.Delta( ItemDelta.Update );
            PropertyInfo[] properties = oldItem.GetType().GetProperties();
            for (int i = 0; i < properties.Length; i++)
            {
                try
                {
                    if (properties[i].CanRead && properties[i].CanWrite)
                    {
                        properties[i].SetValue(item, properties[i].GetValue(oldItem, null), null);
                    }
                }
                catch
                {
                    return null;
                }
            }
            item.Amount = oldItem.Amount - amount;
            oldItem.Amount = amount;
            oldItem.OnAfterDuped(item);
 
            return item;
}

This way, special item properties usually like BaseItemType prop, for items normally non stackable, could be duplicated, thanks to reflection.

Remember that any prop will be duplicated, so you can make stackable any type of item, even atypical.

Bye

PS: you can also use any server version you wish, but this mod was made and tested on latest svn
PPS: by tested I mean on a server with a hundred of players.
 

mumuboy

Sorceror
I like your idea!
I have dabbled with this myself as well. Another alternative the RunUO devs could consider is a dupe command someone on the forums made a while back. That command could be used internally to dupe items/mobiles and if its set up in the right way, it can be done without risk to dynamic lists.
 

fwiffo

Sorceror
Eh, that is something already made in ages in our shard, I've only seen that in the core script of runuo SVN they're still using the faster method, but that is absolutely imprecise, for copying properties to stackable items..if you mod the scrolls for example and want them to contain a specific property unique, of "BaseScroll" type property, actually, with official core, you can't...you have to quirk something in the scripts unless you mod the core. That's why I posted it, maybe there is someone in need of help and can find this "ready to use solution", a lot of time I learned from my errors only by reading and searching in this forum, so I returned (partly) the favor.

Anyway, I'll search this dupe command, just to peek :p
 

mumuboy

Sorceror
I forgot to mention that the one I found by searching was done by deserializing the items and then serializing new ones with the exact same data and using new serial numbers. I tested it out and if used right it is pretty flawless.

The downside to all dupe methods that I found is that the server lags tremendously if a container is duped with many items and its recursively duped. To fix that you would have to LOCK the items and MOVE them, then async (separate thread?) the process.
 
Top