Skip to content

Custom Scripts

ancymon edited this page Sep 2, 2024 · 2 revisions

Overview

This section guides you through the process of creating, downloading, and injecting custom scripts for the Minecraft Bot Panel (MCBP). Custom scripts allow you to extend and personalize the behavior of your bots.

Downloading Custom Scripts

You can download custom scripts from the official MCBP community on Discord. Join the server to find a variety of scripts shared by other users.

Discord Link: Join Our Discord

Injecting Custom Scripts

Once you have created or downloaded a custom script, you need to inject it into the MCBP.

Steps to Inject a Script:

  1. Locate the MCBP Directory:

    • If installed via setup .exe:
      • Navigate to %appdata% => Local => minecraft_bot_panel
    • If installed via zip file:
      • Open the directory where you extracted the files.
    • Navigate to .\resources\app.asar.unpacked\custom\scripts.
  2. Place the Script:

    • Move your .js script file into the scripts directory located in the paths described above.
  3. Reload or Restart MCBP:

    • After placing your script, restart the Minecraft Bot Panel. Your script should now appear in the MCBP interface, ready to be used.

Creating a Custom Script

To create a custom script, you'll need to make a .js file with the following template:

let info = {
  name: "<name>",  // Replace <name> with the script's name | NOTE: Using spaces in names may result in many bugs
  default: { interval: 200 },  // Default settings for the script
  options: [
    // Add options here, e.g., { type: 'input', label: 'Block ID' }
  ],
};

function script(bot, log, clearLog, getOption, scriptRepeater) {
  // Your script logic goes here
}

module.exports = {
  info,
  script,
};

getOption

In order to get the value of an option declared in let info use:

getOption("<option_id>", info.name) // Replace <option_id> with the actual option's ID
   .then((value)=>{
      console.log(value) // Example   
   })

As you can see getOption returns a Promise.

Option: Repeat

To loop your script if user selected it:

let info = {
  name: "ScriptExample",
  default: { interval: 200 },
  options: [
    {
      type: "checkbox",
      label: "Repeat",
      id: "repeat",
    },
  ],
};

It's important to set the type to "checkbox" and id to "repeat"

function script(bot, log, clearLog, getOption, scriptRepeater) {
  getOption("repeat", info.name).then((r) => {
    function yourFunction() {
        // Your code
    } 
    if (r === "on") {
      scriptRepeater(yourFunction, info.default.interval).then(() => { // Feel free to change info.default.interval into a number or value in let info 
        return;
      });
    } else yourFunction();
  });
}

Custom Function: log(text)

log(text) "logs" the text you've provided into the MCBP's logs tab.

Custom Function: clearLog(text)

clearLog(text) clears every already logged message that include provided text.

Function: bot()

Mineflayer Documentation