capturetheflag/mods/pvp/hpregen/init.lua

40 lines
937 B
Lua
Raw Normal View History

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
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
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
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
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
if update < hpregen.interval then
2019-03-22 03:18:45 +00:00
return
end
update = update - hpregen.interval
2019-03-22 03:18:45 +00:00
regen_all()
end)