2

Say there is a player called Dave with a Health score of 10 and a MaxHealth score of 20. I need to check if there is any players with a health score lower than MaxHealth and tellraw it. Also is there a way to add values onto Health say 60 or 20 but without it going over MaxHealth? E.G. Health + 60 = MaxHealth (without going over)? Thanks in advance.

1 Answer 1

2

How can I tellraw all players with less than full health:

You can use

/scoreboard players operation <targetName> <targetObjective> <operation> <selector> <objective> 

to modify a players score by the value of another score(even between players).

But unfortunately, I couldn't find an objective criteria for MAX_HEALTH. (might be worth a feature request on bugs.mojang.com)

If there should be one, you would need 3 objectives to do what you want:

/scoreboard objectives add Health health
/scoreboard objectives add MaxHealth maxHealth
/scoreboard objectives add HealthLost dummy

You need a clock to run all of these following commands:

execute @a ~ ~ ~ /scoreboard players operation @p HealthLost = @p MaxHealth
execute @a ~ ~ ~ /scoreboard players operation @p HealthLost -= @p Health

For the tellraw, use the selector tag in the json text:

/tellraw @a {text: "All these players are hurt: ",extra:[{selector:"@a[score_HealthLost_min=1]"}]}

How can I heal players without going over maxHealth:

You can't modify a health scoreboard value. Instead use the

/effect <player> <effect> [seconds] [amplifier] [hideParticles]

command to heal players. The amount of health added is equal to duration * 2 ^ amplifier

See Potion effects (ID 6)

Edit according to comment:

(All objectives = dummy) You can use the operation command again to achieve this: Just add an arbitrary value to your score and then execute this:

/execute @a ~ ~ ~ /scoreboard players operation @p Health < @p MaxHealth

This will limit the "Health" score of every player to his "MaxHealth" score

1
  • 1
    Thanks but I actually didn't want to heal them. It was just need the bit that actually modifies the score. Health score should have a value added on but not going over the score set by MaxHealth. All values are dummy..
    – sebdroid
    Oct 23, 2015 at 10:36

You must log in to answer this question.

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