3

I want to target a specific player when they do an action such as open a door, step on a pressure plate, press a button, etc.

Currently, using @p on a pressure plate directly over a command block is not good enough, as another player can actually stand closer to the command block by standing in the center of the pressure plate.

If I were to do a /testfor ~ ~1 ~ stone_button 9 that only tracks if the button is pressed, but I then can't use @s in anothe command block to do an action on the press of the button.

So my question is, what actions can a player perform which I can then target them with using @s?

3

Using commands you can check for everything that is tracked by the scoreboard (see https://minecraft.gamepedia.com/Scoreboard#Criteria) or trackable through advancement triggers (https://minecraft.gamepedia.com/Advancements#List_of_triggers).

sadly, none of the things you mentioned (open door, step on pressure plate, click button) are trackable at this point.
(which is also why mapmakers often use clickable signs instead of buttons so they know which player clicked it)

  • This is very helpful, thank you. Could you provide a link to more details about the clickable signs? Or is that a mod/plugin? – Jake Bristow Mar 21 '18 at 17:10
  • @JakeBristow The format used for storing text on signs allows you to embed "onClick" events, including commands that will be run when the sign is right-clicked. The command will use the player that clicked as @s, and will be run at the coordinates of the sign. Very useful. Here's a nice generator: minecraft.tools/en/sign.php – AjaxGb Mar 21 '18 at 17:31
1

Moving my comment to an answer:

The format used for storing text on signs allows you to embed "onClick" events, including commands that will be run when the sign is right-clicked. The command will target the player that clicked as @s, and will be run at the coordinates of the sign. Very useful, and seems to be just what you're looking for.

Here's a nice generator: minecraft.tools/en/sign.php

You can find more information on sign's data format here, and on Minecraft's JSON text format here.

0

Since i lost access to my old account, I must use an answer (although it works for Bedrock Editions at this time).

Stone and Wooden pressure plates have data value 0 to represent unpressed, and I forgot what to represent pressed. Weighted pressure plates (Iron / Gold) have 0 to represent nothing on it, yet I forgot if it increases as more entities get on it.

Levers as well as both buttons use the data value to represent both the facing and its powered / unpowered state (0-5 for unpowered, 8-13 for powered). To figure out which is which, just add or subtract 8 depending on its value to get its respective value for the opposite powered state.

For doors, check the lower block's data value as the upper block does not really help, except tell you it has something below it. (It also applies the "facing and powered" idea as levers and buttons, but in a different way.

Once again: Bedrock Edition only and subject to change with updates to the game.

EDIT: To make it work: /execute <target-specifier> <command-position> detect <block-id> <block-data> <detect-position> <command>
Where:
<target-specifier> would probably be something like @a[x=~,y=~2,z=~,dx=1,dy=1,dz=1] (if the layout is "pressure-plate > solid block > this command block".
<command-position> where the command would execute (using relative coordinates at any of the x/y/z means relative to that entity this command is being executed upon.
<block-id> is the named id of the block to detect.
<block-data> is the numeric data value of the block to detect.
<detect-position> where to detect the block (relative positions are relatice to what was specified as the command's executing location (see <command-position>).
<command> is the command to run, without leading /, and is to be like the entity being acted upon is executing it whils having all the permissions that a command block has (meaning no /ban, /op, /deop, etc.).
-- I might have accidentally swapped the <detect-position> accidentally (it might be actually immediately after detect).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.