1
Hi guys 'n girls!
This is a problem i've had for a long time. I know you are able to use the symbol @p to target the nearest player. But is there a way to target the exact person that activates the command block? Let's say i put a button beside a commandblock, and made it give me an apple. What can i do so it will target the exact player which presses the button?
Thanks guys
This is a problem i've had for a long time. I know you are able to use the symbol @p to target the nearest player. But is there a way to target the exact person that activates the command block? Let's say i put a button beside a commandblock, and made it give me an apple. What can i do so it will target the exact player which presses the button?
Thanks guys
4
You coud use the old Villager trick. When a Player clicks a Villager with empty trades, no GUI pops up, but it still counts as trading. Trading with Villagers can be tracked with a scoreboard. Now place anywhere an invisible Villager with a special tag, lets say "button" and create a scoreboard "scoreboard objectives add click_villager stat.tradedWithVillager". Now if the score increases for any Player, test if there is a Villager with the tag "button" near them. If so the Player clicked the Button. Then you just have to reset the score and activate the commandblock.
I do agree with that. If you thought what i said was confusing, go back to what Cadermate said and use a command sign. They can be multiple colors and give the player an item or do other stuff.
I'm sorry to tell you that there is no way to target the player who presses the button without add-ons, but the only thing close enough that you can do is do like you said with the @p:
execute @p ~ ~ ~ (your command here)
that is the closest possible thing you can get to in vanilla.
But, however, you can use clickable signs to target the player who clicks the sign in the place of a button (I also find signs much more attractive than buttons.)
you can use this sign generator here.
https://minecraftcommand.science/command-sign-generator
execute @p ~ ~ ~ (your command here)
that is the closest possible thing you can get to in vanilla.
But, however, you can use clickable signs to target the player who clicks the sign in the place of a button (I also find signs much more attractive than buttons.)
you can use this sign generator here.
https://minecraftcommand.science/command-sign-generator
Good question. Many YouTubers and other Minecrafters all had this same question. I will give you the best answer I can come up with.
First thing's first. What you are trying to do is correct, but there is another work-around. If you use a Pressure Plate (stone or wood) you can make it do exactly what you want a lot easier. You can put a Pressure Plate on a block with a command block under the block. Good to go!
Second, there is yet another work-around: what if you want to still use a button? Easy. Make an area for the person to stand on, place your button wherever. The command block you place to give the player the apple should now actually be a /setblock command. Let's say the player stands at 0 64 0. The block under is just a block. The block under that (at 0 62 0) is a command block. That command block will have
0 64 0 = Player
0 63 0 = block of choice (not redstone)
0 62 0 = Command Block (Command: /give @p apple 1)
0 61 0 = block of choice (not redstone)
0 60 0 = Command Block (Command: /setblock ~ ~1 ~ air 0 replace)
Now go back to the button. Behind it, behind the block the button is on, run this command:
Thought that was the end? There is one more way. Just one question: what is the location where you want the player to receive the apple? The coordinates? I will continue until I have the exact (press f3 and look at "Block", or 1 block above "Looking At"). Glad to help!
First thing's first. What you are trying to do is correct, but there is another work-around. If you use a Pressure Plate (stone or wood) you can make it do exactly what you want a lot easier. You can put a Pressure Plate on a block with a command block under the block. Good to go!
Second, there is yet another work-around: what if you want to still use a button? Easy. Make an area for the person to stand on, place your button wherever. The command block you place to give the player the apple should now actually be a /setblock command. Let's say the player stands at 0 64 0. The block under is just a block. The block under that (at 0 62 0) is a command block. That command block will have
/give @p apple 1. Below that block (0 61 0) is a regular block. The one below that will now be another command block with /setblock ~ ~1 ~ air 0 replace. So the final product:0 64 0 = Player
0 63 0 = block of choice (not redstone)
0 62 0 = Command Block (Command: /give @p apple 1)
0 61 0 = block of choice (not redstone)
0 60 0 = Command Block (Command: /setblock ~ ~1 ~ air 0 replace)
Now go back to the button. Behind it, behind the block the button is on, run this command:
/setblock 0 61 0 redstone_block 0 replace. This will place that block at the location, give the player an apple, and then replace the redstone block with air, resetting the mechanism.Thought that was the end? There is one more way. Just one question: what is the location where you want the player to receive the apple? The coordinates? I will continue until I have the exact (press f3 and look at "Block", or 1 block above "Looking At"). Glad to help!
