nodecore-cd2025/mods/nc_api/util_phealth.lua
Aaron Suen fb75424335 Encumbered injured players walk slower.
Encumbrance is calculated from inventory slots filled (ignoring
count within stacks), compared to health; players can freely carry
the same proportion of slots as their health.

Players who are encumbered lose up to 80% of their walking speed
(i.e. for a full hotbar and no health).

This is another disadvantage for being injured, and an incentive
for players to take care of their health.
2019-02-24 13:54:58 -05:00

27 lines
760 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, nodecore, tonumber, tostring
= math, 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)
local dhp = hp - whole
player:set_attribute("dhp", tostring(dhp))
return player:set_hp(whole)
end
nodecore.setphealth = setphealth
function nodecore.addphealth(player, hp)
return setphealth(player, getphealth(player) + hp)
end