Add support for C# script extensions

- Allow defining function for use into the script
- Allow defining a ChatBot for loading it into MCC
- Improve sample script and add more examples
- Todo add new documentation into the readme file
This commit is contained in:
ORelio 2015-06-21 18:45:43 +02:00
parent a6b3bf0481
commit e29b4ee545
6 changed files with 115 additions and 26 deletions

View file

@ -0,0 +1,30 @@
//MCCScript 1.0
/* This script demonstrates how to add fields and methods */
for (int i = 0; i < 5; i++)
{
int count = GetVarAsInt("test") + 1;
SetVar("test", count);
SendHelloWorld(count);
SleepBetweenSends();
}
//MCCScript Extensions
/* Here you can define methods for use into your script */
void SendHelloWorld(int count)
{
/* Warning: Do not make more than one server-related call into a method
* defined as a script extension eg SendText or switching servers,
* as execution flow is not managed in the Extensions section */
SendText("Hello World no. " + count);
}
void SleepBetweenSends()
{
LogToConsole("Sleeping for 5 seconds...");
Thread.Sleep(5000);
}

View file

@ -0,0 +1,35 @@
//MCCScript 1.0
/* This is a sample script that will load a ChatBot into Minecraft Console Client
* Simply execute the script once with /script or the script scheduler to load the bot */
LoadBot(new ExampleBot());
//MCCScript Extensions
/* The ChatBot class must be defined as an extension of the script in the Extensions section
* The class can override common methods from ChatBot.cs, take a look at MCC's source code */
public class ExampleBot : ChatBot
{
public override void Initialize()
{
LogToConsole("Sucessfully Initialized!");
}
public override void GetText(string text)
{
string message = "";
string username = "";
text = GetVerbatim(text);
if (IsChatMessage(text, ref message, ref username))
{
LogToConsole("Public message from " + username + ": " + message);
}
else if (IsPrivateMessage(text, ref message, ref username))
{
LogToConsole("Private message from " + username + ": " + message);
}
}
}

View file

@ -6,10 +6,9 @@
for (int i = 0; i < 5; i++)
{
int count = GetVarAsInt("test");
count++;
int count = GetVarAsInt("test") + 1;
SetVar("test", count);
SendText("Hello World no. " + count);
PerformInternalCommand("log Sleeping for 5 seconds...");
LogToConsole("Sleeping for 5 seconds...");
Thread.Sleep(5000);
}