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:
Server Crash Report
===================

RunUO Version 2.6, Build 0.13549
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.42000
Time: 3/19/2017 12:21:43 AM
Mobiles: 17107
Items: 144434
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Gumps.PaintingGump.AbstractTarget1.OnTarget(Mobile from, Object targeted)
   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
   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
   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
   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
   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

Here is the way I did that particular targeting method:
Code:
public class AbstractTarget1 : Target
        {
            private Mobile m_Owner;
            private PaintBrush m_abstracttarget;

            public AbstractTarget1() : base(1, false, TargetFlags.None)
            {
                        

            }

            protected override void OnTarget(Mobile from, object targeted)
            {

                if (targeted is Item)
                {
                    Item subject = (Item)targeted;
                                              
                        subject.Name = "An abstract painting by " + m_Owner.Name.ToString();
                        from.AddToBackpack(new AbstractPainting1());
                  
                }

                else if (targeted is Static)
                {
                    Static staticsubject = (Static)targeted;
                    staticsubject.Name = "An abstract painting by" + m_Owner.Name.ToString();
                    from.AddToBackpack(new AbstractPainting1());
                }

                else
                {
                    from.SendMessage("You cannot immagine an abstract of that!");
                    return;
                }

            }

        }

        public class AbstractTarget2 : Target
        {
            private Mobile m_Owner;
            private PaintBrush m_abstracttarget;

            public AbstractTarget2() : base(1, false, TargetFlags.None)
            {


            }

            protected override void OnTarget(Mobile from, object targeted)
            {

                if (targeted is Item)
                {
                    Item subject = (Item)targeted;

                    subject.Name = "An abstract painting by " + m_Owner.Name.ToString();
                    from.AddToBackpack(new AbstractPainting2());

                }

                else if (targeted is Static)
                {
                    Static staticsubject = (Static)targeted;
                    staticsubject.Name = "An abstract painting by" + m_Owner.Name.ToString();
                    from.AddToBackpack(new AbstractPainting2());
                }

                else
                {
                    from.SendMessage("You cannot immagine an abstract of that!");
                    return;
                }

            }

        }

        public class AbstractTarget3 : Target
        {
            private Mobile m_Owner;
            private PaintBrush m_abstracttarget;

            public AbstractTarget3() : base(1, false, TargetFlags.None)
            {


            }

            protected override void OnTarget(Mobile from, object targeted)
            {

                if (targeted is Item)
                {
                    Item subject = (Item)targeted;

                    subject.Name = "An abstract painting by " + m_Owner.Name.ToString();
                    from.AddToBackpack(new AbstractPainting3());

                }

                else if (targeted is Static)
                {
                    Static staticsubject = (Static)targeted;
                    staticsubject.Name = "An abstract painting by" + m_Owner.Name.ToString();
                    from.AddToBackpack(new AbstractPainting3());
                }

                else
                {
                    from.SendMessage("You cannot immagine an abstract of that!");
                    return;
                }

            }

        }

I've attached all of the needed files for testing. I'd appreciate help with any or all of these questions. Thanks
 

Attachments

  • Painting.zip
    9.8 KB · Views: 2
Last edited:
Try this for the abstract section:

Code:
        public class AbstractTarget1 : Target
        {
            public AbstractTarget1() : base(1, false, TargetFlags.None)
            {
            }
            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted is Item)
                {
                    Item subject = (Item)targeted;
                   
                    AbstractPainting1 painting = new AbstractPainting1();
                    painting.Name = "An abstract painting by " + from.Name.ToString();
                    from.AddToBackpack(painting);
                }
                else if (targeted is Static)
                {
                    Static staticsubject = (Static)targeted;
                   
                    AbstractPainting1 painting = new AbstractPainting1();
                    painting.Name = "An abstract painting by" + from.Name.ToString();
                    from.AddToBackpack(painting);
                }
                else
                {
                    from.SendMessage("You cannot immagine an abstract of that!");
                    return;
                }
            }
        }

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.
 
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.
 
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.

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!
 
Back