Zergatul / cheatutils

MIT License
33 stars 11 forks source link

auto disconnect when player comes into range #68

Closed Calianthus closed 3 months ago

Calianthus commented 3 months ago

is there any way to auto disconnect when a player comes into a certain range/straight up rendered? i couldnt find any methods to do this with scripting, also if there is a way to send a message in chat when this occurs as well

Zergatul commented 3 months ago

For latest 1.20.4, I don't remember if all these methods are available in older versions

int otherPlayerId = game.entities.findClosestEntityById("minecraft:player");
if (otherPlayerId > 0) {
    float dx = player.getX() - game.entities.getX(otherPlayerId);
    float dy = player.getY() - game.entities.getY(otherPlayerId);
    float dz = player.getZ() - game.entities.getZ(otherPlayerId);
    float distance = math.sqrt(dx * dx + dy * dy + dz * dz);
    if (distance < 10) {
        string name = game.entities.getName(otherPlayerId);
        // main.systemMessage("Player: " + name + " nearby"); // show message in chat
        // player.disconnect("", "Player: " + name + " nearby"); // or disconnect
    }
}
Calianthus commented 3 months ago

TYSMMMM i really appreciate it and i love this mod keep up the great work!!!