Prevent compound regeneration

This commit is contained in:
Brandon 2020-06-20 10:16:00 -04:00
parent d929ca19a8
commit ec2d700c95
1 changed files with 35 additions and 9 deletions

View File

@ -1,5 +1,8 @@
local invisibility = {} local invisibility = {}
local poisoned = {} local poisoned = {}
local regenerating = {}
local strong = {}
local weak = {}
-- reset player invisibility/poison if they go offline -- reset player invisibility/poison if they go offline
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
@ -14,6 +17,18 @@ minetest.register_on_leaveplayer(function(player)
poisoned[name] = nil poisoned[name] = nil
end end
if regenerating[name] then
regenerating[name] = nil
end
if strong[name] then
strong[name] = nil
end
if weak[name] then
weak[name] = nil
end
end) end)
function mcl_potions.invisible(player, toggle) function mcl_potions.invisible(player, toggle)
@ -39,6 +54,13 @@ function mcl_potions.poison(player, toggle)
end end
function mcl_potions.regenerate(player, toggle)
if not player then return false end
regenerating[player:get_player_name()] = toggle
end
function mcl_potions._use_potion(item, obj, color) function mcl_potions._use_potion(item, obj, color)
local d = 0.1 local d = 0.1
local pos = obj:get_pos() local pos = obj:get_pos()
@ -152,6 +174,8 @@ function mcl_potions.poison_func(player, factor, duration)
end end
function mcl_potions.regeneration_func(player, factor, duration) function mcl_potions.regeneration_func(player, factor, duration)
if not regenerating[player:get_player_name()] then
mcl_potions.regenerate(player, true)
for i=1,math.floor(duration/factor) do for i=1,math.floor(duration/factor) do
minetest.after(i*factor, function() minetest.after(i*factor, function()
if player:get_hp() < 20 then if player:get_hp() < 20 then
@ -162,6 +186,8 @@ function mcl_potions.regeneration_func(player, factor, duration)
for i=1,math.floor(duration) do for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end) minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end)
end end
minetest.after(duration, function() mcl_potions.regenerate(player, false) end)
end
end end