0

I'm trying to run commands on the condition that the executing player is at full health. The problem is, in this datapack, a considerable amount of players will not have the default Max Health attribute of 20. It can range anywhere from 6 to 40, for example.

I've tried to run a function referencing the player's Attributes data, but the issue is that the player's total value of any given attribute, including the base value and any modifiers, isn't stored anywhere, so I can't figure out how to reference just the total value.

In summary, I need a way to find out if a player's current health is equal to their maximum possible health, including all attribute modifiers. Is there a way that I can do this?

3
  • I am a bit out of touch with commands, but how are you trying to get the player's attribute? I mean the attribute command. Especifically the "base get" version
    – BunnyMerz
    Commented Aug 7 at 17:56
  • @BunnyMerz I use the command execute store result score @s max_health run attribute @s generic.max_health base get to retrieve the attribute, and the write it to the max_health score. I just can't seem to figure out how to total all the modifiers as well, since it seems like I'd need to run that command with every individual modifier ID to get the total. (Edit: I've seen your other response, and that fixes all the issues I was worried about. Thanks!)
    – Harth
    Commented Aug 9 at 20:22
  • I actually went through the same problem when figuring out an answer haha. Always include those kinds of information in your answers, helps to build better answers and directed towards your question in specific! Glad it helped either way
    – BunnyMerz
    Commented Aug 10 at 0:43

1 Answer 1

1

Caveat: There are different things that can affect your health and max health. For health, I am not considering the absorption effect (gold hearts) into this answer. And for max health, I am considering both the player's attribute and the health boost effect (marked as an "attribute modifier")

You will need two scoreboards, one for your health and another for your max health. Then, you can test if both have the same value. Note here that I am not using the default health criteria, since that one counts golden hearts towards the value. I will be using the dummy criteria and manually getting the player's health through the data command.

Setting the scoreboards:

/scoreboard objectives add health dummy
/scoreboard objectives add maxHealth dummy

Here are the chain of commands. First, we get the player's health and max health, then we test if both values are equal. In case they are, run whatever command you wish afterwards:

execute as @a store result score @s health run data get entity @s Health
execute as @a store result score @s maxHealth run attribute @s minecraft:generic.max_health get 1 run <your command for full health players>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.