Arqade Asked by TheOddSteakGuy on October 26, 2020
I want to tp someone holding a specific item (diamond sword), but I don’t want it to be a /clear @p[r=5] diamond_sword
and a /tp @p x y z
command linked together because there will be more than one person in the room and only one will be holding a diamond sword, and the above command will just clear the sword and tp a person that may not be the holder of the sword. (I’m playing windows 10 edition on Xbox One)
These instructions work for Java Edition, I don't know if it's different in Console Edition. It definitely does not work for Pocket/Windows 10 Edition, because NBT doesn't work there.
You can use the /scoreboard
command to tag players based on their NBT data. You would for example want this:
/scoreboard players tag @a add test {SelectedItem:{id:"minecraft:diamond_sword"}}
This everyone with "test" who is holding a diamond sword. Then you can just target players with the tag like this:
/tp @a[tag=test] <x> <y> <z>
Afterwards you have to remove the tag again so that it's ready to use the next time:
/scoreboard players tag @a[tag=test] remove test
Answered by Fabian Röling on October 26, 2020
There isn't a good way to inspect player inventories on bedrock. The closest you can manage is something like the following:
/enchant @a sharpness 1
This command would succeed if any player is holding a sword, but can't be made to be limited to a type of sword. It also can't be used to determine which player was holding the sword.
The following command will detect if someone has a diamond sword in their inventory, but not whether they're holding it.
/clear @p diamond_sword -1 0
If you're willing to compromise your design a little, you could have the player drop the sword and then detect it via the following command chain:
/execute @e[type=item,name="diamond_sword"] ~~~ tp @p x y z
This largely guarantees the player who had the sword is teleported because the item will be closest to the player who dropped it.
This leaves the player without a sword however and leaves the sword available for the other players to pick up. Both problems are solvable by additional command chains.
You can kill the sword to remove it so other players can't get it.
/kill @e[type=item,name="diamond_sword"]
And then give the teleported player back a diamond sword.
/replaceitem entity @p slot.weapon.mainhand 1 diamond_sword
This will have the side effect of restoring the sword's durability.
Answered by peabody on October 26, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP