Author Topic: Bot  (Read 1930 times)

This is a simple bot script.

Code: [Select]
package simpleBot
{
  function serverCmdMessageSent(%client, %text)
  {
     parent::serverCmdMessageSent(%client, %text);
     if(striPos(%text, "Hello world!") != -1) //makes it so that it isn't case sensitive
     {
        messageAll('',"\c3Bot\c6: Hello!");
     }
  }
};
activatePackage(simpleBot);

VERY simple and only detects one phrase and has only one response and one name.

To add a name/message to answer simply replace some things and add some lines

Code: [Select]
$botmessage = "Hello!";
$botname = "Bot";

Would be BEFORE the package.

The messageAll would be replaced with this:
Code: [Select]
messageAll('',"\c3"@$botname@"\c6: "@$botmessage);
I would go more in-depth about working this with auto-learning, auto-speaking, etc.

But I don't feel that I need to help you, if you can code and have a logical and/or insightful brain.

Code: [Select]
if(striPos(%text, "Hello world!") != -1) //makes it so that it isn't case sensitive

What. TorqueScript is type-insensitive and case-insensitive (except for stuff like strReplace, striReplace, strPos, striPos, etc).

=> echo(("Hello, world" $= "Hello, world"));
1
=> echo(("hELLo, WoRlD" $= "Hello, world"));
1
=> echo(("Hello, worl" $= "Hello, world"));
0

(except for stuff like strPos, striPos)
if(striPos(%text, "Hello world!") != -1) //makes it so that it isn't case sensitive


Why is he SEARCHING for the string? And secondly, he's saying that using the str?Pos function makes it case-insensitive.

OH, I see what you mean.

There's no need for the striPos there, you're right.