1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Seek help on Gold Ledger Crash

Discussion in 'Script Support' started by 13440130, Mar 16, 2019 at 4:18 PM.

  1. 13440130
    Online

    13440130 Member

    Joined:
    Jan 25, 2015
    Messages:
    103
    Likes Received:
    5
    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 (C#):
    1. /*public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
    2.         {
    3.             bool canDrop = base.OnDroppedInto(from, target, p);
    4.  
    5.             if (canDrop && target is BankBox)
    6.             {
    7.                 CheckBank((BankBox)target, from);
    8.             }
    9.  
    10.             return canDrop;
    11.         }*/
    12.         #region Alpha Gold Ledger Edit 1
    13.         public override bool OnDroppedToMobile(Mobile from, Mobile target)
    14.         {
    15.             Item gitem = target.Backpack.FindItemByType(typeof(GoldLedger));
    16.             Item thisgitem = this.FindItemByType(typeof(GoldLedger));
    17.  
    18.             if (gitem != null && thisgitem != null)
    19.             {
    20.                 if (target == from)
    21.                     from.SendMessage("You can only carry one gold ledger!");
    22.                 else
    23.                     from.SendMessage("That player can only carry one gold ledger!");
    24.                 return false;
    25.             }
    26.  
    27.             return false;
    28.         }
    29.  
    30.         public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
    31.         {
    32.             if (from == null || target == null)
    33.             {
    34.                 return false;
    35.             }
    36.  
    37.             Item gitem = target.FindItemByType(typeof(GoldLedger));
    38.             Item thisgitem = FindItemByType(typeof(GoldLedger));
    39.  
    40.             if (target == from.Backpack)
    41.             {
    42.                 if (gitem != null && thisgitem != null)
    43.                 {
    44.                     from.SendMessage("You can only carry one gold ledger!");
    45.                     return false;
    46.                 }
    47.             }
    48.             else if (target.IsChildOf(from.Backpack))
    49.             {
    50.                 if (gitem != null && thisgitem != null)
    51.                 {
    52.                     from.SendMessage("You can only carry one gold ledger!");
    53.                     return false;
    54.                 }
    55.             }
    56.  
    57.             return target.OnDragDropInto(from, this, p);
    58.         }
    59.  
    60.         public override bool OnDroppedOnto(Mobile from, Item target)
    61.         {
    62.             Item gitem = from.Backpack.FindItemByType(typeof(GoldLedger));
    63.             Item thisgitem = this.FindItemByType(typeof(GoldLedger));
    64.  
    65.             if (target == from.Backpack)
    66.             {
    67.                 if (gitem != null && thisgitem != null)
    68.                 {
    69.                     from.SendMessage("You can only carry one gold ledger!");
    70.                     return false;
    71.                 }
    72.             }
    73.  
    74.             else if (target.IsChildOf(from.Backpack))
    75.             {
    76.                 if (gitem != null && thisgitem != null)
    77.                 {
    78.                     from.SendMessage("You can only carry one gold ledger!");
    79.                     return false;
    80.                 }
    81.             }
    82.  
    83.             return target.OnDragDrop(from, this);
    84.         }
    85.         #endregion
     
  2. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    1,123
    Likes Received:
    160
    What is the crash error? Post the output from the console or the crash file.
     
  3. 13440130
    Online

    13440130 Member

    Joined:
    Jan 25, 2015
    Messages:
    103
    Likes Received:
    5
    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)
     
  4. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    1,123
    Likes Received:
    160
    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?
     
  5. 13440130
    Online

    13440130 Member

    Joined:
    Jan 25, 2015
    Messages:
    103
    Likes Received:
    5
    The crash log in debug mode is no different, just the same.
     

    Attached Files:

  6. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    1,123
    Likes Received:
    160
    In debug mode it should show line numbers.
     
  7. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    1,123
    Likes Received:
    160
    This version should have the necessary check to prevent null reference crashes:

    Code (C#):
    1.  
    2.         #region Alpha Gold Ledger Edit 1
    3.         public override bool OnDroppedToMobile(Mobile from, Mobile target)
    4.         {
    5.             if (target == null || target.Backpack == null)
    6.             {
    7.                 from.SendMessage("That mobile is null or has no backpack!");
    8.                 return false;
    9.             }
    10.             Item gitem = target.Backpack.FindItemByType(typeof(GoldLedger));
    11.             Item thisgitem = this.FindItemByType(typeof(GoldLedger));
    12.  
    13.             if (gitem != null && thisgitem != null)
    14.             {
    15.                 if (target == from)
    16.                     from.SendMessage("You can only carry one gold ledger!");
    17.                 else
    18.                     from.SendMessage("That player can only carry one gold ledger!");
    19.                 return false;
    20.             }
    21.  
    22.             return false;
    23.         }
    24.  
    25.         public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
    26.         {
    27.             if (from == null || target == null)
    28.             {
    29.                 return false;
    30.             }
    31.  
    32.             Item gitem = target.FindItemByType(typeof(GoldLedger));
    33.             Item thisgitem = FindItemByType(typeof(GoldLedger));
    34.  
    35.             if (target == from.Backpack)
    36.             {
    37.                 if (gitem != null && thisgitem != null)
    38.                 {
    39.                     from.SendMessage("You can only carry one gold ledger!");
    40.                     return false;
    41.                 }
    42.             }
    43.             else if (target.IsChildOf(from.Backpack))
    44.             {
    45.                 if (gitem != null && thisgitem != null)
    46.                 {
    47.                     from.SendMessage("You can only carry one gold ledger!");
    48.                     return false;
    49.                 }
    50.             }
    51.  
    52.             return target.OnDragDropInto(from, this, p);
    53.         }
    54.  
    55.         public override bool OnDroppedOnto(Mobile from, Item target)
    56.         {
    57.             if (target == null || target.Backpack == null)
    58.             {
    59.                 from.SendMessage("That mobile is null or has no backpack!");
    60.                 return false;
    61.             }
    62.             Item gitem = from.Backpack.FindItemByType(typeof(GoldLedger));
    63.             Item thisgitem = this.FindItemByType(typeof(GoldLedger));
    64.  
    65.             if (target == from.Backpack)
    66.             {
    67.                 if (gitem != null && thisgitem != null)
    68.                 {
    69.                     from.SendMessage("You can only carry one gold ledger!");
    70.                     return false;
    71.                 }
    72.             }
    73.  
    74.             else if (target.IsChildOf(from.Backpack))
    75.             {
    76.                 if (gitem != null && thisgitem != null)
    77.                 {
    78.                     from.SendMessage("You can only carry one gold ledger!");
    79.                     return false;
    80.                 }
    81.             }
    82.  
    83.             return target.OnDragDrop(from, this);
    84.         }
    85.         #endregion
     
  8. 13440130
    Online

    13440130 Member

    Joined:
    Jan 25, 2015
    Messages:
    103
    Likes Received:
    5
    Thank you very much for your help, but there seems to be a slight mistake.
     

    Attached Files:

    • a1.png
      a1.png
      File size:
      7.3 KB
      Views:
      3
    • a2.png
      a2.png
      File size:
      9.4 KB
      Views:
      3
  9. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    1,123
    Likes Received:
    160
    Try this:

    Code (C#):
    1. if (target == null || from.Backpack == null)
     
Similar Threads: Seek help
Forum Title Date
ServUO Discussion seeking help with placement of items and npcs Oct 11, 2017
Script Support seeking setup help Oct 10, 2017
Looking For Help My Work In Progress (seeking help) Oct 25, 2015
Script Support Seek help~ Feb 9, 2015
ServUO Discussion Novice and to seek help and guidance Feb 2, 2015
Looking For Help Family Shard Seeks Help with Load Test Jul 17, 2014
Looking For Help 3yr old dev shard Seeking All Staff. Any help appreciated. May 21, 2014