I used the player.joined event and the chatfilter features that Dzienny has brought into the source!
- Code: Select all
using System.Threading;
using System;
namespace MCDzienny
#region Settings
{
public class CmdWelcome_bot : Command
{
public override string name { get { return "lbs"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "mod"; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
Player.GlobalMessage(" %f[%bLeeBot%f]: " + message);
}
#endregion
#region Joined server
public override void Init()
{
Player.Joined += (object sender, PlayerEventArgs e) =>
{
Player.GlobalMessage("%f[%bLeeBot%f]: Hey %a$name! %fWelcome to $server.:D");
};
Player.PlayerChatEvent += FilterChat;
}
#endregion
#region greetings
private void FilterChat(Player p, ref string message, ref bool stopIt)
{
string botCmd = message;
if (botCmd.Contains("hey leebot"))
{
Player.GlobalMessage(p.color + p.name + "%f to %f[%bLeeBot%f]: " + message);
Player.GlobalMessage(" %bLeeBot%f is typing... ");
Thread.Sleep(2000);
message = null;
Player.GlobalMessage("%f[%bLeeBot%f]: Hello there, " + p.color + p.name + "%f!");
}
else if
(botCmd.Contains("hi leebot"))
{
Player.GlobalMessage(p.color + p.name + "%f to %f[%bLeeBot%f]: " + message);
Player.GlobalMessage(" %bLeeBot%f is typing... ");
Thread.Sleep(2000);
message = null;
Player.GlobalMessage("%f[%bLeeBot%f]: Hello there, " + p.color + p.name + "%f!");
}
else if (botCmd.Contains("Hey leebot"))
{
Player.GlobalMessage(p.color + p.name + "%f to %f[%bLeeBot%f]: " + message);
Player.GlobalMessage(" %bLeeBot%f is typing... ");
Thread.Sleep(2000);
message = null;
Player.GlobalMessage("%f[%bLeeBot%f]: Hello there, " + p.color + p.name + "%f!");
}
#endregion
#region I'm back
if (botCmd.Contains("I'm back"))
{
Player.GlobalMessage(" %bLeeBot%f is typing... ");
Thread.Sleep(2000);
message = null;
Player.GlobalMessage("%f[%bLeeBot%f]: Welcome back, " + p.color + p.name + "%f!");
}
else if (botCmd.Contains("i'm back"))
{
Player.GlobalMessage(" %bLeeBot%f is typing... ");
Thread.Sleep(2000);
message = null;
Player.GlobalMessage("%f[%bLeeBot%f]: Welcome back, " + p.color + p.name + "%f!");
}
else if (botCmd.Contains("im back"))
{
Player.GlobalMessage(" %bLeeBot%f is typing... ");
Thread.Sleep(2000);
message = null;
Player.GlobalMessage("%f[%bLeeBot%f]: Welcome back, " + p.color + p.name + "%f!");
}
}
#endregion
public override void Help(Player p)
{
Player.SendMessage(p, "/lbs to speak as the bot");
}
}
}
It basically makes the bot respond to a normal text from a Minecraft player, mess around with the code and see how you do! use /lbs (message) to speak as the bot.
ps: If anyone can suggest how to remove the case sensitivity that would be great!