Skip to content

Autohotkey_improvments? #26

@unaveragetech

Description

@unaveragetech

; Minecraft Bot Control Script
; Version: 2.0
; Description: Provides hotkeys and menu system for controlling a Minecraft bot via chat commands

; --------------------------
; Configuration Section
; --------------------------
; Set global bot name at script start
global VarBotName := (ib := InputBox("Enter Bot Name", "Bot Configuration")).Result = "OK" ? ib.value : ExitApp()
SetKeyDelay 75, 25 ; Delay between keystrokes (75ms press, 25ms release)

; --------------------------
; Core Functionality
; --------------------------

/**

  • Sends a sequence of commands to reset bot state before new commands
  • @param {string} botName - Name of the bot to control
    */
    SendResetSequence(botName) {
    SendChatCommand(botName, "{!}stop")
    SendChatCommand(botName, "{!}endGoal")
    SendChatCommand(botName, "{!}stfu")
    }

/**

  • Executes a bot command with proper chat handling
  • @param {string} botName - Name of the bot to control
  • @param {string} command - Command to send to the bot
    */
    MCSendCommand(botName, command) {
    SendResetSequence(botName)
    SendChatCommand(botName, "{!}" command)
    }

/**

  • Helper function to send individual chat commands
  • @param {string} botName - Name of the bot to control
  • @param {string} message - Message to send in chat
    */
    SendChatCommand(botName, message) {
    Send "{esc}" ; Ensure chat is closed
    Sleep 100
    Send "t" ; Open chat
    Sleep 100
    Send "/msg " botName " " message
    Sleep 100
    Send "{enter}"
    Sleep 100
    }

; --------------------------
; Hotkey Definitions
; --------------------------

; F1: Send custom command with reset sequence
f1:: {
ib := InputBox("Enter Bot Command", "Custom Command")
if ib.Result = "OK" {
MCSendCommand(VarBotName, ib.value)
}
}

; F2: Emergency stop commands
f2::SendResetSequence(VarBotName)

; --------------------------
; Menu System Configuration
; --------------------------

; Menu item definitions [Internal ID, Display Text, Command Template]
MenuItems := [
["header", "* * * Bot Control Menu * * *"],
["follow", "Follow Player", 'followPlayer("{}",4)'],
["block", "Search For Block", 'searchForBlock("{}",32)'],
["entity", "Search For Entity", 'searchForEntity("{}",32)'],
["collect", "Collect Blocks", 'collectBlocks("{}",32)'],
["log", "Tracker Log Section", ""],
["hotkeys", "Master HotKeys/Hotstrings", ""]
]

; Create menu structure
BotMenu := Menu()
BotMenu.SetColor("FFFFFF", true)

; Add menu items and disable header
for index, item in MenuItems {
if (item[1] = "header") {
BotMenu.Add(item[2], MenuHandler)
BotMenu.Disable(item[2])
} else {
BotMenu.Add(item[2], MenuHandler)
}
}

; Ctrl+Shift+M: Show menu
^+M::BotMenu.Show()

; --------------------------
; Menu Handler
; --------------------------

/**

  • Handles menu item selection and executes corresponding commands

  • @param {string} ItemName - Display name of selected menu item

  • @param {number} ItemPos - Position index of selected item

  • @param {Menu} ThisMenu - Reference to the menu object
    */
    MenuHandler(ItemName, ItemPos, ThisMenu) {
    item := MenuItems[ItemPos]

    Switch item[1] {
    Case "follow":
    MCSendCommand(VarBotName, StrReplace(item[3], "{}", GetPlayerName()))

     Case "block", "entity", "collect":
         ib := InputBox("Enter target for " item[2], "Bot Command")
         if ib.Result = "OK" && ib.value != "" {
             cmd := StrReplace(item[3], "{}", ib.value)
             MCSendCommand(VarBotName, cmd)
         }
     
     Case "log", "hotkeys":
         ToolTip "Feature coming soon!"
         SetTimer(() => ToolTip(), -2000)
    

    }
    }

/**

  • Prompts for player name input
  • @returns {string} Player name entered by user
    */
    GetPlayerName() {
    ib := InputBox("Enter player name", "Follow Player")
    return ib.Result = "OK" ? ib.value : "Desk509" ; Default value
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions