How can I add half a heart of health using command blocks?
How would I add half a heart of health to a player when they are in a certain area?
I have got the detection part right I just don't know how to add exactly half a heart. Here is what I have tried so far:
/execute @p ~ ~ ~ detect ~ ~-1 ~ grass 0 effect @p 6
This heals the player too much though.
Solution 1:
You can't add a half hearth via instant health, however you could using regeneration for 3 seconds with level 1.
/effect @p minecraft:regeneration 3 0
This gives the player one half heart. For every 2,5 seconds the player gets half a heart.
Solution 2:
Method A: For all users to use
To heal a player with this method exactly half a heart, set the score "Heal" on the player to 10. (Setting this on a loop will permanently give them regeneration until they disable the loop)
Commands in Chat
/scoreboard objectives add Heal dummy
Inside Command Blocks
(Note: All command blocks must be in line) Repeating Command Block (Always Active, Unconditional)
scoreboard players remove @a[scores={Heal=0..}] Heal 1
Chain Command Blocks (Always Active, Unconditional)
execute as @a[scores={Heal=9}] run effect give @s regeneration 1 2 true
effect clear @a[scores={Heal=0}] regeneration
Recommended Commands In Chat
/gamerule commandBlockOutput false
Method B: For this specific example
To heal a player with this method exactly half a heart, stand on a Grass Block. Note if they stand off the Grass Block before they heal, they stop healing.
Commands in Chat
/scoreboard objectives add Heal dummy
/scoreboard objectives add HealAllow dummy
Inside Command Blocks
(Note: All command blocks must be in line) Repeating Command Block (Always Active, Unconditional)
execute as @a if block ~ ~-1 ~ grass_block run scoreboard players set @s HealAllow 1
Chain Command Blocks (Always Active, Unconditional)
scoreboard players set @a[scores={HealAllow=1}] Heal 10
scoreboard players set @a[scores={HealAllow=1}] HealAllow 2
execute as @a[scores={HealAllow=2}] unless block ~ ~-1 ~ grass_block run scoreboard players set @s Heal 1
execute as @a[scores={HealAllow=2}] unless block ~ ~-1 ~ grass_block run scoreboard players reset @s HealAllow
scoreboard players remove @a[scores={Heal=0..}] Heal 1
execute as @a[scores={Heal=9}] run effect give @s regeneration 1 2 true
effect clear @a[scores={Heal=0}] regeneration
scoreboard players set @a[scores={Heal=0}] HealAllow 1
Recommended Commands In Chat
/gamerule commandBlockOutput false
In Method B, if you wish to make them have to jump off the block to heal again, delete the last chain command block.