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