Author Topic: Chat Bot Help  (Read 4327 times)

One last time, I got my last chat bot to work but now I'm trying to figure something else out.

What is an efficient way so that this is possible:

Randomperson: Hey ChatBot
Yola: ChatBot: Hey

In other words,
How would I get a chat message to send a
commandToServer('messageSent', "message");

I mean efficient as in I'm going to repeat this multiple times, as in for different chat messages (ex. "Hey", "Whats Up?")

check every chat message, make a switch for different cases like "hey" or "what's up" or whatever, then compare what was said to the cases and send your message

Correctly using a switch?

Code: [Select]
package ChatBot
{
function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
{
Parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if($ChatBotActive)
{
switch$(%msg)
{

case "ChatBot On":
commandToServer('messagesent', "ChatBot: Turning On");

case "ChatBot Off":
commandToServer('messagesent', "ChatBot: Turning Off");

Yes I realize that it's not actually turning it on and off

I am confused, what is your problem here?

No problem, wondering how to do this correctly,
Am I using the switch correctly?

Here is how I would make a chat bot (but a lot more advanced if I was going to as I whipped this up in like 5 minutes). It allows for more responses and less ifs/cases to be used.

(i didn't test this)


//triggers our chat bot when someone says one of these words
$chatbot::greetTrigger = "hi hello whatsup howdy hiya hai helo hey";
//our chat bot picks one of these responses, same follows below
$chatbot::greets = "hi hello_#name whatsup_#name howdy hiya hai hey";

$chatbot::farewellTrigger = "bye cya g2g bb";
$chatbot::farewells = "bye_bye_#name cya_#name bye bai_#name  bb farewell_#name";

$chatbot::funnyTrigger = "lol haha lolz rofl lmao";
$chatbot::funnys = "haha_that's_funny_#name lol_what_#name? #name,_i_dont_get_it..";

package ChatBot
{
   function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
   {
      Parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
      
      if($chatbotActive)
      {
         //check if %msg contains any word from our greet trigger variable
         if(inStr(%msg,$chatbot::greetTrigger))
         {
            //pick a random word from our greets variable
            %ms = getWord($chatbot::greets,getRandom(0,getWordCount($chatbot::greets)-1));
            %ms = strReplace(%ms,"_"," ");
            %ms = strReplace(%ms,"#name",%name);
         }
         else
         //check if %msg contains any word from our farewell trigger variable
         if(inStr(%msg,$chatbot::farewellTrigger))
         {
            //pick a random word from our farewells variable
            %ms = getWord($chatbot::farewells,getRandom(0,getWordcount($chatbot::farewells)-1));
            %ms = strReplace(%ms,"_"," ");
            %ms = strReplace(%ms,"#name",%name);
         }
         else
         if(inStr(%msg,$chatbot::funnyTrigger))
         {
            %ms = getWord($chatbot::funnys,getRandom(0,getWordcount($chatbot::funnys)-1));
            %ms = strReplace(%ms,"_"," ");
            %ms = strReplace(%ms,"#name",%name);
         }
         
         if(%ms !$= "")
         {
            //should check if it is the same as the last message you sent
            //to avoid chat penalties.
            commandToServer('messageSent',%ms);
         }
      }
   }
};

function inStr(%string,%case)
{
   for(%i=0;%i<getWordCount(%string);%i++)
   {
      %w = getWord(%string,%i);
      
      for(%j=0;%j<getWordCount(%case);%j++)
      {
         %sw = getWord(%case,%j);
         
         if(%w $= %sw)
            return true;
      }
   }
   return false;
}
« Last Edit: June 11, 2012, 04:53:41 PM by elm »

Here is how I would make a chat bot (but a lot more advanced if I was going to as I whipped this up in like 5 minutes). It allows for more responses and less ifs/cases to be used.

(i didn't test this)

-snip-

Love this idea, I had something just like this all planned out for greets/goodbyes

How would I add delays to the responses?
As in

RandomPlayer: Hey

30second delay

Yola: ChatBot: Hey!

30 seconds hawly sheets batman!

Just create a function to do the greet, let's say it's named THCIATHEFUNCTIONUSEDTOGREETPEOPLE.

Then create a schedule, and put the function inside it, like this:
schedule(%delay, 0, THCIATHEFUNCTIONUSEDTOGREETPE OPLE);

You'll have to take the space out of that because for some reason it added one automatically.

30 seconds hawly sheets batman!

Just create a function to do the greet, let's say it's named THCIATHEFUNCTIONUSEDTOGREETPEOPLE.

Then create a schedule, and put the function inside it, like this:
schedule(%delay, 0, THCIATHEFUNCTIONUSEDTOGREETPE OPLE);

You'll have to take the space out of that because for some reason it added one automatically.
Thank you


Add this under inStr:


function chatBot_Talk(%msg)
{
   commandToServer('messageSent',%msg);
}


then erase the old commandtoserver('messagsent..
and put this in it's place:


            %delay = getRandom(100,2000);
            schedule(%delay,0,chatBot_talk,%ms);

One last thing,
is this a correct if statement after the clientcmdchatmessage?

Code: [Select]
if(%name == ¥ola)

One last thing,
is this a correct if statement after the clientcmdchatmessage?

Code: [Select]
if(%name == ¥ola)

== in torque script is not used to compare strings, it's generally used to compare integers and things of that sort. To compare strings we use $= (does string equal?) so "hi" $= "hello", etc.

== in torque script is not used to compare strings, it's generally used for integers and things of that sourt. To compare strings we use $= (does string equal?) so "hi" $= "hello", etc.
Okay thank you a lot for that, but I was talking more along the lines of will it recognize the ¥ in my name

Okay thank you a lot for that, but I was talking more along the lines of will it recognize the ¥ in my name

Yes, if you do %name $= "¥ola"