Author Topic: Chatbot Help  (Read 2353 times)

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%fmsg);
}
if(%msg $= "Alchbot, test active")
{
if(%name $= "Alchemy")
{
commandToServer('messageSent',"AlchBot: Activity Test Succeed!");
}
};
activatePackage(Chatbot);
The packaging for my code works, but when I say the line, it does nothing. Please help.

You are ending the function early.

You are ending the function early.
What do you mean, Should I place the string check in the clientCmdChatMessage function?

What do you mean, Should I place the string check in the clientCmdChatMessage function?

yes.

congratulations on being a newby scripter with perfect indentation.

It still doesn't work :c

yes.

congratulations on being a newby scripter with perfect indentation.
He's been trying to learn how to script for a while now

It still doesn't work :c
post your current code.
He's been trying to learn how to script for a while now
oh.

The %msg variable was never defined. You probably mean %fmsg judging by parameters

The %msg variable was never defined. You probably mean %fmsg judging by parameters

He also put %fmsg twice

This is not nessisary or anything but I suggest using if(%name $= $Pref::Player::NetName) instead because than you don't need to change the script if you change your name.

Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%msg $= "Alchbot, test active" && %name $= $Pref::Player::Netname)
{
commandToServer('messageSent',"AlchBot: Activity Test Succeed!");
}
}
};
activatePackage(Chatbot);
Fixxxxxed.

You also killed his indenting, and combined the two ifs into one. Which is fine now, but if he wants to add more messages to reply too he either has to seperate them again or copy both of them.

I'd recommend checking the name first, then checking the message. That way, when you add more messages, you don't need to add more name checks.
« Last Edit: July 27, 2012, 09:16:58 AM by Headcrab Zombie »

One question, I want to add in support for asking my Alchbot my current status, such as my health, what should I put to return my health value? Is health supposed to be a field/area in the player datablock?

I changed the script a little bit, I set a global string for the owner's name, so checking the name would be easier. It turns out it works
« Last Edit: July 27, 2012, 12:01:22 PM by PurpleMetro »

I've added a random number feature, but it doesn't work, please help
Code: [Select]
//"Alchemy's Person Chatbot" made by Alchemy
//This is a "Medium" script level
//This script was created for "Alchemy"

$owner = "Alchemy"
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $owner && %msg $= "Alchbot, Test Active")
{
commandToServer('messageSent',"[AlchBot]: Activity Test Succeed!");
}
elseif(%name $= $owner && %msg= "Alchbot, generate a random number between "%a" and "%b"")
{
%a = 0
%b = 0
%c = (getRandom(%a,%b)
commandToServer('messageSent',"[Alchbot]: The number returned was "@ %c @"");
}
};
activatePackage(Chatbot);

You have a lot of serious syntax errors there, and quite a few logic errors.

Wall of text incoming

syntax errors: you forgot to put a semicolen at the end of line 5, you forgot a closing brace on line 14/15, you forgot to put a space between else and if on line 15, you used = to compare 2 values when = is to set a variable (you should've used $=), you improperly used the if statement at "alchbot, generate a [...]", it isn't for formatting an input string, it's for checking values, and even if it did work like that you would've reset it at lines 17 and 18, on which you forgot to put semicolens at the end of, meaning more syntax errors, you put an extra ( on line 19 and again forgot a semicolen, and on line 20 you put @ "" for some reason, idk why.

so about 15 syntax errors
« Last Edit: July 27, 2012, 12:28:30 PM by Ipquarx »