#[RESOLVED] HOW TO FIX DISABLE CONTAINER INTERACTION

1 messages · Page 1 of 1 (latest)

fast dragon
#

This is my code about disable player interaction when player trying to use container,but it have some issue

#
import { system, server } from '@minecraft/server';

let system = server.registerSystem(0, 0);

system.initialize = function() {
    this.listenForEvent("minecraft:script_logger_config", (eventData) => this.onScriptLoggerConfig(eventData));
    this.listenForEvent("minecraft:script_logger_config", (eventData) => this.onInteractWithContainer(eventData));
};

system.onInteractWithContainer = function(eventData) {
    let player = eventData.data.player;
    let container = eventData.data.container;

    if (container) {
        this.cancelEvent(eventData);
    }
};

system.cancelEvent = function(eventData) {
    eventData.cancel = true;
};
#

Here the script,my version is 1.21.21 pls help to fix it

#

When I run it it said server in module not export

#

I hope the code will let player can't interact with container and some block like trapdoor and bookshelf

#

** also I accept use any other way to made player can't use trapdoor and bookshelf**

frozen hazel
#

From the looks of it. You probably use AI to create this code, which is a mess of incorrect and nonexistent functionality.

fast dragon
#

So have another way to disable player interaction?

frozen hazel
#

Let me list out the things...

  1. Import of server doesn't exist, it's more likely to be world
  2. events for block interaction is still in beta, and it's called like this:
world.beforeEvents.playerInteractWithBlock```
#

The rest is just inccorect

fast dragon
#

Then how to reject interaction

frozen hazel
#

Have you tried to learn JavaScript first?

#

It would be easier explained that way

fast dragon
#

Sorry, I just learned Minecraft code not long time ago

deep hullBOT
frozen hazel
#

Aight, imma make a quick tutorial here, let's start with a simpler one.

Here's a list of afterEvents available in the beta API
In that, you'll find a list of properties corresponding to different types of events.

Here's an example of subscribing/listening to the event, block interaction, and saying "hello world" in the chat:
( it should run whenever you open a chest, ring a bell, or use crafting table. )

import { world } from "@minecraft/server";
world.afterEvents.playerInteractWithBlock.subscribe(()=>{
    world.sendMessage("Hello World!");
})

Contents of the @minecraft/server.WorldAfterEvents class.

fast dragon
#

Then how if I want to cancel it

frozen hazel
#

To cancel it, you need an alternate version of the events. The beforeEvents, runs before the action happens.

world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    evd.cancel = true;
})

(evd could by named anything here)

fast dragon
#

Thanks

#

@frozen hazel

#

Can I use

#

if(player.Hastag(admin)) to detect different players to assign permissions

fast dragon
#

@final flare

#
import { world } from "@minecraft/server";
world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    evd.cancel = true;
})
world.beforeEvents.playerBreakBlock.subscribe((evd)=>{
    evd.cancel = true;
    world.sendMessage({
  rawtext: [
    { text: "§c不要破壞地圖!" }]});
    player.playSound("random.hurt");
})
#

How to playsound when player break block

fast dragon
#

@frozen hazel

final flare
fast dragon
#

Not the playsound code problem

final flare
#

you need callback player in evd

fast dragon
#

How

final flare
#
const player = evd.player
fast dragon
#

Oh Thanks

#

@final flare but it said evd is not defind

#
import { world } from "@minecraft/server";
const evd.player = player
world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
})
world.beforeEvents.playerBreakBlock.subscribe((evd)=>{
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
    world.sendMessage({
  rawtext: [
    { text: "§c不要破壞地圖!" }]});
    player.playSound("random.hurt");
})
#

Do like this?

solar pecanBOT
#

Debug result for [code](#1285872096106381312 message)

Compiler Result

Compiler found 2 errors:

<REPL0>.js:2:10 - error TS1005: ',' expected.

2 const evd.player = player
           ~

``````ansi
<REPL0>.js:2:20 - error TS2448: Block-scoped variable 'player' used before its declaration.

2 const evd.player = player
                     ~~~~~~

  <REPL0>.js:2:11
    2 const evd.player = player
                ~~~~~~
    'player' is declared here.

Lint Result

ESLint results:

<REPL0>.js

2:9 error Parsing error: ',' expected

frozen hazel
#
import { world } from "@minecraft/server";

world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    const player = evd.player
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
})
world.beforeEvents.playerBreakBlock.subscribe((evd)=>{
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
    world.sendMessage({
  rawtext: [
    { text: "§c不要破壞地圖!" }]});
    player.playSound("random.hurt");
})
fast dragon
#

Uh ok thanks my skill have big issue

final flare
#

if it's this error use:

- player.playSound(`random.hurt`)
+ system.run(()=>{player.playSound(`random.hurt`)})
fast dragon
#

Ok thanks

final flare
#
import { world } from "@minecraft/server";

world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    const player = evd.player
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
})
world.beforeEvents.playerBreakBlock.subscribe((evd)=>{
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
    world.sendMessage({
  rawtext: [
    { text: "§c不要破壞地圖!" }]});
    system.run(()=>{player.playSound(`random.hurt`)}) //new code
})
fast dragon
final flare
#

lel.. send your code in here

fast dragon
#

Sure

#
import { world, system } from "@minecraft/server";
world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    const player = evd.player
    if (evd.player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
})
world.beforeEvents.playerBreakBlock.subscribe((evd)=>{
    if (evd.player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
    world.sendMessage({
  rawtext: [
    { text: "§c不要破壞地圖!" }]});
    system.run(()=>{player.playSound(`random.hurt`)})
})
#

What changed

final flare
#

my bad, i didn't check when sending

#

look in new code

fast dragon
#

What

#

; ?

#

I changed the if(playerhastag to if(evd.playerhastag

#

Oh I understand

final flare
#
world.beforeEvents.playerInteractWithBlock.subscribe((evd)=>{
    const player = evd.player
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
})
world.beforeEvents.playerBreakBlock.subscribe((evd)=>{
    const player = evd.player // new code
    if (player.hasTag('WorldBuilder')) return;
    evd.cancel = true;
    world.sendMessage({
  rawtext: [
    { text: "§c不要破壞地圖!" }]});
    system.run(()=>{player.playSound(`random.hurt`)})
})
fast dragon
#

Thanks for yall help