Seek help on Gold Ledger Crash

13440130

Well-Known Member
Jan 25, 2015
123
6
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
 

13440130

Well-Known Member
Jan 25, 2015
123
6
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)
 

Lokai

Moderator
ServUO Developer
Dec 4, 2014
1,199
189
Western New York State
Shard Name
Test Center
Donate
Donate money to this user
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?
 

Lokai

Moderator
ServUO Developer
Dec 4, 2014
1,199
189
Western New York State
Shard Name
Test Center
Donate
Donate money to this user
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