For my server, I create a scoreboard health value so I can do what I want when it goes to 0, and have 250 health point if I want !
This is not a thing that I use to fight mobs, I think we can do something to get only this scoreboard health down when a mob hit us, but this is not the discuss today. Here we only set Health with commands !
To start, we have to make 3 new scoreboard objectives : 1 for the health_max, 1 for the Health we have, and 1 for a buffer for later. Here the 3 commands to do it :
With that, we have an ghost entity called #TIMER with an objectives timer set to 0 !
And now, we gonna increase it every tick ! So two choice here, if you work with command block or if you work with functions !
I just gonna show how to do it with function, it's more simple !
If you work with function, you surely already have a function that run all tick, if not, go search how to do it, you'll find easily ! So, in this function, we gonna write this :
scoreboard players add #TIMER timer 1
execute if score #TIMER timer matches 20.. run function datapack:timer
Now, every tick our ghost entity will see his objectives timer increase by 1 !
And when it reach 20 (you can change this value for slower or faster regeneration) it will run the function timer.mcfunction, where you have :
scoreboard players set #TIMER timer 0
execute as @e if score @s health < @s max_health run scoreboard players add @s health 1
We set the timer to 0 and we give 1 health point to all players only if they havn't a health equal or superior to their max_health !
Good job ! Now, you have a health objective that regenerate to the max_health and stop regenerating.
But... Arf, something's missing... Oh, I know ! Why my heart GUI won't goes down when my health objectives decrease ? That's stupid...
Héhé, do you think I'm not prepared for this ?!?
Hell Yeah ! Why do you think our objectives health_buffer has been created to?
So, in our every tick function, we add this line :
execute as @a unless score @s health_buffer = @s health run function datapack:check_health
So if your buffer doesn't correspond to you health, it gonna run the function check_health.
And it's in this function that the magic works !
Let's check it !
scoreboard players set #100 health_buffer 100
scoreboard players operation @s health_buffer = @s health
scoreboard players operation @s health_buffer *= #100 health_buffer
scoreboard players operation @s health_buffer /= @s max_health
execute if score @s health_buffer matches 91..100 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:0,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 81..90 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-2,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 71..80 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-4,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 61..70 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-6,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 51..60 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-8,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 41..50 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-10,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 31..40 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-12,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 21..30 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-14,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 11..20 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-16,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches 1..10 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-18,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
execute if score @s health_buffer matches ..0 run replaceitem entity @s armor.feet minecraft:diamond_boots{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:-20,Operation:0,UUIDLeast:894654,UUIDMost:2872,Slot:"feet"}],Enchantments:[{id:"minecraft:binding_curse",lvl:1}]}
scoreboard players operation @s health_buffer = @s health
"Uuuum... ok, but what is th-..."
SOOOOO, the first part of the command will set the health_buffer objectives. It will give us a percentage of our health. Then all the commands except the last one will set the boots of the player to be a diamond boots with a special thing... Every time our buffer reach a new dozen, the attribute generic.maxHealth of boots will up, and give us more heart ! If you have 21 to 30 percents of your max_health, you will have 3 hearts, 51 to 60 percents for 6 hearts, etc.
And the final commands set the buffer to the health you have, so the command in your every tick function will only run when you health will change.
What is good with that is you can have as much as health as you want, and when the boots let you to 0 hearts, it's only graphic so you don't have the death screen.
I hope what I said here make senses, and maybe will help someone, that's a very simple command system, but it work well. Isn't that what we all wanted ? :'o
I remember that if you set player health to zero, it will die as soon as it health value updates by any way
Pretty funny, as I released a datapack some time ago which uses scoreboard health as well to test a bit how far it could go, if anyone wants to search deeper :
I highly suggest checking that out if you are interested. Its name made it rather not popular, though I still consider it as pretty amazing.
Basically, this pack sets a 9-lives mechanic, and if player dies, it loses a life instead of truly dying (totem of undying simulation, but without this item).
The trick I use for it : I give resistance 5 (100% dmg reduction) to the player.
If it takes damage, health will not drop though its score "damage resisted" will raise.
Once its damage resisted >0, it substracts its actual health score by the damage resisted, then replace its cat head (which it permanently kept) by one having the matching maxHealth attribute. Its health gets updated using healing effect, then the cat head is replaced again by a non-attribute one, leaving empty hearts.
Cool part with this is that natural regeneration still works, and it's compatible with pretty much all damage sources/reductions. Also, I use a cat head as permanent armor piece, so it justifies why we can not remove it.
I also added a little json-sign thing to display remaining lives on the cat head.
Rollback Post to RevisionRollBack
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Hello everyone !
For my server, I create a scoreboard health value so I can do what I want when it goes to 0, and have 250 health point if I want !
This is not a thing that I use to fight mobs, I think we can do something to get only this scoreboard health down when a mob hit us, but this is not the discuss today. Here we only set Health with commands !
To start, we have to make 3 new scoreboard objectives : 1 for the health_max, 1 for the Health we have, and 1 for a buffer for later. Here the 3 commands to do it :
When we have this 3 objectives set you can set a max_Health for your player, and don't forget to set the health as well :
Ok, now we have a player with health_max and health, but we want it to regenerate if it goes down ! Let's create a new objectives, a timer !
With that, we have an ghost entity called #TIMER with an objectives timer set to 0 !
And now, we gonna increase it every tick ! So two choice here, if you work with command block or if you work with functions !
I just gonna show how to do it with function, it's more simple !
If you work with function, you surely already have a function that run all tick, if not, go search how to do it, you'll find easily ! So, in this function, we gonna write this :
Now, every tick our ghost entity will see his objectives timer increase by 1 !
And when it reach 20 (you can change this value for slower or faster regeneration) it will run the function timer.mcfunction, where you have :
We set the timer to 0 and we give 1 health point to all players only if they havn't a health equal or superior to their max_health !
Good job ! Now, you have a health objective that regenerate to the max_health and stop regenerating.
But... Arf, something's missing... Oh, I know ! Why my heart GUI won't goes down when my health objectives decrease ? That's stupid...
Héhé, do you think I'm not prepared for this ?!?
Hell Yeah ! Why do you think our objectives health_buffer has been created to?
So, in our every tick function, we add this line :
So if your buffer doesn't correspond to you health, it gonna run the function check_health.
And it's in this function that the magic works !
Let's check it !
"Uuuum... ok, but what is th-..."
SOOOOO, the first part of the command will set the health_buffer objectives. It will give us a percentage of our health. Then all the commands except the last one will set the boots of the player to be a diamond boots with a special thing... Every time our buffer reach a new dozen, the attribute generic.maxHealth of boots will up, and give us more heart ! If you have 21 to 30 percents of your max_health, you will have 3 hearts, 51 to 60 percents for 6 hearts, etc.
And the final commands set the buffer to the health you have, so the command in your every tick function will only run when you health will change.
What is good with that is you can have as much as health as you want, and when the boots let you to 0 hearts, it's only graphic so you don't have the death screen.
I hope what I said here make senses, and maybe will help someone, that's a very simple command system, but it work well. Isn't that what we all wanted ? :'o
I like trains... OF CHAIN COMMAND BLOCKS !
Yay! Health controlling mechanic!
I remember that if you set player health to zero, it will die as soon as it health value updates by any way
Pretty funny, as I released a datapack some time ago which uses scoreboard health as well to test a bit how far it could go, if anyone wants to search deeper :
https://www.planetminecraft.com/data-pack/eglaios-s-cats-have-nine-lives/
I highly suggest checking that out if you are interested. Its name made it rather not popular, though I still consider it as pretty amazing.
Basically, this pack sets a 9-lives mechanic, and if player dies, it loses a life instead of truly dying (totem of undying simulation, but without this item).
The trick I use for it : I give resistance 5 (100% dmg reduction) to the player.
If it takes damage, health will not drop though its score "damage resisted" will raise.
Once its damage resisted >0, it substracts its actual health score by the damage resisted, then replace its cat head (which it permanently kept) by one having the matching maxHealth attribute. Its health gets updated using healing effect, then the cat head is replaced again by a non-attribute one, leaving empty hearts.
Cool part with this is that natural regeneration still works, and it's compatible with pretty much all damage sources/reductions. Also, I use a cat head as permanent armor piece, so it justifies why we can not remove it.
I also added a little json-sign thing to display remaining lives on the cat head.
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
I will check that, it sounds interesting
I like trains... OF CHAIN COMMAND BLOCKS !