Author Topic: Reading Words in a Sentence  (Read 670 times)

I'm having problems figuring out how to do the following:


$Answer[0] = "I'm AFK right now."
$Answer[1] = "I'm AFK at the moment."
$Answer[2] = "I'm AFK."
$Answer[3] = "AFK, ask me later."

package AFKBot
{
   function serverCmdMessageSent(%client, %text)
   {
      for (%i = 0; %i < getWordCount(%text); %i++)
      {
         %t = getWord(%text,%i);
         if (%t $= "#")
         {
            schedule(1000,0,messageAll,'',"<color:FFFF00>General<color:FFFFFF>: " @ $Answer[getRandom(3)]);
         }
      }
      parent::serverCmdMessageSent(%client, %text);
   }
};
activatePackage(AFKBot);



The code just checks for the word I enter where the red number symbol is, if the word is Hello and somebody says: "Hello, how's it going General?" It will return a message. I want it to check for two or more words in that sentence to return the message, for example: "Hello, how's it going General?" Both Hello and General...

I hope I made myself as clear as possible, help would be much appreciated. Thanks.
« Last Edit: July 16, 2010, 07:52:38 AM by General »

It should be getRandom(0,3);

It should be getRandom(0,3);
It doesn't have to be... It works the same either way

do
if(stripos(%text,%word) !$= -1 || stripos(%text,%Otherword) !$= -1)
{
    servercmdMessageSent(findclientbyname(General),$Answer[getRandom(3)]);
}

do
if(stripos(%text,%word) !$= -1 || stripos(%text,%Otherword) !$= -1)
{
    servercmdMessageSent(findclientbyname(General),$Answer[getRandom(3)]);
}
What I meant was that I want both words to be present in the sentence to display the message, not separated.

Never mind, I replaced || with && and it works. Thanks!