Started by
Lc9
on
Topic category: Help with Minecraft modding (Java Edition)
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
Please restate what it is exactly you want to do. When you die, your attributes get reset.
everytime you die you respawn with 1 heart less
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.
I tryed that but the Hearts geht reseted wegen you die so everytime your Hearts are in 5
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
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
but dosent the variable effect evry player then?
No, each player has their own.
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