#player place a block event [RESOLVED]
1 messages · Page 1 of 1 (latest)
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 !");
}
});
world.beforeEvents.playerPlaceBlock.subscribe(ev => {
const loc = ev.block.location;
if (isInZone(loc)) {
ev.cancel = true;
ev.player.sendMessage("§ccant break this block !");
}
});
What does "isInZone" do??
@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.
What error did you get in the content error log?
Can beforeEvents send a player message, don't you need a system.run()??
no
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
11:32 PM for me, surrounded by oil paint fumes.
i have all this its just the world before events is not working
The playerPlaceBlock event is not currently available in the latest stable version of Minecraft Bedrock Edition; it is only available in the beta version. That’s why it doesn’t work for you in the stable release.
I just realized that. The last time I used it, the event was available. I updated Minecraft just yesterday.
I guess that’s it, but I didn’t opt into beta updates. I suggest you check it out yourself.
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
player place a block event [RESOLVED]
no you just have to make it wait a tick
you can just do await system.waitTicks(1);