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

Painting system - crash and other questions

Discussion in 'Script Support' started by Abracadabra2.0, Mar 18, 2017.

  1. Abracadabra2.0
    Offline

    Joined:
    Sep 10, 2016
    Messages:
    72
    Likes Received:
    2
    I am attempting to create a custom system in which the player can select from a menu of different types of paintings and then, when selected, get a target which will allow them to identify the subject of the work. The end result would produce a painting or portrait of the subject by the artist.

    I'm having a little trouble with a few key elements.

    1. I'm not quite sure about how to write the targeting methods. I've created one for each art style because each one will do something a little different.
    • Portraits should produce "A portrait of (subject) by (artist)" or, in the event the player targets themselves, "A self portrait by (artist)".
    • Still Lifes should produce "A painting of (subject item) by (artist)".
    • Abstracts should produce "An abstract painting by (artist)".
    2. I attempted to do the abstract first because i thought it would be easier, but I must have something wrong because it produced the following crash:
    Code (C#):
    1.  
    2.  
    3. Server Crash Report
    4. ===================
    5.  
    6. RunUO Version 2.6, Build 0.13549
    7. Operating System: Microsoft Windows NT 6.2.9200.0
    8. .NET Framework: 4.0.30319.42000
    9. Time: 3/19/2017 12:21:43 AM
    10. Mobiles: 17107
    11. Items: 144434
    12. Exception:
    13. System.NullReferenceException: Object reference not set to an instance of an object.
    14.    at Server.Gumps.PaintingGump.AbstractTarget1.OnTarget(Mobile from, Object targeted)
    15.    at Server.Targeting.Target.Invoke(Mobile from, Object targeted) in C:\Users\Tom\Desktop\RunUO-2.6 + Distro151\RunUO-2.6 + Distro151\RunUO-2.6\Server\Targeting\Target.cs:line 291
    16.    at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc) in C:\Users\Tom\Desktop\RunUO-2.6 + Distro151\RunUO-2.6 + Distro151\RunUO-2.6\Server\Network\PacketHandlers.cs:line 1200
    17.    at Server.Network.MessagePump.HandleReceive(NetState ns) in C:\Users\Tom\Desktop\RunUO-2.6 + Distro151\RunUO-2.6 + Distro151\RunUO-2.6\Server\Network\MessagePump.cs:line 260
    18.    at Server.Network.MessagePump.Slice() in C:\Users\Tom\Desktop\RunUO-2.6 + Distro151\RunUO-2.6 + Distro151\RunUO-2.6\Server\Network\MessagePump.cs:line 127
    19.    at Server.Core.Main(String[] args) in C:\Users\Tom\Desktop\RunUO-2.6 + Distro151\RunUO-2.6 + Distro151\RunUO-2.6\Server\Main.cs:line 532
    20.  
    Here is the way I did that particular targeting method:
    Code (C#):
    1.  
    2. public class AbstractTarget1 : Target
    3.         {
    4.             private Mobile m_Owner;
    5.             private PaintBrush m_abstracttarget;
    6.  
    7.             public AbstractTarget1() : base(1, false, TargetFlags.None)
    8.             {
    9.                        
    10.  
    11.             }
    12.  
    13.             protected override void OnTarget(Mobile from, object targeted)
    14.             {
    15.  
    16.                 if (targeted is Item)
    17.                 {
    18.                     Item subject = (Item)targeted;
    19.                                              
    20.                         subject.Name = "An abstract painting by " + m_Owner.Name.ToString();
    21.                         from.AddToBackpack(new AbstractPainting1());
    22.                  
    23.                 }
    24.  
    25.                 else if (targeted is Static)
    26.                 {
    27.                     Static staticsubject = (Static)targeted;
    28.                     staticsubject.Name = "An abstract painting by" + m_Owner.Name.ToString();
    29.                     from.AddToBackpack(new AbstractPainting1());
    30.                 }
    31.  
    32.                 else
    33.                 {
    34.                     from.SendMessage("You cannot immagine an abstract of that!");
    35.                     return;
    36.                 }
    37.  
    38.             }
    39.  
    40.         }
    41.  
    42.         public class AbstractTarget2 : Target
    43.         {
    44.             private Mobile m_Owner;
    45.             private PaintBrush m_abstracttarget;
    46.  
    47.             public AbstractTarget2() : base(1, false, TargetFlags.None)
    48.             {
    49.  
    50.  
    51.             }
    52.  
    53.             protected override void OnTarget(Mobile from, object targeted)
    54.             {
    55.  
    56.                 if (targeted is Item)
    57.                 {
    58.                     Item subject = (Item)targeted;
    59.  
    60.                     subject.Name = "An abstract painting by " + m_Owner.Name.ToString();
    61.                     from.AddToBackpack(new AbstractPainting2());
    62.  
    63.                 }
    64.  
    65.                 else if (targeted is Static)
    66.                 {
    67.                     Static staticsubject = (Static)targeted;
    68.                     staticsubject.Name = "An abstract painting by" + m_Owner.Name.ToString();
    69.                     from.AddToBackpack(new AbstractPainting2());
    70.                 }
    71.  
    72.                 else
    73.                 {
    74.                     from.SendMessage("You cannot immagine an abstract of that!");
    75.                     return;
    76.                 }
    77.  
    78.             }
    79.  
    80.         }
    81.  
    82.         public class AbstractTarget3 : Target
    83.         {
    84.             private Mobile m_Owner;
    85.             private PaintBrush m_abstracttarget;
    86.  
    87.             public AbstractTarget3() : base(1, false, TargetFlags.None)
    88.             {
    89.  
    90.  
    91.             }
    92.  
    93.             protected override void OnTarget(Mobile from, object targeted)
    94.             {
    95.  
    96.                 if (targeted is Item)
    97.                 {
    98.                     Item subject = (Item)targeted;
    99.  
    100.                     subject.Name = "An abstract painting by " + m_Owner.Name.ToString();
    101.                     from.AddToBackpack(new AbstractPainting3());
    102.  
    103.                 }
    104.  
    105.                 else if (targeted is Static)
    106.                 {
    107.                     Static staticsubject = (Static)targeted;
    108.                     staticsubject.Name = "An abstract painting by" + m_Owner.Name.ToString();
    109.                     from.AddToBackpack(new AbstractPainting3());
    110.                 }
    111.  
    112.                 else
    113.                 {
    114.                     from.SendMessage("You cannot immagine an abstract of that!");
    115.                     return;
    116.                 }
    117.  
    118.             }
    119.  
    120.         }
    121.  
    I've attached all of the needed files for testing. I'd appreciate help with any or all of these questions. Thanks
     

    Attached Files:

    #1 Abracadabra2.0, Mar 18, 2017
    Last edited: Mar 19, 2017
  2. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    918
    Likes Received:
    137
    Try this for the abstract section:

    Code (C#):
    1.  
    2.         public class AbstractTarget1 : Target
    3.         {
    4.             public AbstractTarget1() : base(1, false, TargetFlags.None)
    5.             {
    6.             }
    7.             protected override void OnTarget(Mobile from, object targeted)
    8.             {
    9.                 if (targeted is Item)
    10.                 {
    11.                     Item subject = (Item)targeted;
    12.                    
    13.                     AbstractPainting1 painting = new AbstractPainting1();
    14.                     painting.Name = "An abstract painting by " + from.Name.ToString();
    15.                     from.AddToBackpack(painting);
    16.                 }
    17.                 else if (targeted is Static)
    18.                 {
    19.                     Static staticsubject = (Static)targeted;
    20.                    
    21.                     AbstractPainting1 painting = new AbstractPainting1();
    22.                     painting.Name = "An abstract painting by" + from.Name.ToString();
    23.                     from.AddToBackpack(painting);
    24.                 }
    25.                 else
    26.                 {
    27.                     from.SendMessage("You cannot immagine an abstract of that!");
    28.                     return;
    29.                 }
    30.             }
    31.         }
    I think the main problem you were having was that you were using a private variable named m_From, but you never set the value for that variable anywhere. Since the targeting constructor brings over the Mobile "from" anyway, you probably don't need it.
     
  3. Lokai
    Offline

    Moderator ServUO Developer

    Joined:
    Dec 4, 2014
    Messages:
    918
    Likes Received:
    137
    Also, you were setting the name of the targeted item to "An abstract painting..." I think you were intending to make that the name of the painting, not the new name for the targeted item.
     
  4. Abracadabra2.0
    Offline

    Joined:
    Sep 10, 2016
    Messages:
    72
    Likes Received:
    2
    Ok good to know, tyvm. I actually got some help elsewhere and managed to finish the script. It's undergoing quality testing now and if everything checks out I'll be releasing it to the community. Thanks for your help!
     
Similar Threads: Painting system
Forum Title Date
Custom Releases Painting System by Abracadabra Mar 26, 2017
Art Paintings - Lots Oct 5, 2017
Tutorials Creating Custom Paintings Oct 3, 2017
SA & High Seas Kings Collection Ship Paintings Mar 19, 2017
Script Support Fire Painting Mar 12, 2016
Tutorials Video Tutorial - Painting With Elements Feb 5, 2014
3rd Party Applications Cat's Jail System Friday at 9:30 PM