2019-02-23 13:14:09 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-03-07 22:21:04 -05:00
|
|
|
local math, minetest, nodecore, tonumber, tostring
|
|
|
|
= math, minetest, nodecore, tonumber, tostring
|
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)
|
|
|
|
return player:get_hp()
|
2019-02-23 13:14:09 -05:00
|
|
|
+ tonumber(player:get_attribute("dhp") or "0")
|
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-02-23 13:14:09 -05:00
|
|
|
player:set_attribute("dhp", tostring(dhp))
|
|
|
|
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
|