Page 1 of 1

Allowing to change maximum health/breath for players

PostPosted: Mon Oct 13, 2014 10:26
by Wuzzy
Hi!
This is a suggestion regarding the health and breath of players.

This is the main suggestion:
1. Allow to modify the maximum health of players (must be a positive number)
2. Allow to modify the maximum breath (bubbles) of players (must be a positive number)

This suggestion requires to modify the HUD, like this:

3. Modify the interface to handle large numbers:
If a player’s max health is greater than 10 hearts, display the health like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
<hearts>/<max. hearts> ♥


For example, for a health of 15 out of 30 hearts, show “15/30 ” instead of “♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥”. For 10.5 hearts, show “10.5/30 ”.
The heart symbol serves like a unit symbol here, as in “5 m”, “17 kg”, etc.

Do the same analog to bubbles.

4. If a player’s max health equals or is lower than 10 hearts, show the health in the traditional way.

If you’re sophisticated:
5. Use a new texture, “heart_background.png” used in the traditional display to show “empty hearts”. So for showing 2/10 hearts, display “♥♥♡♡♡♡♡♡♡♡” instead of “♥♥”. For 2/5 hearts, display “♥♥♡♡♡”. The texture is optional and no image should be drawn if it is not present.

Re: Allowing to change maximum health/breath for players

PostPosted: Sat Jan 09, 2016 20:40
by Neuromancer
Drat, I need this for my crystal hearts mod.
https://forum.minetest.net/viewtopic.php?f=9&t=13865

Re: Allowing to change maximum health/breath for players

PostPosted: Sat Jan 09, 2016 21:11
by Don
@Wuzzy - I like the idea. It would be nice to be able to change health/air as needed by mods.

@Neuromancer - I saw your crystal hearts mod. It is an awesome idea. Hope this gets added so you can complete the mod.

Re: Allowing to change maximum health/breath for players

PostPosted: Sat Jan 09, 2016 21:50
by Neuromancer
Thanks much. I think it might make sense for them to add player:set_max_hp. There already is player:get_hp and player:set_hp

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jan 12, 2016 16:03
by Minetestforfun
Totally agree with Wuzzy, we need a way to be able to change the maximum health and bubble of players ! :)

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jan 12, 2016 16:24
by KCoombes
+1

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jan 12, 2016 18:15
by cd2
Wuzzy : Very cool idea!

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jan 12, 2016 18:37
by kaadmy
+1

Re: Allowing to change maximum health/breath for players

PostPosted: Sat Jan 16, 2016 23:05
by Nathan.S
This would be an excellent addition.

Re: Allowing to change maximum health/breath for players

PostPosted: Mon Jan 18, 2016 15:24
by yyt16384
Currently you can hack with register_on_player_hpchange, but this is really something that should be in the engine.

Re: Allowing to change maximum health/breath for players

PostPosted: Tue May 17, 2016 21:44
by wilkgr76
Yep, 100% needed.

+1

Re: Allowing to change maximum health/breath for players

PostPosted: Wed May 18, 2016 11:52
by azekill_DIABLO
+1

Re: Allowing to change maximum health/breath for players

PostPosted: Wed May 18, 2016 13:34
by burli
signed

please add this in the next release

Re: Allowing to change maximum health/breath for players

PostPosted: Wed May 18, 2016 17:51
by ErrorNull
this would be awesome for a future release. for now I've created a mod that bypasses the engines hp and breath and uses my own hp and breath objects (thus can dictate any maximum) and displays them using the [hudbars] mod. but it's very hacky.

Re: Allowing to change maximum health/breath for players

PostPosted: Sun Jun 19, 2016 00:35
by davidthecreator
Allways wanted to max hp up to 100 (then i would make mobs that deal 1dmg do 5dmg and wearing cheap armor wouldnt help to completely evade damage from that mob... realy wish this gets added...

Re: Allowing to change maximum health/breath for players

PostPosted: Sun Jun 19, 2016 01:20
by KCoombes
ErrorNull wrote:this would be awesome for a future release. for now I've created a mod that bypasses the engines hp and breath and uses my own hp and breath objects (thus can dictate any maximum) and displays them using the [hudbars] mod. but it's very hacky.


I'd love to see your mod

Re: Allowing to change maximum health/breath for players

PostPosted: Sun Jun 19, 2016 15:58
by ErrorNull
I'm sure many have done similar, but here's my code snippet that does the main bypass of health limitation. Essentially my mod uses its own object to track the player's "true" health (thus can set any maximum) and reports that to the HUD and is also saved to file when player leaves the game. The mod check's the engine's HP value at each globalstep to see if it has gone down - due to falling damage, hunger or breath depletion, mob attacks, etc. If engine's HP has gone down, calculate the difference and deduct it from player's true health. Then reset engine's HP back to 20 while player's health object in my mod maintains the current/correct value.

Drawback: All health restoring items must call a function in my mod to increase the player's "real" health value and not the engine's HP value... since the engine's value will always be at 20.

When mod's health value reaches zero then the function rpg.showKnockedout(player) performs 'knocked out' sequence. This is because to the minetest engine, HP is still 20 and player is still alive.. but in-game, player is to be immobilized and on the ground. While knocked out, player can consume health restoring potions or players can cooperate to give health items to the downed player, who then can get up and move again.

But here's the twist... while player is in the knocked out state, the engine's HP mechanism operates normally and any damage the player receives deducts from the engine's HP value.. from 20 to zero... by which time the player TRULY DIES! And must respawn.

If player is knocked out, without any healing items, and no players to give help, and no mobs or dangers to kill off the player... then the player can give up and type /DIE command and player will die... in other words, engine's HP value set to zero.

*** If anyone has any suggestions on how to improve, please let me know as I welcome any critisizm and I'm still new at all this mintest modding and lua scripting! Thanks! *** I have also used the same principle to hack around the breath limitation. It's all so messy... but hopefully the devs can allow us to edit the engine's HP and Breath values soon.. then I can throw away all this code! LOL.

The code below runs inside globalstep function. Also...
- rpg.HEALTH_HARD_CODED_MAX = 20 // engine's limitation
- rpg[pname].health = player's 'real' health, reports to HUD
- rpg[pname].player_status = 1 when player 'alive'. When zero, entire code below is skipped at each globalstep

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- check if Health values have changed since last globalstep
local hpLoss = rpg.HEALTH_HARD_CODED_MAX - player:get_hp()

-- player knocked out
if hpLoss >= rpg[pname].health then
   rpg[pname].health = 0
   rpg[pname].player_status = 0
   if rpg[pname].breath <= 0 then
      player:set_hp(0)
   end
   -- display onscreen hud stating knocked out
   rpg.showKnockedout(player)
   
-- health lost, but still 'alive'
elseif hpLoss > 0 then
   rpg[pname].health = rpg[pname].health - hpLoss
   player:set_hp(20)
   minetest.sound_play("damage", { to_player = pname,   gain = 2.0, })
end


function rpg.showKnockedout(player)
   local pname = player:get_player_name()
   
   -- drop player to the ground
   player:set_eye_offset({x=0, y=-13, z=0}, {x=0, y=0, z=0})
   default.player_attached[pname] = true
   default.player_set_animation(player, "lay", 0)
   
   -- play drop sound and save player position
   minetest.sound_play("knockedout", { to_player = pname,   gain = 2.0, })
   --rpg[pname].spawn_position = player:getpos()
   
   -- show 'knocked out' overlay on-screen
   rpg[pname]["hud_id_knockedout_effect"] = player:hud_add({
      hud_elem_type = "image",
      scale = { x = -100, y = -100 },
      position = { x = 0.5, y = 0.5 },
      text = "hud_knockedout.png",
      alignment = { x=0, y=0 },
      direction = 0             
   })
   rpg[pname]["hud_id_knockedout_text"] = player:hud_add({
      hud_elem_type = "text",
      position = {x=0.5,y=0.5},
      text = "** KNOCKED OUT **",
      number = 0xFFFFFF,
      alignment = {x=0,y=0},
      offset = {x=0, y=-15}
   })


end

Re: Allowing to change maximum health/breath for players

PostPosted: Mon Jun 20, 2016 15:58
by yyt16384
ErrorNull wrote:The code below runs inside globalstep function. Also...
- rpg.HEALTH_HARD_CODED_MAX = 20 // engine's limitation
- rpg[pname].health = player's 'real' health, reports to HUD
- rpg[pname].player_status = 1 when player 'alive'. When zero, entire code below is skipped at each globalstep

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- check if Health values have changed since last globalstep
local hpLoss = rpg.HEALTH_HARD_CODED_MAX - player:get_hp()

-- player knocked out
if hpLoss >= rpg[pname].health then
   rpg[pname].health = 0
   rpg[pname].player_status = 0
   if rpg[pname].breath <= 0 then
      player:set_hp(0)
   end
   -- display onscreen hud stating knocked out
   rpg.showKnockedout(player)
   
-- health lost, but still 'alive'
elseif hpLoss > 0 then
   rpg[pname].health = rpg[pname].health - hpLoss
   player:set_hp(20)
   minetest.sound_play("damage", { to_player = pname,   gain = 2.0, })
end


function rpg.showKnockedout(player)
   local pname = player:get_player_name()
   
   -- drop player to the ground
   player:set_eye_offset({x=0, y=-13, z=0}, {x=0, y=0, z=0})
   default.player_attached[pname] = true
   default.player_set_animation(player, "lay", 0)
   
   -- play drop sound and save player position
   minetest.sound_play("knockedout", { to_player = pname,   gain = 2.0, })
   --rpg[pname].spawn_position = player:getpos()
   
   -- show 'knocked out' overlay on-screen
   rpg[pname]["hud_id_knockedout_effect"] = player:hud_add({
      hud_elem_type = "image",
      scale = { x = -100, y = -100 },
      position = { x = 0.5, y = 0.5 },
      text = "hud_knockedout.png",
      alignment = { x=0, y=0 },
      direction = 0             
   })
   rpg[pname]["hud_id_knockedout_text"] = player:hud_add({
      hud_elem_type = "text",
      position = {x=0.5,y=0.5},
      text = "** KNOCKED OUT **",
      number = 0xFFFFFF,
      alignment = {x=0,y=0},
      offset = {x=0, y=-15}
   })


end


minetest.register_on_player_hpchange may be useful here...

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jun 21, 2016 11:28
by burli
yyt16384 wrote:minetest.register_on_player_hpchange may be useful here...

You mean something like this?

http://dev.minetest.net/minetest.register_on_hpchange

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jun 21, 2016 14:20
by ErrorNull
ah yes i forgot about this new register function. i will incorporate that asap. thanks for pointing that out!

Re: Allowing to change maximum health/breath for players

PostPosted: Tue Jun 21, 2016 14:45
by orwell
Wuzzy wrote:This suggestion requires to modify the HUD, like this:

3. Modify the interface to handle large numbers:
If a player’s max health is greater than 10 hearts, display the health like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
<hearts>/<max. hearts> ♥


For example, for a health of 15 out of 30 hearts, show “15/30 ” instead of “♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥”. For 10.5 hearts, show “10.5/30 ”.
The heart symbol serves like a unit symbol here, as in “5 m”, “17 kg”, etc.

I think the mod that modifies the HP maximum should be responsible to handle this itself, either the way you suggested or using multiple lines, or just scaling the HP value down on 10 hearts. This is no problem since all HUD elements (even the one for HP) are managed by the server.
The problem of monsters (or other things) doing no damage at all can easily be cast away by just multiplying all damage and HP values by, let's say 10. So if a player has 200HP, the hand can do 5 damage and 2 hand-hits equal 1 HP in regular 20HP setup, which is not possible yet. Still, when updating the HUD, the HP value is divided by 10, so that 200HP are shown as the regular 10 hearts in the HUD.

Re: Allowing to change maximum health/breath for players

PostPosted: Thu Jun 23, 2016 03:01
by Wuzzy
orwell: No. Minetest should at least have a sane default way to display health which just works out of the box. This includes modified max. health. I would hate to be required to add pointless boilerplate code only to change the max. health. Changing the max. health should really just involve a single function call and you're done.

But there is already the option to disable the default health display so you can add your own HUD elements to replace it.

The problem of monsters (or other things) doing no damage at all can easily be cast away by just multiplying all damage and HP values by, let's say 10. So if a player has 200HP, the hand can do 5 damage and 2 hand-hits equal 1 HP in regular 20HP setup, which is not possible yet. Still, when updating the HUD, the HP value is divided by 10, so that 200HP are shown as the regular 10 hearts in the HUD.

This is completely out of scope of this suggestion. It should be entirely up to the subgame to balance the damage values. It could be done in a way like you suggested, or differently.