2019-03-22 04:31:57 +00:00
|
|
|
hpregen = {}
|
|
|
|
|
|
|
|
hpregen.interval = tonumber(minetest.settings:get("hpregen.interval"))
|
|
|
|
if hpregen.interval <= 0 then
|
|
|
|
hpregen.interval = 6
|
2016-01-02 14:08:40 +00:00
|
|
|
end
|
2019-03-22 04:31:57 +00:00
|
|
|
hpregen.amount = tonumber(minetest.settings:get("hpregen.amount"))
|
|
|
|
if hpregen.amount <= 0 then
|
|
|
|
hpregen.amount = 1
|
2016-01-02 14:08:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function regen_all()
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2016-01-05 02:57:10 +00:00
|
|
|
local oldhp = player:get_hp()
|
|
|
|
if oldhp > 0 then
|
2019-03-22 04:31:57 +00:00
|
|
|
local newhp = oldhp + hpregen.amount
|
2019-03-21 01:36:59 +00:00
|
|
|
if newhp > player:get_properties().hp_max then
|
|
|
|
newhp = player:get_properties().hp_max
|
2021-02-09 00:03:03 +00:00
|
|
|
kill_assist.clear_assists(player:get_player_name())
|
2016-01-05 02:57:10 +00:00
|
|
|
end
|
2019-03-22 03:18:45 +00:00
|
|
|
if oldhp ~= newhp then
|
2021-02-09 00:03:03 +00:00
|
|
|
kill_assist.add_heal_assist(player:get_player_name(), hpregen.amount)
|
2019-03-22 03:18:45 +00:00
|
|
|
player:set_hp(newhp)
|
|
|
|
end
|
2016-01-02 14:08:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-22 03:18:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
local update = 0
|
|
|
|
minetest.register_globalstep(function(delta)
|
|
|
|
update = update + delta
|
2019-03-22 04:31:57 +00:00
|
|
|
if update < hpregen.interval then
|
2019-03-22 03:18:45 +00:00
|
|
|
return
|
|
|
|
end
|
2019-03-22 04:31:57 +00:00
|
|
|
update = update - hpregen.interval
|
2019-03-22 03:18:45 +00:00
|
|
|
|
|
|
|
regen_all()
|
|
|
|
end)
|