Author Topic: So I made a chatbot...  (Read 1031 times)

A while back, I asked for help, and now I finally got it!
But now I need help with an error.
My chatbot doesn't even work anymore! :O
Here is the code:
Code: [Select]
package chatbot
{
function clientCmdChatMessage( %cl, %voice, %pitch, %line, %pre, %name, %suf, %msg )
{
parent::clientCmdChatMessage( %cl, %voice, %pitch, %line, %pre, %name, %suf, %msg );
%self = ( %name $= $Pref::Player::NetName );

switch$ ( %msg )
{
case "comedyBot":
if ( %self )
{
commandToServer( 'messageSent', "comedyBot: Yes?" );
}
case "afk":
if ( %self )
{
commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" );

}
case "brb":
if ( %self )
{
commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" );

}
case "Back":
if ( %self )
{
commandToServer( 'messageSent', "comedyBot: Welcome back!" );

}
}

}
}
};

activatePackage( "chatbot" );

You cannot magically have sub-cases that use a secondary part of the string. And please, work on your indentation. In any case, you have an extra bracket near the end of the function.


Code: [Select]
removed

Wait...this code doesn't even make sense. You first check if the msg is Comedybot, and then check if it IS Comedybot, is it also 'afk', 'brb', or 'back'.

Tip: 1 word can't be two words
« Last Edit: April 12, 2012, 12:56:47 PM by LundoomGaming »

Try this

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg)
{
parent::clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg);
%self = (%name $= $Pref::Player::NetName);
if(!%self)
{
return;
}
if(firstWord(%msg)$="Comedybot")
saystuff(restWords(%msg));
}
};
function saystuff(%msg)
{
switch(%msg)
{
if(%msg == "")
{
commandToServer( 'messageSent', "comedyBot: Yes?" );
}
else if(%msg == "afk")
{
commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" );

}
else if(%msg == "brb")
{
commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" );

}
else if(%msg = "back")
{
commandToServer( 'messageSent', "comedyBot: Welcome back!" );

}

}

}
activatePackage( "chatbot" );

« Last Edit: April 12, 2012, 01:07:19 PM by LundoomGaming »


Please learn TorqueScript before trying to help others with TorqueScript.


Try this

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg)
{
parent::clientCmdChatMessage(%cl, %voice, %pitch, %line, %pre, %name, %suf, %msg);
%self = (%name $= $Pref::Player::NetName);
if(!%self)
{
return;
}
if(firstWord(%msg)$="Comedybot")
saystuff(restWords(%msg));
}
};
function saystuff(%msg)
{
switch(%msg)
{
if(%msg == "")
{
commandToServer( 'messageSent', "comedyBot: Yes?" );
}
else if(%msg == "afk")
{
commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" );

}
else if(%msg == "brb")
{
commandToServer( 'messageSent', "comedyBot: I'll see you when you get back!" );

}
else if(%msg = "back")
{
commandToServer( 'messageSent', "comedyBot: Welcome back!" );

}

}

}
activatePackage( "chatbot" );

Oh my epic fail

This code will work
Code: [Select]
package ChatBot
{
function clientCmdChatMessage(%c,%a,%b,%fmsg,%cp,%name,%cs,%msg)
{

if(%msg $= "AFK")
{
commandToServer('messageSent',"ComedyBot: See you when you get back!");
}
if(%msg $= "Back")
{
commandToServer('messageSent',"ComedyBot: Welcome Back!");
}
//Remove this and you'll break your chat, so don't.
parent::clientCmdChatMessage(%c,%a,%b,%fmsg,%cs,%name,%cp,%msg);
}
};
ActivatePackage(ChatBot);

oh my god how many tabs is that

Why does nobody indent properly!
It's the easiest part of scripting!

Chatbots are generally frowned upon...
...unless they are server sided and only helpful.

The only situation where I will not instantly condemn a chatbot is if it is server-sided, actually helpful and can actually speak English (e.g. “Bot, could you please tell me what 7*4 is? Oh, and kick all the non-admins.“).

The only situation where I will not instantly condemn a chatbot is if it is server-sided, actually helpful and can actually speak English (e.g. “Bot, could you please tell me what 7*4 is? Oh, and kick all the non-admins.“).
You made a client sided translator chat bot.

The thing about a clientsided chatbot is that 3/4 of the time they only respond to the owner anyway in which case why the forget does anyone else need to see your input. Use NMH_Type::Send(%this) where the text is %this.getValue(). For bonus points, instead of returning, use %this.setValue(%output) before parenting so it's literally just a chat preprocessor allowing for special input. You could even then set the value to a server command and have it work, as the servercmd parsing part for /cmds is done by this function.

Here's some other fun exercises for you chatbot enthusiasts:
  • Don't make it give an error message if they're not allowed to use it (that's just stupid)
  • Make it use your actual name to figure out if they're referring to you, rather than some friend bot name (you pretentious cunt)
  • Use trust for permission management
  • Parse commands using english-like syntax; this one's a doozy (I've done it partially, once)
  • Give it actual helpful functions (such as a mathematical parser that doesn't use eval (people will try to get you to crash yourself), a Google translation API, a system people can use to leave you messages while you're AFK or for other people if you happen to see them, a voting system, a hexadecimal translator, stuff like that)
  • Implement a message queue so multiple lines of output don't trigger all at once, to help with flood protection, and make it automatically go faster if you're an admin ($iAmAdmin is a default value containing your admin status, clientside; it's used so you don't have to check with the server to find out if you can open the admin menu - if you set it manually you can open the admin menu but it won't work. Same for loading.)
  • As well as a message queue, allow people to tell you to stop sending messages, if your queue gets huge you could be sat there for a while. It's also a good idea to make the message queue halt sending if you're typing and resume after a delay when you send the message, or maybe cancel if you've got the chatbox open for more than ten seconds.
Things you should never do with chatbots:
  • Automatically greet players who join the server - this is annoying for everyone, and people always say "It's to show I care!" when in fact you do not care. You have automated the process of acting like you care which is saying you care exactly enough to not want to put the effort in. Which is like saying you care about your dying aunt exactly enough to not go and visit her in the hospital, but you'll leave a note with someone who is going to visit her.
  • Make it only answer you - this should be done entirely on your screen. If other players can't interact with it, you're acting like a pretentious friend trying to lord that you made a chatbot over others. In other words, it makes you a huge prick, and in the eyes of most people, being a huge prick is grounds for a permanent ban and you loving deserve it.
  • Use some stupid bot name like "COMEDYBOT" - we know it's a bot you imbecile. You don't need to say it's a bot. Make it respond to your own name since we all see it as such. It feels much more natural and is in fact kind of cool.
  • Give it a bunch of useless functions, such as RANDUMB QUOTES LOL or a BL_ID lookup. We have the RTB List (it'd be nice if there was an API for this), and nobody cares what your bot knows how to say unless it's formulating its own sentences or the messages actually contain information people might need. Try to keep your bots as some form of aide, not a toy, because nobody likes toys that make forgetloads of noise and don't do anything interesting.
« Last Edit: April 16, 2012, 08:13:34 AM by M »

You made a client sided translator chat bot.

That only displays the translation to me. It is not a chatbot.