-1

I am creating a public Minecraft server with different game modes like Lifesteal and Survival. I am facing an issue. I have created multiple worlds for each of these game modes using Multiverse Core. The problem is that when I die in the Lifesteal world, I lose one heart, so I have 9 hearts remaining. However, if I switch to the Survival world to play, I still have 9 hearts, and the same applies to all the other worlds.

Does anyone know how I can set different health values for each world? I thought about adding a command block and a pressure plate that triggers a command to set players' health to 10 hearts whenever they step on it. However, this would also reset their health in the Lifesteal SMP, which is something I don't want.

1
  • 1
    Welcome to Arqade! Please, refrain from random tagging your question, tags are meant to be used for a reason.
    – pinckerman
    Commented Nov 18, 2023 at 14:49

1 Answer 1

1

I was able to make this work, but it will require the use of multiple command blocks.

By storing the player's current health in a scoreboard, you can reset their health when they go to survival, then set their health to the same as the score.

First make the scoreboard:

/scoreboard objectives add LifestealHealth dummy

Then I assume you got your health reduction system set up properly, you can add the next commands when the player goes to the survival area.

The first command will fetch the value of the player's health:

execute as @a store result score @s LifestealHealth run attribute @s minecraft:generic.max_health get

This command stores all player's current health values on the scoreboard, but you can change the selector to whatever would work best for you.

The next command changes the closest player's Health to 10 hearts, value 20.0:

attribute @p minecraft:generic.max_health base set 20

This will not heal the player only change the max health.


Then when the player joins the Lifesteal area you can set their health according to the scoreboard:

execute as @p if score @s LifestealHealth matches 18..18 run attribute @s minecraft:generic.max_health base set 18

Here I execute only as the closest player and then run the command only if the player has a Lifesteal score of 18, i.e. 9 hearts.

This would need to be repeated for all different values the player can have. If you only reduce by 1 heart increment, then you should test for all even values up to 20.

20 or 10 hearts isn't necessary to test for because it won't change anything.

Depending on how you make the player activate these commands you can do it in many different ways, the way I did it in testing was to place the command when the player goes to the survival area, with the first command in an impulse block and the second following in a chain block: First command block chain

The bottom command stores the player's health value, and the top sets the player's health to 20.

You need to make sure the player can only activate this once, if they press it again the health value stored will be 20. So you could add a tp command at the end to teleport them away or whatever you can come up with.

The next commands will be when the player enters the Lifesteal area. The commands I used to test the closest player. This will be a lot of command blocks as we need to test for every possible value, except for 20. As it looks like you only set the health to whole hearts then we should test for all even values from 2 to 18, this will be a total of 9 blocks:

Seocund command block chain

To change the command you have to change the score-matching range and the attribute command value:

execute as @a if score @s LifestealHealth matches 2..2 run attribute @s minecraft:generic.max_health base set 2

This command changes the player's health to 1 heart if the score is 2. The changes in the range: matches 2..2 run, and the attribute value: base set 2.

You must log in to answer this question.

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