Skip to content

Custom Modules

SenkJu edited this page Sep 1, 2019 · 9 revisions

Example

function ExampleModule() {

    var myBoolValue = value.createBoolean("MyBoolValue", true);

    // 'getName()' returns the name of the module. This name will be used in the ClickGUI/TabGUI.
    this.getName = function() {
        return "TestModule";
    };

    /* 'getDescription()' returns the description of the module. 
    It can be seen when hovering the module in the ClickGUI. */
    this.getDescription = function() {
        return "This module has been created using LiquidBounce's scripting API.";
    };

    // 'getCategory()' returns the name of the ClickGUI/TabGUI category the module should be added to.
    this.getCategory = function() {
        return "Exploit";
    };

    // 'onEnable()' is being executed once the user activated the module.
    this.onEnable = function() {
        if (myBoolValue.get()) {
            chat.print("MyBoolValue is enabled.");
        } else {
            chat.print("MyBoolValue is disabled.");
        }

        chat.print("§c§lHey! I am now enabled.");

        myBoolValue.set(false);
    };

    /* 'onDisable()' is being executed once the user disabled the module. 
    Changed Minecraft values should be reset here. */
    this.onDisable = function() {
        chat.print("§c§lBye! I am now disabled.");
    };

    /* 'onUpdate()' is being executed constantly (every tick => 20 times per seconds) 
    if the module is enabled. */
    this.onUpdate = function() {
        mc.thePlayer.swingItem();
    }

    /* In 'addValues' custom values can be added to a module. Those will appear in the ClickGUI 
    and can be changed by the user. */
    this.addValues = function(values) {
        values.add(myBoolValue);
    }
}

Module Events

this.onEnable = function() {
    // Code in here will be executed directly after the module has been enabled by the user 
};

this.onDisable = function() {
    // Code in here will be executed directly after the module has been disabled by the user 
};

this.onUpdate = function() {
    // Code in here is being executed every tick (~20 times per seconds)
};

this.onMotion = function(event) {
    // Code in here is being executed everytime the player receives motion

    var eventState = event.getEventState();
    eventState.getStateName(); // PRE or POST 
};

this.onRender2D = function(event) {
    // Code in here will be executed when the client draws its 2D elements

    var partialTicks = event.getPartialTicks(); // Used to render FPS independent animations
};

this.onRender3D = function(event) {
    // Code in here will be executed when the client draws its 3D elements

    var partialTicks = event.getPartialTicks(); // Used to render FPS independent animations
};

this.onAttack = function(event) {
    // Code in here will be executed when an entity is being attacked

    var targetEntity = event.getTargetEntity();
};

this.onJump = function(event) {
    // Code in here will be executed when the player jumps
    
    event.cancelEvent() // Cancels the event
    event.isCancelled() // Whether the event has been cancelled

    var motion = event.getMotion();
    event.setMotion(0.42);
};

this.onPacket = function(event) {
    // Code in here will be executed when the client receives a packet

    event.cancelEvent() // Cancels the event
    event.isCancelled() // Whether the event has been cancelled

    var packet = event.getPacket();
};

this.onKey = function(event) {
    // Code in here will be executed when a key is pressed

    var pressedKey = event.getKey(); // ID of the pressed key (https://minecraft.gamepedia.com/Key_codes)
};

this.onMove = function(event) {
    // Code in here will be executed when the player moved

    var x = event.getX(); // Returns x-position of move
    var y = event.getY(); // Returns y-position of move
    var z = event.getZ(); // Returns z-position of move
    var isSafeWalk = event.isSafeWalk(); // Whether SafeWalk is enabled for this event

    event.setX(100); // Sets x-position of move to 100
    event.setY(100); // Sets y-position of move to 100
    event.setZ(100); // Sets z-position of move to 100
    event.setSafeWalk(true); // Prevents player from falling of the edge of blocks
}

Adding values to modules

Values will be visible in the ClickGUI and can be changed by the user. If a module is using settings instead of hard-coded values, it is more customizable for the user.

// Values must be registered manuelly
this.addValues = function(values) {
    values.add(myValue1);
    values.add(myValue2);
}

Available value types

// BoolValue - Either true or false
var myBoolValue = value.createBoolean(valueName, defaultValue);

// BlockValue - Used for selecting a block
var myBlockValue = value.createBlock(valueName, defaultBlockId);

// FloatValue - Slider allowing the user to select a floating-point number
var myFloatValue = value.createFloat(valueName, defaultValue, minValue, maxValue);

// IntegerValues - Slider allowing the user to select an integer number
var myIntValue = value.createInteger(valueName, defaultValue, minValue, maxValue);

// ListValue - Allowing the user to select one item from the list of available values
var myList = value.createList(valueName, [possibleValue1, possibleValue2, possibleValue3], defaultValue);

// TextValue - Allowing the user to specify any string as its value
var myTextValue = value.createText(valueName, defaultValue);

Setting and getting a value

// BoolValue - Either true or false
var myBoolValue = value.createBoolean("MyBoolValue", true);
myBoolValue.get(); // true
myBoolValue.set(false); // Sets value to false