Remove Hearts

Started by Lc9 on

Topic category: Help with modding (Java Edition)

Last seen on 09:54, 14. Jul 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Remove Hearts

I want to decrease the hearts of the player when he dies im using the (attribute @s minecraft:generic.max_health base set) (max health of entity-10) command but when you die you have 1/2 hearts but brfore i set my health to like 30 hearts 

Last seen on 05:05, 30. Oct 2022
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Please restate what it is…
Fri, 06/10/2022 - 20:28

Please restate what it is exactly you want to do.  When you die, your attributes get reset.

Last seen on 09:54, 14. Jul 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
everytime you die you…
Fri, 06/10/2022 - 20:34

everytime you die you respawn with 1 heart less

 

Last seen on 05:05, 30. Oct 2022
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Set up a global number…
Fri, 06/10/2022 - 23:38

Set up a global number variable of PLAYER_PERSISTENT type. 

Increment this variable each time the player dies.

On player spawn, reduce the player's HP attribute by the stored value.

Last seen on 09:54, 14. Jul 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tryed that but the Hearts…
Sat, 06/11/2022 - 09:43

I tryed that but the Hearts geht reseted wegen you die so everytime your Hearts are in 5

Last seen on 09:54, 14. Jul 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried that but it doesn't…
Sat, 06/11/2022 - 09:47

I tried that but it doesn't work when you die the value gets set to 10 everytime when I set my heart's to 30 it's the same

Last seen on 05:05, 30. Oct 2022
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes, as I stated, attributes…
Sat, 06/11/2022 - 14:04

Yes, as I stated, attributes get reset after a player dies.  This is why I said to make a Global Variable (not Local) to store the number of times the player has died.  This number won't get reset and you can use it to adjust your attributes when the player respawns.

For example, lets make the global variable "vDeathCount" to track player deaths. 

On player death, set vDeathCount = vDeathCount + 1

On player spawn, set Max health = 20 - (vDeathCount * 2)

 

At game start vDeathCount = 0, player hearts = 10

After 1 death, vDeathCount = 1, player hearts = 9

After 5 deaths, vDeathCount = 5, player hearts = 5

Last seen on 09:54, 14. Jul 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
but dosent the variable…
Sat, 06/11/2022 - 15:29

but dosent the variable effect evry player then?

Last seen on 05:05, 30. Oct 2022
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No, each player has their…
Sat, 06/11/2022 - 16:47

No, each player has their own.

Last seen on 12:31, 22. Jan 2024
Joined Jul 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
there are various types of…
Sat, 06/11/2022 - 18:31

there are various types of global variables

local refers to stored within the procedure and global is within the world

in this case you want to use "PLAYER_PERSISTENT", which will not be reset after you die

try valirane's solution, and see if it works