Author Topic: Help with chat bot.  (Read 974 times)

Making this chat bot because Im new to torque, not to be an idiot on servers.

Quote
$chatbot::greetTrigger = "hi hello hey yo hi! hello! yo! hallo";
$chatbot::greets = "SpyBot:_Whats up? SpyBot_How's it going_#name ? SpyBot:_Hey!";

$chatbot::farewellTrigger = "gtg bya bah bi by g2g bb bye cya";
$chatbot::farewells = "SpyBot:_Later_#name";

//$chatbot::randomTrigger = "Test"
//$chatbot::randoms = "SpyBot:_Testing complete...booting up!"

package Chatbot
{
   function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
   {
     Parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);

     if(%name == %name)
     {
      if(inStr(%msg,$chatbot::greetTrigger))
      {
         %ms = getWord($chatbot::greets,getRandom(0,getWordCount($chatbot::greets)-1));
         %ms = strReplace(%ms,"_","");
         %ms = strReplace(%ms,"#name",%name);
      }
      else
      
      if(inStr(%msg,$chatbot::farewellTrigger))

            {
            
                  %ms = getWord($chatbot::farewells,getRandom(0,getWordcount($chatbot::farewells)-1));
                  %ms = strReplace(%ms,"_"," ");
                  %ms = strReplace(%ms,"#name",%name);
      }
     }

     if(%msg $= "Chatbot Off" && %name $= $Pref::Player::Netname)
     {
      deactivatePackage(Chatbot);
     }
   }
};
activatepackage(Chatbot);

When I say "Hi" or "Chatbot off" it says unable to find function inStr in line 18 and 25

Wondering what I would do to fix this. I also want to add another trigger for Test, so that when I say "Test" it replys "Testing complete...booting up" Would I have to use switch instead of an if else?

replace inStr with strStr

Thanks. When I say "Chat bot off" it deactivates but if I type in "Hi" or "bye" nothing happens. I want it to respond to everyone with the triggers not just me.
« Last Edit: January 09, 2013, 03:59:39 PM by SlayerZ99 »

Because I don't think any message will have "hi hello hey yo hi! hello! yo! hallo" in it.

Because I don't think any message will have "hi hello hey yo hi! hello! yo! hallo" in it.
Oh, well haha. How would you make it so if you say any of those it will respond with 1 of my 3 greeting messages?

Because I don't think

You don't say?

Oh, well haha. How would you make it so if you say any of those it will respond with 1 of my 3 greeting messages?

Nah dont listen to zeblote. You need to use strstr instead of instr. Also if(%name == %name) is wrong. Firstly, you cant compare strings like that, secondly %name will always equal %name so that if statement is going to always return true.

To compare strings, use the $=. So "apple" $= "apple". If you want, add me on RTB and ill help you when i get home in a few hours.
« Last Edit: January 09, 2013, 05:42:27 PM by elm »

Add this to the if statements

Code: [Select]
if(%ms !$= "")
         {
            commandToServer('messageSent',%ms);
         }

Add this to the if statements

Code: [Select]
if(%ms !$= "")
         {
            commandToServer('messageSent',%ms);
         }
what incredibly obvious explanation am I missing here? Would this not cause you to echo everything you hear back to the server?

what incredibly obvious explanation am I missing here? Would this not cause you to echo everything you hear back to the server?
No, %ms is the outgoing message. %msg is the incoming message. He currently has no code to send %ms, just code to calculate it.

No, %ms is the outgoing message. %msg is the incoming message. He currently has no code to send %ms, just code to calculate it.
oops

Got most of it to work but when I say /on it not only says my startup trigger but my greeting trigger as well. It doesn't do this when I say /off though