nodecore-cd2025/mods/nc_api/util_phealth.lua
Aaron Suen 8add276587 Make falling things bounce off players.
If the falling item/node causes enough damage to
trigger a "hurt" effect, then it loses much of its energy
and bounces upward off the player.

This will also reduce the "scraping" effect when nodes
fall through a player.  Hopefully the damage from
falling things is a little more consistent now.
2019-12-29 12:12:08 -05:00

35 lines
1019 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore
= math, minetest, nodecore
local math_ceil
= math.ceil
-- LUALOCALS > ---------------------------------------------------------
local function getphealth(player)
return player:get_hp() + player:get_meta():get_float("dhp")
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:get_meta():set_float("dhp", dhp)
local old = player:get_hp()
player:set_hp(whole)
return old ~= 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