Minecraft problem with commands - /testfor health

Minecraft problem with commands - /testfor health - Person in Black Pants and Black Shoes Sitting on Brown Wooden Chair

I have a problem with my redstone/command blocks circuit. My redstone circuit:

redstone circuit

In command block 1, the command in that block is:

/testfor @a [score_health=19,score_health_min=1]

(this sends a redstone signal when their is a player with less than 10 hearts).

In command block 2 the command is:

/replaceitem entity @p slot.armor.head diamond_helmet 1 0

(when activated it places a diamond helmet on your head)
The rest of the commands are for other armor pieces.

When someone has less than 10 hearts, it activates the other commands but gives the nearest player the armor. How do I make it so that the "armor wear" commands only effect the player who has less than 10 hearts?



Best Answer

/replaceitem has a target selector. Just use /replaceitem instead of /testfor.

/replaceitem entity @a[score_health=19,score_health_min=1] slot.armor.head minecraft:diamond_helmet 1 0

Relying on physical redstone logic when dealing with multi-target situations will make it difficult or impossible to support it. For example, you mechanism appears to turn on and stay on as long as a player has that health, which means any future players that meet those requirements will not be affected because the mechanism is locked due to the first detection. Removing physical logic and using /replaceitem on the clock will allow it to support multiplayer.




Pictures about "Minecraft problem with commands - /testfor health"

Minecraft problem with commands - /testfor health - Man in Black Blazer Sitting on Chair
Minecraft problem with commands - /testfor health - Man in Black Sweater Sitting on Brown Wooden Chair
Minecraft problem with commands - /testfor health - 2 Women Sitting on Brown Wooden Chair



Is Testfor command still in Minecraft?

You can test for a certain target in the game using the /testfor command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /testfor command was removed from the Java Edition version of the game.

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.



Minecraft Redstone Tutorial | How to use testfor commands in MCPE!




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

Images: cottonbro, cottonbro, cottonbro, cottonbro