Author Topic: Chat bot not working like it should  (Read 1537 times)

I wanted to create a chat bot, and I got most of it down. Here is the raw code for it.
Code: [Select]
$chatBot::name = "ColBot";
 
$chatBot::response["hi"] = "ayy wassup ayy_wassup hola_amigo hola hi,_and_welcome_to_the_server";
$chatBot::response["yo"] = "ayy wassup ayy_wassup hola_amigo hola hi,_and_welcome_to_the_server";
$chatBot::response["ayy"] = "ayy wassup ayy_wassup hola_amigo hola hi,_and_welcome_to_the_server";
$chatBot::response["lol"] = "TOP_KEK! kek rofl lmao lel its_not_funny_stfu";
$chatBot::response["kek"] = "TOP_KEK! kek rofl lmao lel its_not_funny_stfu";
$chatBot::response["lmao"] = "TOP_KEK! kek rofl lmao lel its_not_funny_stfu";
$chatBot::response["lel"] = "TOP_KEK! kek rofl lmao lel its_not_funny_stfu";
$chatBot::response["rofl"] = "TOP_KEK! kek rofl lmao lel its_not_funny_stfu";
$chatBot::response["ur_gey"] = "no_u ok only_for_col_<3 sorry_for_the_inconvenience";
$chatBot::response["ur_gay"] = "no_u ok only_for_col_<3 sorry_for_the_inconvenience";
$chatBot::response["you're_gay"] = "no_u ok only_for_col_<3 sorry_for_the_inconvenience";
$chatBot::response["wtf"] = "whats_your_problem_>.> what lmao_u_mad?";
$chatBot::response["the_forget?"] = "whats_the_problem? what ?";
$chatBot::response["what_the_forget?"] = "whats_the_problem? what ?";
$chatBot::response["the_forget"] = "whats_your_problem_>.> what lmao_u_mad?";
$chatBot::response["what_the_forget"] = "whats_your_problem_>.> what lmao_u_mad?";
 
 
 
$chatBot::timeOut = 5000;
 
 
package chatBot
{
       
        function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
        {
                parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
               
                if(%name !$= $pref::Player::NetName)
                {
                        %msg = stripMlControlChars(%msg);
                       
                        %hasTrigger = chatBot_messageHasTriggerWord(%msg);
                       
                        if(%hasTrigger !$= "0")
                        {
                                %phrase = chatBot_getRandomPhraseFromWord(%hasTrigger);
                                chatBot_say(%phrase);
                        }
                }
        }
};
activatePackage(chatBot);
 
 
function chatBot_getRandomPhraseFromWord(%word)
{
        %phrases = $chatBot::response[%word];
       
        if(%phrases !$= "")
        {
                %count = getWordCount(%phrases);
                %ranPhrase = getWord(%phrases,getRandom(0,%count));
                %ranPhrase = strReplace(%ranPhrase,"_"," ");
               
                return %ranPhrase;
        }
        else
                return false;
}
 
 
function chatBot_messageHasTriggerWord(%string)
{
        %wordCount = getWordCount(%string);
       
        for(%i=0;%i<%wordCount;%i++)
        {
                %word = getWord(%string,%i);
               
                if($chatBot::response[%word] !$= "")
                {
                        return %word;
                }
        }
        return false;
}
 
 
function chatBot_say(%string)
{
        %time = getSimTime();
       
        if(%time - $chatBot::lastTalkTime >= $chatBot::timeOut)
        {
                if($chatBot::lastTalkMessage $= %string)
                {
                        error("Our chatbot will trigger the flood protection, returning false");
                        return false;
                }
                else
                {
                        commandToServer('messageSent',$chatBot::name @ " => " @ %string);
                        $chatBot::lastTalkMessage = %string;
                        $chatBot::lastTalkTime = %time;
                }
               
                return true;
        }
        return false;
}

The only problem with it, is when I trigger it using 'hi' or 'lel' it doesn't say
Quote
ColBot: (return phrase)
it says
Quote
Col. Burton: ColBot => (return phrase)

Again, it works, and I can trigger it in my server. I'm just not entirely sure how to get it to say
Quote
ColBot: (return phrase)

Any help would be appreciated.

You can't do this on other peoples' servers, and you don't want to be able to do it on your own.

commandToServer('messageSent', "Col. Burton" @ " => " @ " I hope nobody else can forge names with thiDISREGARD THAT I SUCK roosterS");



In the picture above I was responding to a chat bot that was made for me a while ago, named MidnaBot (I could change the name if I wanted to), and it chose random words from the conversations in the server. It would then place those words together into mindless phrases that it would send at any given time (it had a timeout of 10000). I'm trying to recreate that bot, or a bot similar to it.

are you trying to make it a server addon or a client addon?
if it's a server addon, you can replace commandToServer('messageSent',$chatBot::name @ " => " @ %string); with something to message all the clients in the server
if it's a client addon, you can't do the ColBot: phrase as you want, since it's just going to be just like you saying something (it'll have your name first)

are you trying to make it a server addon
This is exactly what i'm trying to do.
if it's a server addon, you can replace commandToServer('messageSent',$chatBot::name @ " => " @ %string); with something to message all the clients in the server
How can I go about doing that?

messageAll('MsgAdminForce', '<color:ffff00>%1 <color:ffffff>loaded backup <color:ffff00>#%2<color:ffffff>.', %client.name, %option);
some code from something i'm coding
it prints to everybody and plays the admin sound

messageAll('', %string); will send a chat message with %string to everyone. Note the marks are two ' s, not one "

If you want it to be server sided then you also need to change your packaged function to serverCmdMessageSent(%client, %msg) and modify it appropriately.