Blockland Forums > Modification Help

Chat Bot Help

Pages: << < (2/12) > >>

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)


//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;
}


¥ola:


--- Quote from: elm on June 11, 2012, 04:42:19 PM ---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-

--- End quote ---

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

¥ola:

How would I add delays to the responses?
As in

RandomPlayer: Hey

30second delay

Yola: ChatBot: Hey!

Ipquarx:

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.

¥ola:


--- Quote from: Ipquarx on June 11, 2012, 04:59:23 PM ---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.

--- End quote ---
Thank you

Pages: << < (2/12) > >>

Go to full version