#how would i stop a player from mining a block if there score isnt high enough

1 messages · Page 1 of 1 (latest)

radiant mural
#

i want to make it if someone's level is below the required level for that block the block will just spawn back in

#

will the after event stil run if the block is broken by someone who isnt the level needed?

golden comet
#

And you event.cancel = true if the player doesn’t have the required score

radiant mural
golden comet
#

After event only runs when the block actually breaks

#

Before event runs right before the after event( before the block is broken)

#

So you can cancel it and the after event won’t run

tranquil aspen
#

as simple as js world.beforeEvents.playerBreakBlock.subscribe(ev => { const { block, player, itemStack } = ev; ev.cancel = true; });

golden comet
radiant mural
golden comet
radiant mural
golden comet
radiant mural
#

so the item used

golden comet
jolly edge
#
const ob = "rank"
world.beforeEvents.playerBreakBlock.subscribe((ev)=>{
  const {block,player,itemStack:item} = ev
  const scoreboard = world.scoreboard.getObjective(ob) ?? system.run(()=> world.scoreboard.addObjective(ob))
  const score = scoreboard.getScore(player) ?? 0
  if (score < 5 && block.typeId == "minecraft:dirt" && item.typeId == "minecraft:diamond_sword") return ev.cancel = true
})
tranquil aspen
golden comet
tranquil aspen
#

wait, I'm not kinda sure but I don't think you can use system.run() after the ?? Operator

tranquil aspen
jolly edge
#

oh, wait it can't

tranquil aspen
#

-# tho I still won't do that lol

#

Uhh

#

Sooo. I'm correct?

jolly edge
tranquil aspen
#

it makes sense why because ?? Is a left hand right hand shit

#

yep, it ignores the system.run

jolly edge
#

yup, best to push it all in system.run

tranquil aspen
#
let obj = world.scorebord.getObjective();
if (!obj) obj = world.scoreboard.addObjective();```
#

this works fine

jolly edge
tranquil aspen
#

I mostly used that way and yeah no probs

tranquil aspen
jolly edge
#

lel

radiant mural
tranquil aspen
jolly edge
#
const ob = "rank"
world.beforeEvents.playerBreakBlock.subscribe((ev)=>{
  const {block,player,itemStack:item} = ev
  let obj = world.scorebord.getObjective(ob);
  if (!obj) obj = world.scoreboard.addObjective(ob);
  const score = obj.getScore(player) ?? 0
  if (score < 5 && block.typeId == "minecraft:dirt" && item.typeId == "minecraft:diamond_sword") return ev.cancel = true
})
radiant mural
tranquil aspen
jolly edge
#

oh, wait i see something

#

i just copy and paste your code

#

that's another error

tranquil aspen
#

here lol, I made a mistake about what I send lol

jolly edge
#

xD

tranquil aspen
#

I didn't if (!obj) obj = ... it

#

damn, I'm getting old asf I keep forgetting shirs

tranquil aspen
jolly edge