2019-02-23 13:14:09 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-04-06 20:46:13 -04:00
|
|
|
local math, minetest, nodecore
|
|
|
|
= math, minetest, nodecore
|
2019-02-23 13:14:09 -05:00
|
|
|
local math_ceil
|
|
|
|
= math.ceil
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2019-02-24 13:54:58 -05:00
|
|
|
local function getphealth(player)
|
2019-04-06 20:46:13 -04:00
|
|
|
return player:get_hp() + player:get_meta():get_float("dhp")
|
2019-02-24 13:54:58 -05:00
|
|
|
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)
|
2019-03-10 15:47:22 -04:00
|
|
|
if whole == 0 then whole = 1 end
|
2019-02-24 13:54:58 -05:00
|
|
|
local dhp = hp - whole
|
2019-04-06 20:46:13 -04:00
|
|
|
player:get_meta():set_float("dhp", dhp)
|
2019-02-23 13:14:09 -05:00
|
|
|
return player:set_hp(whole)
|
|
|
|
end
|
2019-02-24 13:54:58 -05:00
|
|
|
nodecore.setphealth = setphealth
|
|
|
|
|
2019-03-07 22:21:04 -05:00
|
|
|
local function addphealth(player, hp)
|
2019-02-24 13:54:58 -05:00
|
|
|
return setphealth(player, getphealth(player) + hp)
|
|
|
|
end
|
2019-03-07 22:21:04 -05:00
|
|
|
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
|