HowToMake Talking NPCs with Titles Who can Teach

  • If you would like to submit a tutorial please visit the main tutorial page here.
    You can not submit them from this forum.

Omegaexdeath

Well-Known Member
Nov 9, 2014
111
13
MI USA
Shard Name
EternalDeathSlayer EDS UO PvP
Donate
Donate money to this user
So I cant remember where I found how to do this stuff but its gotta give something back day so here it is how to make Talking NPCS with Titles who can also teach you useful skills (title long enough) can also see how to add clothing armor with custom hues etc,

my Duma Script

Code:
using System;
using Server;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using Server.ContextMenus;
using System.Collections.Generic;

namespace Server.Mobiles
{
    public class Duma : BaseCreature
    {

        public override bool CanTeach { get { return true; } }

        private static bool m_Talked;

        string[] kfcsay = new string[]
        {
        "As I foretold you, we are all spirits, and are melted into air, into thin air...",
        "Are you sure/That we are awake? It seems to me/That yet we sleep, we dream.",
        "I have had a most rare vision. I have had a dream, past the wit of man to say what dream it was.",
        "“Five minutes are enough to dream a whole life, that is how relative time is.",
        "When we can't dream any longer we die.",
        "I have in me all the dreams in the world.",
        "All human beings are also dream beings. Dreaming ties all mankind together.",
        "Ah, it's my longing for whom I might have been that distracts and torments me!",
        "Dreams are the language of God."
        };

       

        [Constructable]
        public Duma()
            : base(AIType.AI_Melee, FightMode.None, 10, 1, 0.8, 3.0)
        {
            {
                this.Body = 605;
                this.Name = "Duma";
                SpeechHue = Utility.RandomDyedHue();
                Hue = 1280;
                Item hair = new Item(Utility.RandomList(0x2FC2, 0x2FC2));
                hair.Hue = 1297;
                hair.Layer = Layer.Hair;
                hair.Movable = false;
                AddItem(hair);
            }
            {
                SetStr(100);
                SetDex(100);
                SetInt(100);

                Fame = 50;
                Karma = 50;

              
                SetSkill(SkillName.Discordance, 60.0, 70.0);
            }
            {

                Container pack = new Backpack();
                pack.DropItem(new Gold(0, 50));
                pack.Movable = false;
                AddItem(pack);
            }
            {
                Item PlateGorget = new PlateGorget();
                PlateGorget.Hue = 1990;
                PlateGorget.Movable = false;
                AddItem(PlateGorget);
            }
            {
                Item PlateChest = new PlateChest();
                PlateChest.Hue = 1990;
                PlateChest.Movable = false;
                AddItem(PlateChest);
            }
            {
                Item PlateArms = new PlateArms();
                PlateArms.Hue = 1990;
                PlateArms.Movable = false;
                AddItem(PlateArms);
            }
            {
                Item PlateGloves = new PlateGloves();
                PlateGloves.Hue = 1990;
                PlateGloves.Movable = false;
                AddItem(PlateGloves);
            }
            {
                Item PlateLegs = new PlateLegs();
                PlateLegs.Hue = 1990;
                PlateLegs.Movable = false;
                AddItem(PlateLegs);
            }

        }

        public override void AddNameProperties(ObjectPropertyList list)
        {
            base.AddNameProperties(list);

            List<string> lines = new List<string>();

            lines.Add(String.Format("AngelOfDarkness", 1));
            lines.Add(String.Format("Prince Of Dreams", 2));
            lines.Add(String.Format("4th Circle", 3));
            //lines.Add(String.Format("", 3));
            //lines.Add("My String 4");

            list.Add(String.Join("<br>", lines)); // Output: "My String 1<br>My String 2<br>My String 3<br>My String 4"
        }

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

        public override void OnMovement(Mobile m, Point3D oldLocation)
        {
            if (m_Talked == false)
            {
                if (m.InRange(this, 1))
                {
                    m_Talked = true;
                    SayRandom(kfcsay, this);
                    this.Move(GetDirectionTo(m.Location));
                    SpamTimer t = new SpamTimer();
                    t.Start();
                }
            }
        }

        private class SpamTimer : Timer
        {
            public SpamTimer()
                : base(TimeSpan.FromSeconds(10))
            {
                Priority = TimerPriority.OneSecond;
            }

            protected override void OnTick()
            {
                m_Talked = false;
            }
        }

        private static void SayRandom(string[] say, Mobile m)
        {
            m.Say(say[Utility.Random(say.Length)]);
        }

        private static int GetRandomHue()
        {
            switch (Utility.Random(6))
            {
                default:
                case 0: return 0;
                case 1: return Utility.RandomBlueHue();
                case 2: return Utility.RandomGreenHue();
                case 3: return Utility.RandomRedHue();
                case 4: return Utility.RandomYellowHue();
                case 5: return Utility.RandomNeutralHue();
            }
        }

        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();
        }
    }
}
Parts explained


add this to allow a npc to teach skills
Code:
public override bool CanTeach { get { return true; } }
add the setskill just after your karma & fame
Code:
SetSkill(SkillName.Discordance, 60.0, 70.0);

this will trigger a random phrase from your list when a player or even another npc walks within range
add this just below your class or after CanTeach if it can teach.

Code:
private static bool m_Talked;

        string[] kfcsay = new string[]
        {
        "As I foretold you, we are all spirits, and are melted into air, into thin air...",
        "Are you sure/That we are awake? It seems to me/That yet we sleep, we dream.",
        "I have had a most rare vision. I have had a dream, past the wit of man to say what dream it was.",
        "“Five minutes are enough to dream a whole life, that is how relative time is.",
        "When we can't dream any longer we die.",
        "I have in me all the dreams in the world.",
        "All human beings are also dream beings. Dreaming ties all mankind together.",
        "Ah, it's my longing for whom I might have been that distracts and torments me!",
        "Dreams are the language of God."
        };

This will create a list that shows under its name on mouse over
add this just after your moblies stats & gear
Code:
public override void AddNameProperties(ObjectPropertyList list)
        {
            base.AddNameProperties(list);

            List<string> lines = new List<string>();

            lines.Add(String.Format("AngelOfDarkness", 1));
            lines.Add(String.Format("Prince Of Dreams", 2));
            lines.Add(String.Format("4th Circle", 3));
            //lines.Add(String.Format("", 3));
            //lines.Add("My String 4");

            list.Add(String.Join("<br>", lines)); // Output: "My String 1<br>My String 2<br>My String 3<br>My String 4"
        }





Just below this
Code:
public Duma(Serial serial)
            : base(serial)
        {
        }
add this
Code:
 public override void OnMovement(Mobile m, Point3D oldLocation)
        {
            if (m_Talked == false)
            {
                if (m.InRange(this, 1))
                {
                    m_Talked = true;
                    SayRandom(kfcsay, this);
                    this.Move(GetDirectionTo(m.Location));
                    SpamTimer t = new SpamTimer();
                    t.Start();
                }
            }
        }

        private class SpamTimer : Timer
        {
            public SpamTimer()
                : base(TimeSpan.FromSeconds(10))
            {
                Priority = TimerPriority.OneSecond;
            }

            protected override void OnTick()
            {
                m_Talked = false;
            }
        }

        private static void SayRandom(string[] say, Mobile m)
        {
            m.Say(say[Utility.Random(say.Length)]);
        }

        private static int GetRandomHue()
        {
            switch (Utility.Random(6))
            {
                default:
                case 0: return 0;
                case 1: return Utility.RandomBlueHue();
                case 2: return Utility.RandomGreenHue();
                case 3: return Utility.RandomRedHue();
                case 4: return Utility.RandomYellowHue();
                case 5: return Utility.RandomNeutralHue();
            }
        }

this will make your npcs talk text different colour after each respawn
& is needed to work properly

& there you go Talking Titled Teaching NPC just change the phrases & titles to fit your needs

if anybody sees fit to improve upon these script edits post it up please or if youve found different better ways to customize NPCs please share it Have Fun You Crazy Kids:D
 
  • Like
Reactions: Greed

Exale

Well-Known Member
Mar 2, 2014
182
16
37
Wisconsin
Shard Name
Mystical Nights
Dude, awesome freaking tutorial. I have dabbled a bit with talking NPCs but this is really going help expand on that.
 

Anomaly

Well-Known Member
Mar 9, 2014
47
5
29
Augusta, Georgia
Shard Name
Elanmire
Thanks for posting this- this is going to come in handy to reference for what i am working on.
+10 points from saving me from posting a support thread.