nodecore-cd2025/mods/nc_api/util_phealth.lua
Aaron Suen 726f385e52 Add player natural healing.
- Players heal over time at variable speed, depending on subtle
  environmental factors.
- This frees us up to work on the death mechanic, since it's no
  longer the only way to restore health and prevent an untimely
  death.
2019-02-23 13:14:09 -05:00

18 lines
590 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, nodecore, tonumber, tostring
= math, nodecore, tonumber, tostring
local math_ceil
= math.ceil
-- LUALOCALS > ---------------------------------------------------------
function nodecore.addphealth(player, hp)
local total = player:get_hp() + hp
+ tonumber(player:get_attribute("dhp") or "0")
if total > 20 then total = 20 end
if total < 0 then total = 0 end
local whole = math_ceil(total)
local dhp = total - whole
player:set_attribute("dhp", tostring(dhp))
return player:set_hp(whole)
end