Author Topic: Help with a script  (Read 438 times)

Alright, I know I did something wrong here.
Here is a snippet of the code
Code: [Select]
package 7Bot {
    function clientCmdChatMessage(%cl,%a,%b,%all,%pre,%name,%suf,%msg)
    {
    Parent::clientCmdChatMessage(%cl,%a,%b,%all,%pre,%name,%suf,%msg);
    7BotStuffs(%name,restWords(%msg));
    }
};
activatePackage(7Bot);

function 7BotSay(%message)
{
commandtoserver('MessageSent',"\c37bot\c6:" SPC %message);
}

function 7BotStuffs(%client, %command)
{
    %parse = firstWord(%command);
    %args = restWords(%command);
    if(%parse $= "info" )
        7BotSay("Pecon7 made me.");

I'm trying to get it to read what people say and respond if they say something in particular or their line includes a particular word/phrase.

It seems to be detecting only the second word someone says... Any help?
« Last Edit: April 14, 2011, 01:48:06 PM by pecon7 »

First off, starting package names and function names with a number is a bad idea.  sometimes it works, sometimes it does not.

next you need to do some debugging on your own and find out what all the arguments in the chatMessage function actually are.

start by using trace(1)  and see what you get in the console.

Code: [Select]
package Sevenbot {
function clientCmdChatMessage(%client, %num2, %num3, %amsg, %prefix, %name, %suffix, %msg) {
Parent::clientCmdChatMessage(%client, %num2, %num3, %amsg, %prefix, %name, %suffix, %msg);
if(firstWord(%msg) $= "7bot,")
SevenbotProcessor(%name, restWords(%msg));
    }
};
activatePackage(Sevenbot);

function SevenbotRelay(%msg) {
commandtoserver('MessageSent', "(7bot) " @ %msg);
}

function SevenbotProcessor(%name, %cmd) {
%first = firstWord(%cmd);
%rest = restWords(%cmd);
switch$(%first) {
case "info":
SevenbotRelay("Pecon7 made this bot.");
case "dance":
SevenbotRelay("I don't feel like it, " @ %name @ ".");
case "baby":
SevenbotRelay("Uh... Baby " @ %rest @ "?");
}
}

That's how I'd do it. Change the other two entries with whatever.

Please note: Clientside is extremely restrictive. You can't send color code and names and such to chat. If you could, everyone would be abusing fake usernames and such... We used to be able to do that. I changed your code so you note it as a 7bot response. It also only activates if someone starts the message with "7bot," so it doesn't have to do a full process every time.

That's how I'd do it. Change the other two entries with whatever.

Please note: Clientside is extremely restrictive. You can't send color code and names and such to chat. If you could, everyone would be abusing fake usernames and such... We used to be able to do that. I changed your code so you note it as a 7bot response. It also only activates if someone starts the message with "7bot," so it doesn't have to do a full process every time.
Thanks, I'll work off of that. Also I didn't know there were problems with adding numbers in package and function names... Probably explains some of the other issues it had.