1

I want to be able to give an entity damage for a command I’m making, but instant damage effect is way too much, how do I apply other amounts of damage with command blocks?

1
  • I am working on something that should be done either today or tomorrow. It requires a data pack for ease of use and for multiplayer friendliness although is not required. Would a data pack work? Dec 8, 2020 at 20:49

1 Answer 1

2

1.16+

Note: This data pack is in beta, and is in the works. If you have any bugs please let me know, and I'll add it to the known bugs list. Also, this is not tested in any version other then 1.16.4

I created a data pack that allows you to set health and deal damage to a player(for mobs use data modify instead). First off, you can get the data pack here. After installing it, make sure it says in chat that it was installed.

How To Use

Dealing Damage

To damage a player, set that player's damage scoreboard to how much damage you want to apply(negatives heal players), then run the function editor:deal_damage as the player you want to damage and you are done.

Setting Health

To set the health of a player, set that player's sethealth scoreboard to what health you want that player to have, then run the function editor:set_health as the player you want to edit health and you are done.

Remember: 1 heart is 2 HP, and a half a heart is 1 HP, default max health is 20 HP(10 hearts)

The Commands

To damage players:

scoreboard players set <selector> damage <value>
execute as <selector> run function editor:deal_damage

To set player health:

scoreboard players set <selector> sethealth <value>
execute as <selector> run function editor:set_health

How It Works

What the data pack does is set the max health of the player to what health you want to set, and gives the player the instant health effect so it will update the player health, setting the player's health to max, then it sets the max health to be what it originally was.

Known Bugs

  • A bug that shows the player as dead, even though they are not. (Its a Minecraft bug)

Incompatibilities

All Incompatibilities are being worked on to be compatible

  • An existing helmet/item in the helmet slot with the max health attribute

Finding Bugs/Issues

Bugs

If you find any bugs, please report it. Also add how you found the bug, so I can recreate it, and fix it, videos/screenshots of bugs are preferred.

Issues

If you have any performance issues while running the data pack, please report it. Also add what performance issues you are getting, low tps, low fps, etc. Videos/screenshots and computer specs do help!

Where to report

To report bugs/issues, use either comments on this answer, or the issues page on the GitHub download link.

Terms of Use

If you use this in a data pack to publish, I would like for you to put the GitHub link to the data pack somewhere for others who may want it, Thanks. You are welcome to edit the data pack to whatever you want, just don't break it! :)

3
  • Is your solution complex enough to warrant a data pack? Why can't you just run the /attribute and /effect commands on your own? Apr 1, 2021 at 3:00
  • @ExpertCoder14 the datapack is supposed to be for simplicity and for wide use. If you did it with /attribute and /effect, you would have to know what to set the max health attribute back to, which in some circumstances, is not easy. If you really wanted to, you could recreate this with command blocks instead, but it would take a while, and would need some workarounds. Apr 3, 2021 at 2:37
  • Ah, great explanation that fills in the missing part. Yes, setting the maxHealth attribute back to the correct value definitely requires some more trickery. I'm worried that you might have reinvented the wheel though, did you check for a "standard" or more widely used data pack out there before going off to make your own? I had to learn that the hard way with the previous answer when we were talking about player inventory modification, turns out there was an "industry standard" data pack out there that I changed the link in your answer to reference, rather than our own. Apr 3, 2021 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .