1

On the latest version of Minecraft Bedrock edition is it possible to have a command block (When activated) check for the nearest player's name and kill them if it does not add up to a pre-entered name?

For example, if "Player1" steps on the pressure plate that activates the command block they do not die, however, if "Player2" steps on the pressure plate that activates it, they die.

Edit: Using more than one command block.

2 Answers 2

2

Simpler solution

There is often a better command that can be used instead of /testfor, if you have a pressure plate that should only kill "Player2", you can simply use this command:

/kill @a[name=Player2,x=~,y=~2,z=~,r=1]

This is assuming that you have the command block 2 blocks under the pressure plate.

More general solution with /execute

Whenever you want to use /testfor, you can likely use /execute instead, simply by putting the target selector from the /testfor command into it.

If you want to kill "Player2" if a zombie is within 5 blocks distance from the command block, then you could use /testfor @e[type=zombie,r=5] in a command block and then /kill Player2 in a conditional chained command block.

This could be done more easily by putting the target selector from the first command into an /execute command:

/execute @e[type=zombie,r=5] ~ ~ ~ kill Player2

Even more general solution

In some extremely rare cases I can't think of any situation where you really need anything beyond /execute right now even this may not be enough, maybe you want to execute several commands as a specific group of mobs that may not be detectable with the same target selector after every command.

If you really need something like this, then you can set up a scoreboard objective:

/scoreboard objectives add objectives dummy

Setup for a even more general solution

You would use one repeating command block that continuously sets the score of all entities to 0, the scoreboard objectives will be used to determine what entities to execute as:

scoreboard players reset * objectives

For every system that you want to set up you would then set the scoreboard score with the same target selector you would use with /testfor, or /execute. Each score value should be unique to every setup:

scoreboard players set @e[type=zombie] objectives 1

You would then use a chain of command blocks, one for each command that you want to execute. You would likely use /execute again, maybe in a command like this:

execute @e[scores={objectives=1}] ~ ~ ~ kill @a[r=5]

This example would kill all players within 5 blocks of any zombie, it could be done more easily with /execute @e[type=zombie] ~ ~ ~ kill @a[r=5].

1
  • I'd be interested if someone can come up with a situation where the "Even more general solution" actually would be required. Even better if it's something that feels usable and not constructed specifically for this, but a constructed example would be interesting enough.
    – user232393
    Sep 4, 2019 at 20:59
0

You can use testfor to test if the player is at the specified position, then use a comparator to trigger another command.

Put testfor @p[name=Name,x=X,y=Y,z=Z,r=maxRadius] in an impulse, unconditional, needs redstone command block that would activate when the pressure plate is activated. Name is the name of the player (in your example Player2). maxRadius is the maximum distance (Euclidean) from X, Y, Z that the player needs. Alternatively, you can use dx, dy, and dz to define cubic volumes. Without these, testfor will always be successful as it would find Name, no matter how far away.

For example: testfor @p[name=Player2,x=10,y=40,z=5,r=2] would activate the second command if Player2 is within 2 blocks of 10, 40, 5.

Then put a comparator (comparison mode) facing away from the command block into another command with the command, such as kill Player2.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .