How to effect players that triggered a command in Minecraft?

I want to do a /testfor
command for burning players, and then instantly heal them, what is the command for that?
Best Answer
First, add an objective to track if a player is burning:
/scoreboard objectives add isBurning dummy
On a clock, run the following commands in this order:
/scoreboard players set @a isBurning 1
/scoreboard players set @a isBurning 0 {Fire:-20s}
/effect @a[score_isBurning_min=1] instant_health 20 20
The way this works is that, first, everybody's isBurning
score is set to 1. When not burning, a player's Fire
tag is at -20s
, so the isBurning
score for those with a Fire
tag at -20s
is then set to 0, leaving only those who are burning still with an isBurning
score of 1. The instant_health potion effect can then be applied to the players that are burning.
As a general tip, the /testfor
command is a lot less useful than people seem to think. When using /testfor
, you are essentially just asking "Does this entity exist?" and getting a yes/no answer without being able to do anything with the entity matched your query. If you want to be doing something with the entity (healing, killing, teleporting, etc.), you shouldn't use /testfor
.
Pictures about "How to effect players that triggered a command in Minecraft?"



How do you give people effects in Minecraft with commands?
This /effect command uses an ID value of 8, a duration of 50 seconds, and an amplifier of 1. This will give the player called DigMinecraft the effect of Jump Boost II for 50 seconds. The amplifier is used to increase the level of the effect....Add Effect using Effect ID.Effect IDAmplifierResult83Jump Boost IV3 more rowsMinecraft Trigger Command [1.19] Tutorial
More answers regarding how to effect players that triggered a command in Minecraft?
Answer 2
This can be done in just one command in Minecraft 1.13:
/effect give @a[nbt=!{Fire:-20s}] instant_health 20 20
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Yaroslav Shuraev, David Gan, jonathan emili, Jess Loiterton