nodecore-cd2025/mods/nc_api/util_phealth.lua
Aaron Suen 4d0f0734ba Beginning of a bold new health system.
- Eliminate health and breath stat bars.
- Players NO LONGER DIE FROM INJURY.
- Players no longer lose walking speed or mobility.
- Players lose inventory slots in proportion to injury; they're
  stuffed with an "injury" item, and items they displace are
  ejected.  Slots are displaced in random order.
- Healing rate is much faster, so players are usually mildly
  inconvenienced by injury, but can soon enough pick up their
  stuff and leave.
- Health and breath HUDs are gone.  Health is visible based on
  number of lost slots, and breath uses a vignette to narrow
  tunnel vision for O2 loss.

Overall, the old health system has been more of an immersion-
breaking annoyance than anything.  This allows health to get out
of the way of the primary gameplay.

UNFINISHED: Need a replacement for the old "suicide to get unstuck"
mechanic.
2019-03-10 15:47:22 -04:00

34 lines
1.0 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore, tonumber, tostring
= math, minetest, nodecore, tonumber, tostring
local math_ceil
= math.ceil
-- LUALOCALS > ---------------------------------------------------------
local function getphealth(player)
return player:get_hp()
+ tonumber(player:get_attribute("dhp") or "0")
end
nodecore.getphealth = getphealth
local function setphealth(player, hp)
if hp > 20 then hp = 20 end
if hp < 0 then hp = 0 end
local whole = math_ceil(hp)
if whole == 0 then whole = 1 end
local dhp = hp - whole
player:set_attribute("dhp", tostring(dhp))
return player:set_hp(whole)
end
nodecore.setphealth = setphealth
local function addphealth(player, hp)
return setphealth(player, getphealth(player) + hp)
end
nodecore.addphealth = addphealth
function nodecore.node_punch_hurt(pos, node, puncher, ...)
if puncher and puncher:is_player() then addphealth(puncher, -1) end
return minetest.node_punch(pos, node, puncher, ...)
end