RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

[2.2]CleverAI

Bittiez

Sorceror
Ever seen CleverBot? Now you can talk to an npc in-game the same way you talk to CleverBot!

See the video here:

Installation:
Unzip to Scripts/Customs/CleverAI/

In-game:
[add CleverAI

Start talking!(Must be within 4 tiles)


See this post for a version that limits how fast players can talk to the bot.
 

Attachments

  • CleverAI.zip
    7.6 KB · Views: 69

Hammerhand

Knight
That reminds me of this one time on a server I staffed. We had a couple of drunken fool types on, so I was using the old Talk script on em'. One actually tried to make a date with an NPC because "it seemed to like her". Aahhh.. good times... :D
 

dazedmouse

Sorceror
Ok I have a smart butt on the shard that decided to put this through a test.... and ended up crashing the shard.. Once it got in that crash mode only way to stop it was to X out of the console... here is the report

Server Crash Report
===================

RunUO Version 2.1, Build 4780.39127
Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1
.NET Framework: 2.0.50727.5466
Time: 3/16/2013 8:48:10 AM
Mobiles: 13
Items: 3995
Exception:
System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at ChatterBotAPI.Utils.Post(String url, IDictionary`2 parameters)
at ChatterBotAPI.CleverbotSession.Think(ChatterBotThought thought)
at ChatterBotAPI.CleverbotSession.Think(String text)
at Bittiez.CleverBot.CleverAI.on_think(Object s)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)

And how they got it to crash was to type fast just letters like a b c d e f etc.
 

Bittiez

Sorceror
I was kind of worried about this, I won't be home for a couple of days but when I get home I'll fix it and add a limit to how fast people can talk to the bot
 

dazedmouse

Sorceror
Thank you..... This is a great script.... The people was so enjoying talking to it .... and I didnt want to toss script out....
 

Bittiez

Sorceror
If this works; This will only listen to players every 15 seconds, and just replace your CleverBot.cs with this(Make a backup incase I missed something)

Okay so I attempted to fix this on my tablets, but I can't test it so here is by attempt, let me know if it works: )

Now that I'm home I looked over the code and fixed it, this is working. It will only listen to a player every 15 seconds.
Code:
using Server;
using Server.Commands;
using ChatterBotAPI;
using System.Threading;
using System.Web;
using Server.Items;
using System;
using System.Collections.Generic;
 
 
namespace Bittiez.CleverBot
{
 
    public class CleverAI : Mobile
    {
        private ChatterBotFactory factory;
        private ChatterBot bot1;
        private ChatterBotSession bot1session;
        private List<chatter> chatters = new List<chatter>();
        public override bool HandlesOnSpeech(Mobile from)
        {
            if (from.Alive)
                return true;
            return base.HandlesOnSpeech(from);
        }
 
        public override void OnSpeech(SpeechEventArgs e)
        {
            if (e.Mobile.Alive && InRange(e.Mobile, 4) && listentomobile(e.Mobile))
            {
                Direction = GetDirectionTo(e.Mobile);
                ThinkIt(e.Speech);
            }
            else
            {
                //this.Say("No.. no.. I clean your house.");
            }
        }
 
        public CleverAI(Serial serial)
            : base(serial)
        {
        }
 
        [Constructable]
        public CleverAI()
        {
 
            factory = new ChatterBotFactory();
            bot1 = factory.Create(ChatterBotType.CLEVERBOT);
            bot1session = bot1.CreateSession();
 
            InitStats(100, 100, 25);
            Title = "the town blabber";
            Hue = Utility.RandomSkinHue();
 
            if (!Core.AOS)
                NameHue = 0x35;
 
            if (this.Female = Utility.RandomBool())
            {
                this.Body = 0x191;
                this.Name = NameList.RandomName("female");
            }
            else
            {
                this.Body = 0x190;
                this.Name = NameList.RandomName("male");
            }
 
            AddItem(new FancyShirt(Utility.RandomBlueHue()));
 
            Item skirt;
 
            switch (Utility.Random(2))
            {
                case 0: skirt = new Skirt(); break;
                default:
                case 1: skirt = new Kilt(); break;
            }
 
            skirt.Hue = Utility.RandomGreenHue();
 
            AddItem(skirt);
 
            AddItem(new FeatheredHat(Utility.RandomGreenHue()));
 
            Item boots;
 
            switch (Utility.Random(2))
            {
                case 0: boots = new Boots(); break;
                default:
                case 1: boots = new ThighBoots(); break;
            }
 
            AddItem(boots);
 
            Utility.AssignRandomHair(this);
        }
 
        public override bool CanBeDamaged()
        {
            return false;
        }
 
        public void ThinkIt(string s)
        {
            thoughargs ss = new thoughargs(s);
            ss.Text = s;
            Thread clientThread = new Thread(new ParameterizedThreadStart(on_think));
            clientThread.Start(ss);
        }
 
        public void on_think(object s)
        {
            if (s is thoughargs && bot1session != null)
            {
 
                thoughargs args = (thoughargs)s;
                string ss = bot1session.Think(args.Text);
                //Console.WriteLine(bot1session.Think(args.Text));
                this.Say("" + ss);
                //this.Say("[You Said: " + args.Text + "]");
            }
            else
            {
                factory = new ChatterBotFactory();
                bot1 = factory.Create(ChatterBotType.CLEVERBOT);
                bot1session = bot1.CreateSession();
                this.Say("No.. no.. More lemon pledge...");
            }
        }
 
        private bool listentomobile(Mobile from)
        {
            foreach (chatter ch in chatters)
            {
                if (ch.MOBILE == from)
                {
                    DateTime m = DateTime.UtcNow;
                    if (m > ch.LASTCHAT.AddSeconds(15))
                    {
                        ch.LASTCHAT = m;
                        return true;
                    }
                    else return false;
                }
            }
 
            chatters.Add(new chatter(from, DateTime.UtcNow));
            return true;
        }
 
 
        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();
            factory = new ChatterBotFactory();
            bot1 = factory.Create(ChatterBotType.CLEVERBOT);
            bot1session = bot1.CreateSession();
            if (Core.AOS && NameHue == 0x35)
                NameHue = -1;
        }
 
 
 
    }
 
    public class thoughargs
    {
        public string Text { get { return text; } set { text = value; } }
        private string text;
        public thoughargs(string txt)
        {
            text = txt;
        }
    }
 
    public class chatter
    {
        public Mobile MOBILE { get{return m;} set{m = value;} }
        private Mobile m;
        public DateTime LASTCHAT { get { return l; } set { l = value; } }
        private DateTime l;
        public chatter(Mobile mobile, DateTime datetime)
        {
            MOBILE = mobile;
            LASTCHAT = datetime;
        }
    }
}
 

dazedmouse

Sorceror
Got this error

Errors:
+ Customs/Custom Mobiles/CleverAI/CleverBot.cs:
CS0501: Line 191: 'Bittiez.CleverBot.chatter.MOBILE.get' must declare a body
because it is not marked abstract or extern
CS0501: Line 191: 'Bittiez.CleverBot.chatter.MOBILE.set' must declare a body
because it is not marked abstract or extern
CS0501: Line 192: 'Bittiez.CleverBot.chatter.LASTCHAT.get' must declare a bo
dy because it is not marked abstract or extern
CS0501: Line 192: 'Bittiez.CleverBot.chatter.LASTCHAT.set' must declare a bo
dy because it is not marked abstract or extern
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 

Bittiez

Sorceror
Got this error

Errors:
+ Customs/Custom Mobiles/CleverAI/CleverBot.cs:
CS0501: Line 191: 'Bittiez.CleverBot.chatter.MOBILE.get' must declare a body
because it is not marked abstract or extern
CS0501: Line 191: 'Bittiez.CleverBot.chatter.MOBILE.set' must declare a body
because it is not marked abstract or extern
CS0501: Line 192: 'Bittiez.CleverBot.chatter.LASTCHAT.get' must declare a bo
dy because it is not marked abstract or extern
CS0501: Line 192: 'Bittiez.CleverBot.chatter.LASTCHAT.set' must declare a bo
dy because it is not marked abstract or extern
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.


Try this:
Code:
using Server;
using Server.Commands;
using ChatterBotAPI;
using System.Threading;
using System.Web;
using Server.Items;
using System;
using System.Collections.Generic;
 
 
namespace Bittiez.CleverBot
{
 
    public class CleverAI : Mobile
    {
        private ChatterBotFactory factory;
        private ChatterBot bot1;
        private ChatterBotSession bot1session;
        private List<chatter> chatters = new List<chatter>();
        public override bool HandlesOnSpeech(Mobile from)
        {
            if (from.Alive)
                return true;
            return base.HandlesOnSpeech(from);
        }
 
        public override void OnSpeech(SpeechEventArgs e)
        {
            if (e.Mobile.Alive && InRange(e.Mobile, 4) && listentomobile(e.Mobile))
            {
                Direction = GetDirectionTo(e.Mobile);
                ThinkIt(e.Speech);
            }
            else
            {
                //this.Say("No.. no.. I clean your house.");
            }
        }
 
        public CleverAI(Serial serial)
            : base(serial)
        {
        }
 
        [Constructable]
        public CleverAI()
        {
 
            factory = new ChatterBotFactory();
            bot1 = factory.Create(ChatterBotType.CLEVERBOT);
            bot1session = bot1.CreateSession();
 
            InitStats(100, 100, 25);
            Title = "the town blabber";
            Hue = Utility.RandomSkinHue();
 
            if (!Core.AOS)
                NameHue = 0x35;
 
            if (this.Female = Utility.RandomBool())
            {
                this.Body = 0x191;
                this.Name = NameList.RandomName("female");
            }
            else
            {
                this.Body = 0x190;
                this.Name = NameList.RandomName("male");
            }
 
            AddItem(new FancyShirt(Utility.RandomBlueHue()));
 
            Item skirt;
 
            switch (Utility.Random(2))
            {
                case 0: skirt = new Skirt(); break;
                default:
                case 1: skirt = new Kilt(); break;
            }
 
            skirt.Hue = Utility.RandomGreenHue();
 
            AddItem(skirt);
 
            AddItem(new FeatheredHat(Utility.RandomGreenHue()));
 
            Item boots;
 
            switch (Utility.Random(2))
            {
                case 0: boots = new Boots(); break;
                default:
                case 1: boots = new ThighBoots(); break;
            }
 
            AddItem(boots);
 
            Utility.AssignRandomHair(this);
        }
 
        public override bool CanBeDamaged()
        {
            return false;
        }
 
        public void ThinkIt(string s)
        {
            thoughargs ss = new thoughargs(s);
            ss.Text = s;
            Thread clientThread = new Thread(new ParameterizedThreadStart(on_think));
            clientThread.Start(ss);
        }
 
        public void on_think(object s)
        {
            if (s is thoughargs && bot1session != null)
            {
 
                thoughargs args = (thoughargs)s;
                string ss = bot1session.Think(args.Text);
                //Console.WriteLine(bot1session.Think(args.Text));
                this.Say("" + ss);
                //this.Say("[You Said: " + args.Text + "]");
            }
            else
            {
                factory = new ChatterBotFactory();
                bot1 = factory.Create(ChatterBotType.CLEVERBOT);
                bot1session = bot1.CreateSession();
                this.Say("No.. no.. More lemon pledge...");
            }
        }
 
        private bool listentomobile(Mobile from)
        {
            foreach (chatter ch in chatters)
            {
                if (ch.MOBILE == from)
                {
                    DateTime m = DateTime.UtcNow;
                    if (m > ch.LASTCHAT.AddSeconds(15))
                    {
                        ch.LASTCHAT = m;
                        return true;
                    }
                    else return false;
                }
            }
 
            chatters.Add(new chatter(from, DateTime.UtcNow));
            return true;
        }
 
 
        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();
            factory = new ChatterBotFactory();
            bot1 = factory.Create(ChatterBotType.CLEVERBOT);
            bot1session = bot1.CreateSession();
            if (Core.AOS && NameHue == 0x35)
                NameHue = -1;
        }
 
 
 
    }
 
    public class thoughargs
    {
        public string Text { get { return text; } set { text = value; } }
        private string text;
        public thoughargs(string txt)
        {
            text = txt;
        }
    }
 
    public class chatter
    {
        public Mobile MOBILE { get{return m;} set{m = value;} }
        private Mobile m;
        public DateTime LASTCHAT { get { return l; } set { l = value; } }
        private DateTime l;
        public chatter(Mobile mobile, DateTime datetime)
        {
            MOBILE = mobile;
            LASTCHAT = datetime;
        }
    }
}
 
Top