How can I create a command that gives me an effect every time I take damage?

I want to make a command that makes it so that every time I take damage, I get regeneration 3 until I come back to full health. I have zero knowledge of commands and coding so I'd appreciate some help.

1

2 Answers

First off, regeneration is an effect which allows the player to gain health rapidly overtime with the regen speed depending on the level of its amplifier, so the effect won't just disappear after you reach full health. Can you be more specific about what you want to achieve?

But I' ll assume that you want to give players regen 3 for 2 seconds after they are hit. put the following in a repeating command block (a purple one)

execute as @a[nbt={HurtTime:10s}] run effect give @s minecraft:regeneration 2 2 false

Notice that if you put in 2 for the amplifier parameter, you get level 3 regeneration.

I don't know if there is anything to do what you want. There may be, but I don't know. However, there are multiple ways to achieve a similar effect.

If you are trying to make yourself invincible, you can give yourself the effect Resistance V. This makes you immune to all damage except starvation, void damage, and the /kill command. Use the following command:

/effect @s resistance time_in_seconds 5

(Replace time_in_seconds with the number of seconds you want to be invincible.)


If you just want to heal with regen 3 whenever you get damaged, use the following command. Regeneration doesn't do anything if you aren't damaged, so you can achieve what you are asking with a repeating command block. Put this command in a repeating command block (purple), set the command block setting "Needs Redstone" to false, and set the Conditional value to unconditional.

/effect username regeneration time_in_seconds 3

(Substitute username with your username and time_in_seconds with the time you wish to have regeneration. Of course, the time in seconds doesn't matter because you will get the effect every tenth of a second.

2

You Might Also Like