2019-02-23 13:14:09 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2020-03-29 07:55:54 -04:00
|
|
|
local math, nodecore, type
|
|
|
|
= math, nodecore, type
|
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
|
|
|
|
|
2020-02-20 07:16:19 -05:00
|
|
|
local function setphealth(player, hp, reason, minwhole)
|
2020-02-19 19:48:51 -05:00
|
|
|
local hpmax = player:get_properties().hp_max
|
|
|
|
if hp > hpmax then hp = hpmax end
|
2019-02-24 13:54:58 -05:00
|
|
|
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
|
2020-02-19 22:32:19 -05:00
|
|
|
if minwhole and whole < minwhole then whole = minwhole 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-12-29 12:12:08 -05:00
|
|
|
local old = player:get_hp()
|
2020-02-20 07:16:19 -05:00
|
|
|
if type(reason) ~= "table" then reason = {nc_type = reason} end
|
|
|
|
reason = reason or {}
|
|
|
|
reason.from = "mod"
|
|
|
|
reason.type = "set_hp"
|
|
|
|
player:set_hp(whole, reason)
|
2019-12-29 12:12:08 -05:00
|
|
|
return old ~= whole
|
2019-02-23 13:14:09 -05:00
|
|
|
end
|
2019-02-24 13:54:58 -05:00
|
|
|
nodecore.setphealth = setphealth
|
|
|
|
|
2020-02-20 07:16:19 -05:00
|
|
|
local function addphealth(player, hp, reason)
|
2020-02-19 22:32:19 -05:00
|
|
|
return setphealth(player,
|
|
|
|
getphealth(player) + hp,
|
2020-02-20 07:16:19 -05:00
|
|
|
reason,
|
2020-02-19 22:32:19 -05:00
|
|
|
hp >= 0 and player:get_hp())
|
2019-02-24 13:54:58 -05:00
|
|
|
end
|
2019-03-07 22:21:04 -05:00
|
|
|
nodecore.addphealth = addphealth
|