Author Topic: Chat Bot Problem  (Read 1605 times)

I tried the following code and the      if (%name $= "jes00") is not working.

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
                switch$(%msg)
                {
                        case "Test":
     if (%name $= "jes00")
                               commandToServer('messageSent',"Test: Success!");
                        case "Hi":
                              commandToServer('messageSent',"Hi");
                        case "the muffin smells good!":
                                commandtoserver('messagesent',"It does indeed!");
                        case "Goodbye":
                                commandtoserver('messagesent',"Goodbye.");
                }
}

};
activatePackage(chatbot);

That is wrong.

this is minus the switch. (I hate switches so much)

Code: [Select]
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)
{
//Writes a line in the console
//so check your console to see
//if it worked
//--------

error("Testing worked.");

//--------
}
}

};
activatePackage(chatbot);

That is wrong.

this is minus the switch. (I hate switches so much)

Code: [Select]
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)
{
//Writes a line in the console
//so check your console to see
//if it worked
//--------

error("Testing worked.");

//--------
}
}

};
activatePackage(chatbot);
Umm now I'm just confused.

You have if(%name $= "jes") or whatever, but nothing under it.. and it's just in an awkward spot.

What i wrote is saying * if %name is equal to whatever your current blockland name is, write in the console "Testing worked." *

You have if(%name $= "jes") or whatever, but nothing under it.. and it's just in an awkward spot.

What i wrote is saying * if %name is equal to whatever your current blockland name is, write in the console "Testing worked." *
But I only want it to check if it's me in the case of someone saying Test.

$pref::Player::NetName is your name.

$pref::Player::NetName is your name.
But I only want it to check if it's me in the case of someone saying Test.

i'm pretty sure switch lines can only be one line, but i might be wrong
Code: [Select]
case "Test":
    checkTest(%name);

...


function checkTest(%arg) {
    if(%arg $= $pref::Player::NetName)
        commandtoserver('messagesent',"Testing worked.");
}
i still might be wrong.


also, of course define the function outside of the other function.


Have seen alot of ppl with Package Chatbot now.

i'm pretty sure switch lines can only be one line, but i might be wrong
case "Test":
    checkTest(%name);

... what do I put here?


function checkTest(%arg) {
    if(%arg $= $pref::Player::NetName)
        commandtoserver('messagesent',"Testing worked.");
}

i still might be wrong.


also, of course define the function outside of the other function.

I think your problem is that you need a "break;" after every case in the switch statement. Try this:
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
                switch$(%msg)
                {
                        case "Test":
                               if (%name $= "jes00")
                               {
                                    commandToServer('messageSent',"Test: Success!");
                                }
                               break;

                        case "Hi":
                              commandToServer('messageSent',"Hi");
                              break;

                        case "the muffin smells good!":
                                commandtoserver('messagesent',"It does indeed!");
                                break;

                        case "Goodbye":
                                commandtoserver('messagesent',"Goodbye.");
                                break;
                }
}

};
activatePackage(chatbot);
Also, it is not necessary to put brackets around the single-line-if-statement, but I like to during testing, it helps you control program flow and keep mistakes from happening. This may not be the solution to your problem, but you should usually follow a case with a break; statement (depending on the application).
« Last Edit: August 10, 2011, 12:51:37 PM by AGlass0fMilk »

I think your problem is that you need a "break;" after every case in the switch statement. Try this:
-script-
Also, it is not necessary to put brackets around the single-line-if-statement, but I like to during testing, it helps you control program flow and keep mistakes from happening. This may not be the solution to your problem, but you should usually follow a case with a break; statement (depending on the application).
Ty AGlassOfMilk! it works!!!

how would you get it to say the words in a mini-game chat?

how would you get it to say the words in a mini-game chat?
i don't see a use in this besides chatspamming, in which case it would be a pretty loving stupid bot.
however, the command is /teammessagesent and you should be able to figure it out from there.