mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Script Works?
This commit is contained in:
parent
0332df909c
commit
7e70494f23
7 changed files with 94 additions and 15 deletions
|
|
@ -845,11 +845,65 @@ namespace MinecraftClient
|
|||
/// <summary>
|
||||
/// Runs a list of commands
|
||||
/// Usage: bot:scripting:filename
|
||||
/// Script must be placed in the config directory
|
||||
/// </summary>
|
||||
|
||||
public class scripting : ChatBot
|
||||
{
|
||||
private string file;
|
||||
private string[] lines = new string[0];
|
||||
public scripting(string filename)
|
||||
{
|
||||
file = filename;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
// Loads the given file from the startup parameters
|
||||
if (System.IO.File.Exists("config/" + file))
|
||||
{
|
||||
lines = System.IO.File.ReadAllLines("config/" + file); // Load the given bot text file (containing commands)
|
||||
for (int i = 0; i < lines.Length; i++) // Parse through each line of the bot text file
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
string this_line = lines[i].Trim(); // Removes all whitespaces at start and end of current line
|
||||
|
||||
if (this_line.Length == 0) {
|
||||
// Skip a completely empty line
|
||||
}
|
||||
else if (this_line.Trim().StartsWith("//"))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
Console.WriteLine("BOT:" + this_line);
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
// Don't do anything for a comment line, denoted by '//'
|
||||
}
|
||||
else if (this_line.StartsWith("send "))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
SendText((lines[i].Trim().Substring(5, lines[i].Length - 5)));
|
||||
// Send the command
|
||||
}
|
||||
else if (this_line.StartsWith("wait "))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
Console.WriteLine("BOT:Pausing for " + Convert.ToInt32(lines[i].Substring(5, lines[i].Length - 5)) * 100 + "ms...");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
System.Threading.Thread.Sleep(Convert.ToInt32(lines[i].Substring(5, lines[i].Length - 5)) * 100);
|
||||
// Do a wait (given in milliseconds)
|
||||
}
|
||||
else if (this_line.StartsWith("exit")) {
|
||||
//Program.Client.Disconnect();
|
||||
} // Optional exit only if called in bot text file,
|
||||
}
|
||||
UnloadBot(); // Otherwise continue operation of Client to normal (non-bot) usage
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(file + " not found! Please make sure that the file is located in the config directory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue