Add sample script with world access

See #123
This commit is contained in:
ORelio 2016-03-03 12:07:18 +01:00
parent b10e3e8521
commit fc9adf902e

View file

@ -0,0 +1,61 @@
//MCCScript 1.0
MCC.LoadBot(new WatchLamp());
//MCCScript Extensions
/* The ChatBot will access the world on a regular basis to watch for a lamp.
* This is an example of how the world around the player can be accessed from a C# script. */
class WatchLamp : ChatBot
{
/* == CONFIG == */
int lampX = 0;
int lampY = 64;
int lampZ = 0;
/* == CODE == */
int checkCount = 0;
Location lampLoc;
public WatchLamp()
{
if (!Settings.TerrainAndMovements)
{
LogToConsole("WARNING: Terrain handling is disabled in INI file.");
LogToConsole("WARNING: This means this bot cannot watch for lamps.");
UnloadBot();
}
else
{
lampLoc = new Location(lampX, lampY, lampZ);
LogToConsole("Watching lamp at " + lampLoc);
}
}
public override void Update()
{
if (checkCount > 10)
{
checkCount = 0;
Material blockType = GetWorld().GetBlock(lampLoc).Type;
switch (blockType)
{
case Material.RedstoneLampOn:
//Lamp is on. All right. Nothing to say here.
break;
case Material.RedstoneLampOff:
LogToConsole("Lamp at " + lampLoc + " is currently turned OFF !!!");
for (int i = 0; i < 3; i++)
Console.Beep();
break;
default:
LogToConsole("Block at " + lampLoc + " is not a lamp: " + blockType + "...");
break;
}
}
else checkCount++;
}
}