Author Topic: Serverbot stuff  (Read 1147 times)

I made a simple serverbot. It doesn't do anything useful yet. So what is wrong with this script?:
Code: [Select]
Package cheesebot{
function servercmdmessagesent(%client,%msg)
{
Parent::servercmdmessagesent(%client,%msg);
if(getsubstr(%msg,0,9) $= "cheesebot")
{
if(getsubstr(%msg,9,3) $= "love")
{
Messageall('','\c6GTFO Noob');
}
if(getsubstr(msg,9,4) $= "Love");
{
Messageall('','\c6I love you too, " @ %client.name @ ".");
}
}
}
};
Activatepackage(cheesebot);

-snip-

Read two posts down.
« Last Edit: November 09, 2008, 05:49:07 PM by Truce »

Code: [Select]
Package CheeseBot
##
##
{
function serverCmdMessageSent(%client,%msg)
{
Parent::serverCmdMessageSent(%client,%msg);
if(getSubStr(%msg, 0, 9) $= "CheeseBot")
{
if(getSubStr(%msg, 10, 3) $= "love")
{
messageAll('',"\c6GTFO Noob");
}
if(getSubStr(%msg, 10, 4) $= "love")
{
messageAll('',"\c6I love you too, " @ %client.name @ ".");
}
}
}
};
activatePackage(CheeseBot);
Thats what the error is showing.

Er well, I had it working, just I use "messy script."
Even though it's easier for me to read, most people don't like it.
I had tried cleaning it up a bit but apparently it still gave you an error.

Anyway, heres the one that works (and is "clean"):

Code: [Select]
package CheeseBot
{
function serverCmdMessageSent(%client,%msg)
{
Parent::serverCmdMessageSent(%client,%msg);
if(getSubStr(%msg, 0, 9) $= "CheeseBot")
{
if(getSubStr(%msg, 10, 3) $= "love")
{
messageAll('',"\c6GTFO Noob");
}
if(getSubStr(%msg, 10, 4) $= "love")
{
messageAll('',"\c6I love you too, " @ %client.name @ ".");
}
}
}
};
activatePackage(CheeseBot);
« Last Edit: November 09, 2008, 05:50:11 PM by Truce »

Thanks, it's all working now.

Ok, can someone give me a brief explination on how to make people admin via cheesebot. I want to say Cheesebot admin <name> 0, 1, or 2.

What you'd need to do is this:

1) Check if the CheeseBot cmd is "admin"
 - Just the same as all the other cmds
2) Check and find the client of the name you enter
 - The name is the third word, so you can use getWord(%msg,2) and then findclientbyname();
3) Perform different actions based on the number
 - Just use if tests to check the number (which is the fourth word, thus, getWord(%msg,3))
4) Make sure the user is the host of the server
 - if(%client.bl_id $= getNumKeyID()) works for non-LAN servers.

Put this below your other CheeseBot cmds.
It should already be indented enough for you :3

Code: [Select]
if(getSubStr(%msg, 10, 5) $= "admin")
{
if($Server::LAN || %client.bl_id $= getNumKeyID())
{
%cl = findclientbyname(getWord(%msg, 2));
if(getWord(%msg,3) $= "0")
{
%cl.isAdmin = 0;
%cl.isSuperAdmin = 0;
commandtoClient(%cl,'setAdminLevel',0);
messageAll('',"\c6CheeseBot has made " @ %cl.name @ " a normal user.");
}
if(getWord(%msg,3) $= "1")
{
%cl.isAdmin = 1;
%cl.isSuperAdmin = 0;
commandtoClient(%cl,'setAdminLevel',1);
messageAll('',"\c6CheeseBot has made " @ %cl.name @ " an Admin.");
}
if(getWord(%msg,3) $= "2")
{
%cl.isAdmin = 1;
%cl.isSuperAdmin = 1;
commandtoClient(%cl,'setAdminLevel',2);
messageAll('',"\c6CheeseBot has made " @ %cl.name @ " a Super Admin.");
}
}
else
{
messageClient(%client,'',"\c6You must be the host to use this command.");
}
}

I know I've been teaching you some stuff in-game, but this is the last time I'm going to give you the full code.
By now you should be able to get the basic idea of how things work by viewing the features of these codes.

EDIT:

I mean I'll still help you, just not give you the whole code.
Just pieces like how to use getWord() so you can learn more out of it.

Besides, you were teaching me stuff too when we were in my server xD
« Last Edit: November 09, 2008, 07:29:45 PM by Truce »


« Last Edit: November 10, 2008, 03:35:12 PM by Burger »

A tip for making bots, use call(func,arg1,arg2,arg3...) and isFunction.

As in:
Code: [Select]
//Package
package ChatBot
{
function servercmdmessagesent(%c,%msg)
{
Parent::ServerCmdMessageSent(%c,%msg);
%ind=searchWord(%msg,$BotName);
if(%ind!$="")
{
if(!isFunction("BotMessage_"@getWord(%msg,%ind+1))) {return;}
call("BotMessage_"@getWord(%msg,%ind+1),%c,getWords(%msg,%ind+2));
}
}
};ActivatePackage(Chatbot);


//Support
function searchWord(%str,%word)
{
%count=getWordCount(%str);
for(%a=0;%a<%count;%a++)
{
if(getWord(%str,%a)$=%word)
{
return %a;
}
}
return "";
}

Then for defining commands you simply use:
Code: [Select]
function BotMessage_Hello(%c,%msg)
{
BotSay("Hello, "@%c.name);
}

Where botSay makes the bot say something.

Note that this code is from my older chatbot, Sigma.
I edited it a little to be more effective.
It should work, but theres a slight chance you'd need to correct minor errors.
« Last Edit: November 11, 2008, 09:32:02 AM by NiXiLL »

I wonder where Tex and Texo is... D=
Last time I saw him/her, Sumz and some other guy who made a Blockopoly "dice" addon to him/her had it.