From fe5f07306d3c13b5f84c3d3f28ffa65ac11cd898 Mon Sep 17 00:00:00 2001 From: Anon Date: Sun, 16 Jul 2023 20:37:56 +0200 Subject: [PATCH 1/2] Added a random interval option to the wait command --- MinecraftClient/ChatBots/Script.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/ChatBots/Script.cs b/MinecraftClient/ChatBots/Script.cs index 9e139db9..a016dbfa 100644 --- a/MinecraftClient/ChatBots/Script.cs +++ b/MinecraftClient/ChatBots/Script.cs @@ -205,7 +205,23 @@ namespace MinecraftClient.ChatBots int ticks = 10; try { - ticks = Convert.ToInt32(instruction_line[5..]); + if (instruction_line[5..].Contains("to", StringComparison.OrdinalIgnoreCase) || + instruction_line[5..].Contains("-")) + { + var processedLine = instruction_line.Replace("wait", "") + .Trim() + .ToLower(); + processedLine = string.Join("", processedLine.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries)); + var parts = processedLine.Contains("to") ? processedLine.Split("to") : processedLine.Split("-"); + + if (parts.Length == 2) + { + var min = Convert.ToInt32(parts[0]); + var max = Convert.ToInt32(parts[1]); + + ticks = new Random().Next(min, max); + } else ticks = Convert.ToInt32(instruction_line[5..]); + } else ticks = Convert.ToInt32(instruction_line[5..]); } catch { } sleepticks = ticks; From c5a0409edc308350997ca6665529591f6391a417 Mon Sep 17 00:00:00 2001 From: Anon Date: Sun, 16 Jul 2023 20:45:24 +0200 Subject: [PATCH 2/2] Added documentation examples and covered an edge case --- MinecraftClient/ChatBots/Script.cs | 6 +++++ .../Translations/Translations.Designer.cs | 6 +++++ .../Resources/Translations/Translations.resx | 3 +++ docs/guide/usage.md | 26 +++++++++++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/ChatBots/Script.cs b/MinecraftClient/ChatBots/Script.cs index a016dbfa..4823f9de 100644 --- a/MinecraftClient/ChatBots/Script.cs +++ b/MinecraftClient/ChatBots/Script.cs @@ -218,6 +218,12 @@ namespace MinecraftClient.ChatBots { var min = Convert.ToInt32(parts[0]); var max = Convert.ToInt32(parts[1]); + + if (min > max) + { + (min, max) = (max, min); + LogToConsole(Translations.cmd_wait_random_min_bigger); + } ticks = new Random().Next(min, max); } else ticks = Convert.ToInt32(instruction_line[5..]); diff --git a/MinecraftClient/Resources/Translations/Translations.Designer.cs b/MinecraftClient/Resources/Translations/Translations.Designer.cs index 4d41b142..2526ebc9 100644 --- a/MinecraftClient/Resources/Translations/Translations.Designer.cs +++ b/MinecraftClient/Resources/Translations/Translations.Designer.cs @@ -3968,5 +3968,11 @@ namespace MinecraftClient { return ResourceManager.GetString("bot.common.movement.lock.held", resourceCulture); } } + + internal static string cmd_wait_random_min_bigger { + get { + return ResourceManager.GetString("cmd.wait.random.min.bigger", resourceCulture); + } + } } } diff --git a/MinecraftClient/Resources/Translations/Translations.resx b/MinecraftClient/Resources/Translations/Translations.resx index 8cab30fc..12aab380 100644 --- a/MinecraftClient/Resources/Translations/Translations.resx +++ b/MinecraftClient/Resources/Translations/Translations.resx @@ -2115,4 +2115,7 @@ Logging in... You can not start/run/use the '{0}' bot because it requires movement, the movement is currently utilized by the '{1}' bot, stop it if you want to use this one. + + Minimum number that you have provided is bigger than the maximum, swapping them around! + \ No newline at end of file diff --git a/docs/guide/usage.md b/docs/guide/usage.md index c641943b..64482327 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -695,10 +695,10 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q - **Examples:** ``` - /setrnd -7to10 + /setrnd -7 to 10 ``` - (Set a `%variable%` to a number from -7 to 9) + (Set a `%variable%` to a number from -7 to 10) ### `sneak` @@ -836,16 +836,38 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q - **Usage:** + Fixed time: + ``` /wait