CheatUtils by Zergatul

CheatUtils by Zergatul

32.5k Downloads

auto disconnect when player comes into range

Calianthus opened this issue ยท 2 comments

commented

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

commented

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
    }
}
commented

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