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