Vert-I-Go

Member
ServUO Version
Publish Unknown
Ultima Expansion
None
Ok so I have an Item it insta tames a creature. The creature is on the water now when you double click the item you target the creature bam insta tame works fine, but what i would like is that the creature would then be moved right next to you, because you would be on a boat of course. here is code. doesnt have to be super complex just need said creature to when targeted and sucessful it moved next to the control master.
THIS is in testing phase so stil playing around with it.
item code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;

namespace Server.Items
{
    public class GoldenCoral : Item
        {
        [Constructable]
        public GoldenCoral() : base(0xB14C)
        {
                    Weight = 1.0;
                    Name = "a piece of golden coral";
                }

            public GoldenCoral(Serial serial) : base(serial)
            {
            }

            public override void Serialize(GenericWriter writer)
            {
                    base.Serialize(writer);

                    writer.Write((int)0); // version
            }

            public override void Deserialize(GenericReader reader)
            {
                    base.Deserialize(reader);
                   
                    int version = reader.ReadInt();
            }

                public override void OnDoubleClick(Mobile from)
            {
                    if ( !IsChildOf( from.Backpack ) )
            {
                from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
            }
            else
                    {
                        from.SendMessage("Target the animal or beast you wish to instantly tame.");
                        from.Target = new CoralTarget(this);
                    }
            }
        }

        public class CoralTarget : Target
        {
            private GoldenCoral m_Coral;
           
            public CoralTarget( GoldenCoral coral = null) : base(15, false, TargetFlags.None )
            {
                    if (coral != null)
                    {
                        m_Coral = coral;
                    }
                }

             protected override void OnTarget(Mobile from, object target)
            {
                    if (target is BaseTameable)
                    {
                        BaseTameable t = (BaseTameable)target;

                        //if (t.ControlMaster != null)
                        //{
                                //from.SendMessage("That pet belongs to someone else!");
                        //}
                if ( !t.Controlled || t.ControlMaster != from || t.IsBonded == false )
                {
                    from.SendLocalizedMessage( 1063737 ); // You can only use this gem on a tamed pet that you own.
                }
                        else if (t.Tamable == false)
                        {
                                from.SendMessage("That creature cannot be tamed!");
                        }
                else
                        {
                                t.RawStr = t.RawStr / 2;
                                t.RawInt = t.RawInt / 2;
                                t.RawDex = t.RawDex / 2;
                                t.HitsMaxSeed = t.HitsMaxSeed / 2;
                    t.Hits = t.Hits / 2;
                                t.Controlled = true;
                                t.ControlMaster = from;
                                from.SendMessage("You have instantly tamed your target.");

                                if (m_Coral != null)
                                {
                                    m_Coral.Delete(); // Delete the coral
                                }
                            }
                    }
            if (target is DeepSeaSahuagin)
            {
                DeepSeaSahuagin d = (DeepSeaSahuagin)target;

                        if (d.ControlMaster != null)
                        {
                                from.SendMessage("That pet belongs to someone else!");
                        }
                else
                        {
                                d.Controlled = true;
                                d.ControlMaster = from;
                                from.SendMessage("You have instantly tamed your target.");

                                if (m_Coral != null)
                                {
                                    m_Coral.Delete(); // Delete the coral
                                }
                }
            }
                    else
                    {
                        from.SendMessage("That is not a valid target.");
                    }
            }
        }
}
 
Basically what Juzzver already wrote,

but I reorganized the method a little. This way you do not have to write the same code twice for BaseTameable and DeepSeaSahuagin.

Since I didnt know if it should only work on anything you derive from BaseTameable, or if there are BaseTamable classes that are not children of BaseCreature I left it as this.

If all BaseTameables are BaseCreature, then you could also change the if at the bottom

C#:
        protected override void OnTarget(Mobile from, object target)
        {
            if (m_Coral == null) return;

            BaseCreature bc = target as BaseCreature;

            if (bc == null || bc.Summoned)
            {
                from.SendMessage("That is not a valid target.");
                return;
            }
            if (!bc.Tamable)
            {
                from.SendMessage("That creature cannot be tamed!");
                return;
            }
            if (bc.ControlMaster != null && bc.ControlMaster != from)
            {
                from.SendMessage("That pet belongs to someone else!");
                return;
            }
            /*
             * I left it in, but this seems to be wrong? I mean the message does not fit
             * and also it would hit every time on your valid targets?
             *
            if (!bc.Controlled || bc.ControlMaster != from || bc.IsBonded == false)
            {
                from.SendLocalizedMessage(1063737); // You can only use this gem on a tamed pet that you own.
                return;
            }*/

            if (target is BaseTameable || target is DeepSeaSahuagin dss)
            {
                if (dss == null)
                {
                    bc.RawStr = bc.RawStr / 2;
                    bc.RawInt = bc.RawInt / 2;
                    bc.RawDex = bc.RawDex / 2;
                    bc.HitsMaxSeed = bc.HitsMaxSeed / 2;
                    bc.Hits = bc.Hits / 2;
                }
                bc.SetControlMaster(from);
                from.SendMessage("You have instantly tamed your target.");

                bc.MoveToWorld(from.Location, from.Map);

                m_Coral.Consume(); // Consume the coral
            }
        }
 

Donations

Total amount
$35.00
Goal
$500.00

Active Shards

Back