Arqade Asked by Aru123 on May 26, 2021
I need a scoreboard that detect the player opening a chest, but I also want it to reset the score when it leaves the chest hud. Is it possible?
/scoreboard objectives add Chest minecraft.custom:minecraft.open_chest
Will add one point to every player that opens a chest, you can test for it like this:
execute as @a[scores={Chest=1..1,ChestCount=0..0}] if entity @s run *command*
*command* is the command that tells you that the player uses a chest, for example:
tell *your name* @s Is using a chest!
Then you need to tell when the player leaves the chest which can't really be done, but you can tell when the player starts to move. However, you need to test for if the player walks, sprints, crouches, climbs, or jumps. Otherwise, the player could break the system.
You can do that by adding scoreboards to these 5:
/scoreboard objectives add Crouch minecraft.custom:minecraft.crouch_one_cm
/scoreboard objectives add Walk minecraft.custom:minecraft.walk_one_cm
/scoreboard objectives add Sprint minecraft.custom:minecraft.Sprint_one_cm
/scoreboard objectives add Climb minecraft.custom:minecraft.climb_one_cm
/scoreboard objectives add Jump minecraft.custom:minecraft.jump
Using the same execute command above you can test for these as well. However, if the player stands still after they closed the chest you won't be able to tell from the score/tests.
You can test for when the player opens a chest, reset the 5 movement scores:
execute as @a[scores={Chest=1..1,ChestCount=0..0}] if entity @s run
scoreboard players set @s Walk 0
execute as @a[scores={Chest=1..1,ChestCount=0..0}] if entity @s run
scoreboard players set @s Sprint 0
etc.
You then give the player another dummy score so the commands don't loop:
execute as @a[scores={Chest=1..1,ChestCount=0..0}] if entity @s run
scoreboard players set @s ChestCount 1
Do this in a command blockchain to make it simpler.
For the movement detection in another repeating command block, you put:
execute as @a[scores={Walk=100..,ChestCount=1..1}] if entity @s run
say @s Isn't using a chest!
The next block should be a chain block:
execute as @a[scores={Walk=100..,ChestCount=1..1}] if entity @s run
scoreboard players set @s Chest 0
And the last chain block resets the dummy ChestCount
score:
execute as @a[scores={Walk=100..,ChestCount=1..1}] if entity @s run
scoreboard players set @s ChestCount 0
Then you repeat this 4 times for the sprint score, crouch score, climb score, and jump score, but instead of testing for a score of 100..
you test for a score of 1 or more, like this:
execute as @a[scores={Sprint=1..,ChestCount=1..1}] if entity @s run
say @s Isn't using a chest!
The reason for this is that you can run into a chest and add to the walking score after you have opened the chest, but this only applies to walking, none of the others.
This should be multiplayer friendly as well but haven't tested this.
Note
Cange the command of the first execute command to the command that tells you when someone is using a chest as I explained on the very first execute-command I wrote. I just copied from my world and currently, it says say @s Isn't using a chest!
Correct answer by Semlan Bakelsen on May 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP