if(!isFile("config/Chatbot/prefs.cs")){ // Checking if the file exists
$Chatbot::Pref::BotName="Chatbot"; //Creating a variable for the chatbot's name
$Chatbot::Pref::Caller="chatbot,"; //creating a variable for the chatbot's caller
$Chatbot::Pref::StartScan=1; //creating a variable to scan when the bot loads
}
export("$Chatbot::Pref*","config/Chatbot/prefs.cs"); //exporting all chatbot prefs to a file
exec("config/Chatbot/prefs.cs"); //executing the prefs file
package ChatBotCore //creating a new package
{
function NMH_Type::Send(%this) //function when you send a chat message
{
if(firstWord(%this.getValue()) $= $Chatbot::Pref::Caller@",") //checking if the first word is the caller of you chatbot
{
%msg=%this.getValue(); //creating a message variable from the value of the chat bar
ChatbotCore_Send(%msg); //sending the message through chat (see below)
ChatbotCore_Command(getWord(%msg,1),$Pref::Player::netName,restWords(restWords(%msg)),1); //Calling a function, keep in mind that 1 at the end
canvas.popDialog(NewMessageHud); //closing the chat window
return; //ending here
}
Parent::Send(%this); //doing what this function was originally meant to do.. (IT HAS TO BE IN A PACKAGE!!!, Otherwise you will get some annoying bugs)
}
function clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg) //function for when you get a chat message
{
parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg); //calling original chat function
if(firstWord(%msg)$=$Chatbot::Pref::Caller@",") //checking if first word of the message is the caller
ChatBotCore_Command(getWord(%msg,1),%name,restWords(restWords(%msg))); //calling a command with specific information
}
};
activatepackage(ChatBotCore); //activating the package so the parented functions will run their new modified code
function ChatBotCore_Command(%command,%name,%arguments,%safe) //function for calling chatbot code
{
if(%name $= $Pref::Player::netName && !%safe) //making sure that there is no one imposing as you
return; //ending because someone is messing with your chat
if(isFunction("ChatBot_"@%command)) //checking if a function exists
call("ChatBot_"@%command,%name,%arguments,%safe); //calling that function with specific information
}
function ChatBotCore_Send(%m) //creating a function to make chatting easier
{
commandtoserver('messagesent',%m); //sending a chat message
}
function ChatBotCore_Print(%s) //creating a function to make adding lines to the screen easier
{
NewChatSO.addLine("\c5"@%s); //adding a chat line
}
function ChatbotCore_scan() //a function for scanning all files in blockland folder
{
%p="./ChatBot_*.cs"; //a new file pattern with a wild card (*) in it
%f=findFirstFile(%p); //finding the first file with the pattern
while(%f!$="") //until there is no file to be found, loop
{
if(compile(%f)) //if the file will compile
{
echo("ChatBot: Executing "@fileBase(%f)); //echo that we're executing the file
exec(%f); //execute it
%l++; //increment a variable
}
else //otherwise..
{
echo("ChatBot: Error in "@%f); //tell us that we have an error
%e++; //increment a variable
}
%t++; //increment a variable
%f=findNextFile(%p); //find the next file using the pattern
}
echo("ChatBot: Loaded Plugins="@%l); //echo a variable
echo("ChatBot: Bugged Plugins="@%e); //echo another variable
echo("Chatbot: Total Plugins="@%t); //and another variable
}
if($Chatbot::Pref::StartScan) //checking if we have that scan pref on
{
ChatbotCore_scan(); //commence scanning
export("$Chatbot::Pref*","config/Chatbot/prefs.cs"); //export prefs
}
My private chatbot code :/
It allows for adding commands as simple as this:
function Chatbot_Hi(%name,%args,%safe) //creating a new function
{
ChatBotCore_Send($Chatbot::Pref::BotName@": Hello, "@%name); //sending a chat message
}
That one function allows you to type "Chatbot, Hi" in the chat and have it respond as "Chatbot: Hello, MARBLE MAN"
Edit:
Forgot to mention that it scans your entire blockland folder for files named "Chatbot_~"
It will execute them and run them
Edit:
Forgot to mention some extra functionality:
It stops you from responding to servercmdmessagesent(%YourClient,"chatbot, Hi");
Edit:
Commented everything so eepos is happy