When using the Gold Ledger script, you need to modify the code in the Container. CS script
But after modification, when container items such as backpacks, boxes and gift boxes are thrown onto NPCs without backpacks (such as Chyloth, Dryad), the server will crash.

Code:
/*public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
        {
            bool canDrop = base.OnDroppedInto(from, target, p);

            if (canDrop && target is BankBox)
            {
                CheckBank((BankBox)target, from);
            }

            return canDrop;
        }*/
        #region Alpha Gold Ledger Edit 1
        public override bool OnDroppedToMobile(Mobile from, Mobile target)
        {
            Item gitem = target.Backpack.FindItemByType(typeof(GoldLedger));
            Item thisgitem = this.FindItemByType(typeof(GoldLedger));

            if (gitem != null && thisgitem != null)
            {
                if (target == from)
                    from.SendMessage("You can only carry one gold ledger!");
                else
                    from.SendMessage("That player can only carry one gold ledger!");
                return false;
            }

            return false;
        }

        public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
        {
            if (from == null || target == null)
            {
                return false;
            }

            Item gitem = target.FindItemByType(typeof(GoldLedger));
            Item thisgitem = FindItemByType(typeof(GoldLedger));

            if (target == from.Backpack)
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }
            else if (target.IsChildOf(from.Backpack))
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }

            return target.OnDragDropInto(from, this, p);
        }

        public override bool OnDroppedOnto(Mobile from, Item target)
        {
            Item gitem = from.Backpack.FindItemByType(typeof(GoldLedger));
            Item thisgitem = this.FindItemByType(typeof(GoldLedger));

            if (target == from.Backpack)
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }

            else if (target.IsChildOf(from.Backpack))
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }

            return target.OnDragDrop(from, this);
        }
        #endregion
 
What is the crash error? Post the output from the console or the crash file.
Server Crash Report
===================

ServUO Version 0.5, Build 6983.12228
Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1
.NET Framework: 4.0.30319.42000
Time: 2019/3/16 14:09:59
Mobiles: 43963
Items: 233905
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.BaseContainer.OnDroppedToMobile(Mobile from, Mobile target)
at Server.Item.DropToMobile(Mobile from, Mobile target, Point3D p)
at Server.Mobile.Drop(Mobile to, Point3D loc)
at Server.Network.PacketHandlers.DropReq6017(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
 
Sorry if this is difficult. Would you be able to run in Debug mode please, and post the crash again? Also post your BaseContainer complete script?
 
This version should have the necessary check to prevent null reference crashes:

Code:
        #region Alpha Gold Ledger Edit 1
        public override bool OnDroppedToMobile(Mobile from, Mobile target)
        {
            if (target == null || target.Backpack == null)
            {
                from.SendMessage("That mobile is null or has no backpack!");
                return false;
            }
            Item gitem = target.Backpack.FindItemByType(typeof(GoldLedger));
            Item thisgitem = this.FindItemByType(typeof(GoldLedger));

            if (gitem != null && thisgitem != null)
            {
                if (target == from)
                    from.SendMessage("You can only carry one gold ledger!");
                else
                    from.SendMessage("That player can only carry one gold ledger!");
                return false;
            }

            return false;
        }

        public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
        {
            if (from == null || target == null)
            {
                return false;
            }

            Item gitem = target.FindItemByType(typeof(GoldLedger));
            Item thisgitem = FindItemByType(typeof(GoldLedger));

            if (target == from.Backpack)
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }
            else if (target.IsChildOf(from.Backpack))
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }

            return target.OnDragDropInto(from, this, p);
        }

        public override bool OnDroppedOnto(Mobile from, Item target)
        {
            if (target == null || target.Backpack == null)
            {
                from.SendMessage("That mobile is null or has no backpack!");
                return false;
            }
            Item gitem = from.Backpack.FindItemByType(typeof(GoldLedger));
            Item thisgitem = this.FindItemByType(typeof(GoldLedger));

            if (target == from.Backpack)
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }

            else if (target.IsChildOf(from.Backpack))
            {
                if (gitem != null && thisgitem != null)
                {
                    from.SendMessage("You can only carry one gold ledger!");
                    return false;
                }
            }

            return target.OnDragDrop(from, this);
        }
        #endregion
 
Thank you very much for your help, but there seems to be a slight mistake.
 

Attachments

  • a1.png
    a1.png
    7.3 KB · Views: 19
  • a2.png
    a2.png
    9.4 KB · Views: 19
Back