Author Topic: A chatbot  (Read 2638 times)

Does not seem to work for me

When using messageAll you don't define a target, as it messages everybody. So the %client is useless. It should be just messageAll('',"\c5MBot\c6:" SPC %args);

Thanks for the help! I have added you all to the credits.
« Last Edit: August 09, 2014, 09:14:00 PM by matthew »

Btw i prefer having it packaged so i can turn it off and on easily
For this you want to check the value of a global variable

function example()
{
   if(!$Pref::Server::EnableExample)
      return;
      
   echo("Hello"!);
}

How would i make the bot greet people who join the server?

How would i make the bot greet people who join the server?
Just change $Pref::Server::WelcomeMessage. Alternatively, you could package and parent GameConnection::autoAdminCheck() and take it from there.

Thanks for that. How would i make it say this message to the person that has just connected: This server is using Mbot V2

Thanks for that. How would i make it say this message to the person that has just connected: This server is using Mbot V2
Dont do this for small add-ons, just huge add-ons (such as gamemodes), or some otherwise VERY iimportant information
When everyone does it, we get a ton of add-ons spamming your chat when you join with "THIS SERVER IS RUNNING THIS MOD" and nobody cares
« Last Edit: August 09, 2014, 10:15:16 PM by Headcrab Zombie »

Well thanks for the help! I do not need anymore help now. Locking

Don't lock coding help threads
Sometimes someone will want to add something else, notice a mistake in a provided solution, something like that, and they won't be able to if the thread is locked

package serverbot
{
  function servercmdmessagesent(%client, %text)
   {
      %help = stripos(%text, "help");
      %length = strlen("help");
      %var = %help + %length;
       if(getsubstr(%text, %help, %var) $= "help")
           {
               messageclient(%client,' ',"\c6 Server:" SPC "text goes here");
           }
       else
          {
                parent::servercmdmessagesent(%client, %text);
           }
   }
};
activatepackage(serverbot);


Didn't test, i think this should work.
If someone says help in chat, the ServerBot says text goes here.
« Last Edit: August 12, 2014, 09:56:54 AM by Benci »

     %help = stripos(%text, "help");
      %length = strlen("help");
      %var = %help + %length;
       if(getsubstr(%text, %help, %var) $= "help")
What the forget are you doing
Why would you ever use strlen on a string literal? The length of "help" is never going to change, it's always going to be 4
Why getsubstr? You already know "help" is at that location, because you found it with stripos
Replace those four lines with if(stripos(%text,"help") > -1). That's it, that's all you need
Of course this will trigger the chat bot (and therefore cancel their entire message, as the if block doesn't include the parent call) every time someone says "help" in their entire message, so you need to either if(%text $= "help") (preffered) or just add the parent call in with the if black
Also, if you read the thread, he said he wanted slash commands


Fixed

Uh, what? No, not really. strstr does basically the same thing as stripos except it's case-sensitive. If you want case-sensitivity, just use strpos.

I thought stripos was the case sensitive one though?
Quote from: dump
   General string manipulation functions.
   @{ */
   virtual int strcmp(string one, string two) {}
   virtual int stricmp(string one, string two) {}
   virtual int strlen(string one, string two) {}
   /*!  Returns the start of the sub string two in one or -1 if not found. */
   virtual int strstr(string one, string two) {}

   /*!  Find needle in hay, starting offset bytes in. */
   virtual int strpos(string hay, string needle, int offset=0) {}
   /*!  Find needle in hay, starting offset bytes in. (Case insensitive) */
   virtual int stripos(string hay, string needle, int offset=0) {}

   virtual string ltrim(string value) {}
   virtual string rtrim(string value) {}
   virtual string trim(string) {}
   /*!  Remove all the characters in chars from value. */
   virtual string stripChars(string value, string chars) {}
   /*!  Convert string to lower case. */
   virtual string strlwr(string) {}
   /*!  Convert string to upper case. */
   virtual string strupr(string) {}
   virtual string strchr(string,char) {}
   virtual string strreplace(string source, string from, string to) {}
   /*!  Returns the substring of str, starting at start, and continuing to either the end of the string, or numChars characters, whichever comes first. */
   virtual string getSubStr(string str, int start, int numChars) {}
   /*!  Returns number of occurences of char in string */
   virtual int getCharCount(string, char) {}
   /// @}

I thought stripos was the case sensitive one though?

Quote
(Case insensitive)
read pls