From f5575d7f8bf201048743381eaa3d19e8b463fd88 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 11 Sep 2016 20:11:01 +0200 Subject: [PATCH] Update bot making documentation in ChatBot.cs + Add GetVarAsDouble in Script API (See #200) --- MinecraftClient/CSharpRunner.cs | 15 +++++++++++++++ MinecraftClient/ChatBot.cs | 18 +++++++----------- MinecraftClient/McTcpClient.cs | 2 ++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/MinecraftClient/CSharpRunner.cs b/MinecraftClient/CSharpRunner.cs index 3c216173..00c76ad1 100644 --- a/MinecraftClient/CSharpRunner.cs +++ b/MinecraftClient/CSharpRunner.cs @@ -303,6 +303,21 @@ namespace MinecraftClient return 0; } + /// + /// Get a global variable by name, as a double + /// + /// Name of the variable + /// Value of the variable as double, or 0 if no variable or not a number + public double GetVarAsDouble(string varName) + { + if (GetVar(varName) is double) + return (double)GetVar(varName); + double result; + if (double.TryParse(GetVarAsString(varName), out result)) + return result; + return 0; + } + /// /// Get a global variable by name, as a boolean /// diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 0b6a62c4..b46315c3 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -11,19 +11,15 @@ namespace MinecraftClient /// /// Welcome to the Bot API file ! /// The virtual class "ChatBot" contains anything you need for creating chat bots - /// Inherit from this class while adding your bot class to the folder "ChatBots". + /// Inherit from this class while adding your bot class to the "ChatBots" folder. /// Override the methods you want for handling events: Initialize, Update, GetText. - /// Once your bot is created, read the explanations below to start using it in the MinecraftClient app. /// - /// Pieces of code to add in other parts of the program for your bot. Line numbers are approximative. - /// Settings.cs:73 | public static bool YourBot_Enabled = false; - /// Settings.cs:74 | private enum ParseMode { /* [...] */, YourBot }; - /// Settings.cs:106 | case "yourbot": pMode = ParseMode.YourBot; break; - /// Settings.cs:197 | case ParseMode.YourBot: switch (argName.ToLower()) { case "enabled": YourBot_Enabled = str2bool(argValue); break; } break; - /// Settings.cs:267 | + "[YourBot]\r\n" + "enabled=false\r\n" - /// McTcpClient:110 | if (Settings.YourBot_Enabled) { handler.BotLoad(new ChatBots.YourBot()); } - /// Here your are. Now you will have a setting in MinecraftClient.ini for enabling your brand new bot. - /// Delete MinecraftClient.ini to re-generate it or add the lines [YourBot] and enabled=true to the existing one. + /// For testing your bot you can add it in McTcpClient.cs (see comment at line ~119). + /// Your bot will be loaded everytime MCC is started so that you can test/debug. + /// + /// Once your bot is fully written and tested, you can export it a standalone script. + /// This way it can be loaded in newer MCC builds, without modifying MCC itself. + /// See config/sample-script-with-chatbot.cs for a ChatBot script example. /// /// diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 3a3e28b8..6ceceebb 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -116,6 +116,8 @@ namespace MinecraftClient if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); } if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); } if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); } + //Add your ChatBot here by uncommenting and adapting + //BotLoad(new ChatBots.YourBot()); } try