hello! i am trying to make a command block/s that senses if a player comes near it, and then it chooses to kill them, or let them walk bye, depending on if they are a certain player. So lets say i want it to let me by, but if anyone else walks bye, the would get killed. does anyone know how to do this? I used to to it with the /testfor command, but it doesn't exist anymore.
4
/testfor was removed in 1.13, where it was replaced with "/execute if/unless entity <entity selector>" which lets you essentially incorporate an unlimited number of tests into a single command. However, the best way to do this is just an entity selector.
/kill @e[tag=!<tag>,distance=<target_range>] will kill all players in range <target_range> that do not have the tag <tag>.
Range values in 1.13+ are used in entity selector arguments and scoreboard values. They work like this:
You want distance:..10 to kill all players in 10 blocks, for example.
Tags are pieces of data attached to entities that you can sort them by. You can add or remove them with /tag (1.13+) or /scoreboard players tag (1.12 or earlier).
For example, if you do "/tag <player> add give_items" and then run "/give @e[tag=give_items] minecraft:diamond 64" it will give whatever players were tagged the diamonds. You want to give yourself the tag BEFORE you set up the death loop, since it will kill you as it starts if you do not have it.
Again, the commands are
/tag @p add allowed_in
kill @a[distance=..5,tag=!allowed_in]
/kill @e[tag=!<tag>,distance=<target_range>] will kill all players in range <target_range> that do not have the tag <tag>.
Range values in 1.13+ are used in entity selector arguments and scoreboard values. They work like this:
| Example of a range | Meaning of range |
| 4 | Exactly 4 (blocks away) |
| 2.. | 2 or more (blocks away) |
| ..5 | 5 or less (blocks away) |
| 4..10 | inbetween 4 and 10 (blocks away) |
You want distance:..10 to kill all players in 10 blocks, for example.
Tags are pieces of data attached to entities that you can sort them by. You can add or remove them with /tag (1.13+) or /scoreboard players tag (1.12 or earlier).
For example, if you do "/tag <player> add give_items" and then run "/give @e[tag=give_items] minecraft:diamond 64" it will give whatever players were tagged the diamonds. You want to give yourself the tag BEFORE you set up the death loop, since it will kill you as it starts if you do not have it.
Again, the commands are
/tag @p add allowed_in
kill @a[distance=..5,tag=!allowed_in]
Wow thanks sooo much!
/testfor (player you want to kill) [r= (how far you want it) just do a number like 1 block 2 blocks away. and make it a repeating command block and always active
once your done with that place a comparator in front of that command block, then a repeater in front of that. then hook it up to another command block that says /kill @p
and that's it,
if you are confused contact me,
once your done with that place a comparator in front of that command block, then a repeater in front of that. then hook it up to another command block that says /kill @p
and that's it,
if you are confused contact me,
Hey so the /testfor command was removed. But thanks for trying to help!
