How to get testfor to go on and off as I please

How to get testfor to go on and off as I please - Yellow Pikachu Plushmascot

I am making a map with friends and I set up a shop keeper to say "hello" when you get within a few blocks, but it has some bugs I would like help with:

  1. I am trying to get it to constant check if someone is there but only run the command once!
  2. I want to find the player, say "hello" and let the player do there stuff. But if the player leaves and comes back I want it to say "hello" again.

If you need further detail say so, I've been on this for hours.



Best Answer

How I understand it you just put a fast clock go into a command block (or 1.9's repeating command block) with the command testfor @p[r=5] (replace 5 with anything) then a comparator coming out of that command block and into a command block with say hello or however you wish to output text.




Pictures about "How to get testfor to go on and off as I please"

How to get testfor to go on and off as I please - Overjoyed African American graduate tossing copies of resumes in air after learning news about successfully getting job while sitting in green park with laptop
How to get testfor to go on and off as I please - Go Neon Light Signage
How to get testfor to go on and off as I please - Crop anonymous child getting brown stones from white container at home



Quick Answer about "How to get testfor to go on and off as I please"

  • Create a pulsor, like with two hopper connected.
  • Get the redstone signal to a command block with the command inside (2 = 2 blocks wide from the command block) : /testfor @p[r=2]
  • Put a comparator as output of the command block going on a second command block with the /tellraw command with @p arg.


  • What replaced the Testfor command in Minecraft?

    The /testfor command became obsolete in Minecraft 1.13, and has been replaced by the /execute command*. It will do the same as typing /testfor @e {SelectedItem:{id:"<item>"}} and then putting a comparator to the command block with the command, and then running the command which you wanna run.

    How do you do the Testfor command in Minecraft?

    2. Type the Command
  • Test if Players are within 10 blocks. In this example, we will test to see if there are any players within a 10 block radius with the following command: /testfor @a[r=10] ...
  • Test if Mooshrooms are within 50 blocks. ...
  • Test if Nearest Player is at Level 20 experience.


  • How do you use Testfor items?

    You can use the /trigger command to create a trigger that sets or adds values to scoreboard objectives that trigger enabled in Minecraft.



    Minecraft Bedrock - Test For Items In Inventory (Mobile/Xbox/PS4/Windows 10/Switch)




    More answers regarding how to get testfor to go on and off as I please

    Answer 2

    The following worked for me in Minecraft 1.9.2:

    1. Place a repeating command block, and enter the command "testfor @p[r=n]" where n is the maximum distance in blocks that a player must be from the command block for the villager to "say" hello. In the options for the repeating command block, click the button to the right that says "Needs Redstone," and it will change to "Always Active." So in order the three options say: Repeat, Unconditional, Always Active. Your chat might be spammed with "[@: Found <username>]" when anyone gets within the maximum range. To fix this, type "/gamerule commandBlockOutput false" and command blocks will not report command outputs anymore.
    2. Place a redstone comparator with the A end of it (the side with the two torches) against the command block. You'll notice it lights up whenever the a player enters the maximum range.
    3. Redstone dust coming off of the C end of the comparator (directly across from the A end) is optional, but I added one. Place a sticky piston touching the redstone or the C end of the comparator, facing any of three directions but not with the moving end towards the comparator.
    4. Put a redstone block onto the sticky end of the piston.
    5. Place a normal command block in a place such that when the piston pushes the redstone block one space, it will then be touching the command block. The command inside this block will fire only once until the redstone block is pulled away and pushed back again. Inside this command block I put "say Hello." See the image below if you are confused.

    Testfor solution

    Answer 3

    Here's how I'll do that :

    1. Create a pulsor, like with two hopper connected
    2. Get the redstone signal to a command block with the command inside (2 = 2 blocks wide from the command block) :

      /testfor @p[r=2]

    3. Put a comparator as output of the command block going on a second command block with the /tellraw command with @p arg

    This will output the message only once when the player is detected. He has to leave the command block area to reset it.

    PS : You can type /gamerule commandBlockOutput false once to disable logging from command blocks

    Answer 4

    I have made a system in a previous world from 1.10 that had exactly this system applied to a villager.

    If you are planning it for 1 player, use a |repeat|unconditional|always active| command block to execute this command:

    testfor @a[r=2]
    

    Hook that up to a comparator that is activating another command block

    /execute @e[type=Villager,name="Fungus"] ~ ~ ~ tellraw @a[r=3] {"text":"[Fungus the Villager] Hello! I'm a villager! I'm pleased to meet you!","color":"yellow"}
    

    The delay applied by the comparator is slow enough to stop the spam. If it isn't slow enough for some reason (e.g. older versions) place a repeater in front of the comparator.

    If you want a dismissal message for when the player walks away, attach the output to a redstone torch, which activates another command block with:

    /execute @e[type=Villager,name=Fungus] ~ ~ ~ tellraw @a[r=5] {"text":"Goodbye! I hope to see you again! :D","color":"yellow"}
    

    If you are expecting multiple players to be near the villager at once, use a /scoreboard command to set nearby players to a team for villager messages and set players just outside of the radius to not in that team.

    Good luck!

    P.S. Apologies for a lack of screenshots; the world was deleted some time ago

    Answer 5

    You can do

    /execute @e[r=10] ~ ~ ~ /tellraw @p ["",{"text":"Hello","color":"gray"}]                                                                                                
    

    And that works the color part is just the text color

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: mentatdgt, Ketut Subiyanto, Ivan Samkov, Tatiana Syrikova