capturetheflag/mods/pvp/hpregen/init.lua

36 lines
783 B
Lua
Raw Normal View History

local regen_interval = tonumber(minetest.settings:get("regen_interval"))
2016-01-02 14:08:40 +00:00
if regen_interval <= 0 then
2017-11-09 21:44:50 +00:00
regen_interval = 6
2016-01-02 14:08:40 +00:00
end
local regen_amount = tonumber(minetest.settings:get("regen_amount"))
2016-01-02 14:08:40 +00:00
if regen_amount <= 0 then
regen_amount = 1
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 + regen_amount
2019-03-21 01:36:59 +00:00
if newhp > player:get_properties().hp_max then
newhp = player:get_properties().hp_max
2016-01-05 02:57:10 +00:00
end
2019-03-22 03:18:45 +00:00
if oldhp ~= newhp then
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 < regen_interval then
return
end
update = update - regen_interval
regen_all()
end)