#player place a block event [RESOLVED]

1 messages · Page 1 of 1 (latest)

gilded rock
#

i tried use world.beforeEvents.playerPlaceBlock

#

but its not working

split vortex
#

Send the whole code

gilded rock
#

world.beforeEvents.playerPlaceBlock.subscribe(ev => {
const loc = ev.block.location;
if (isInZone(loc)) {
ev.cancel = true;
ev.player.sendMessage("§ccant break this block !");
}
});

gilded rock
# split vortex Send the whole code
world.beforeEvents.playerPlaceBlock.subscribe(ev => {
    const loc = ev.block.location;
    if (isInZone(loc)) {
        ev.cancel = true;
        ev.player.sendMessage("§ccant break this block !");
    }
});
thick flax
#

What does "isInZone" do??

ancient herald
#

@gilded rock

import { world } from "@minecraft/server";

// Define the corners of the protected area
const zone = {
    x1: 10,
    y1: 0,
    z1: 10,
    x2: 20,
    y2: 256,
    z2: 20
};

// Function to check if a location is inside the protected zone
function isInZone(loc) {
    return (
        loc.x >= Math.min(zone.x1, zone.x2) && loc.x <= Math.max(zone.x1, zone.x2) &&
        loc.y >= Math.min(zone.y1, zone.y2) && loc.y <= Math.max(zone.y1, zone.y2) &&
        loc.z >= Math.min(zone.z1, zone.z2) && loc.z <= Math.max(zone.z1, zone.z2)
    );
}

// Subscribe to the player placing a block event
world.beforeEvents.playerPlaceBlock.subscribe(ev => {
    const loc = ev.block.location; // Get the location of the block being placed
    if (isInZone(loc)) {
        ev.cancel = true; // Cancel block placement
        ev.player.sendMessage("§cYou can't place blocks in this protected zone!");
    }
});```
#

I didn't try it, and I did it with pure AI, but maybe it gives you an idea.

lyric pilot
thick flax
#

Can beforeEvents send a player message, don't you need a system.run()??

lyric pilot
#

player.sendMessage CAN be run in readonly mode

#

I need to see the error message.

#

wait I just realized that response was from a person who fixed it lol

thick flax
#

Oh yeah

#

That's what reading discord at 4am does

lyric pilot
gilded rock
ancient herald
ancient herald
gilded rock
#

?

#

it only work in 2.0.0-beta ?

ancient herald
gilded rock
#

because all my script are in 1.19.0

#

and if i change in 2.0.0 the dynamic properties will not work

#

but its ok i will try add an other pack only for 2.0.0

#

beta

gilded rock
#

player place a block event [RESOLVED]

lyric pilot
#

you can just do await system.waitTicks(1);