1
0
Fork 0

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,15 +174,19 @@ 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)
for i=1,math.floor(duration/factor) do if not regenerating[player:get_player_name()] then
minetest.after(i*factor, function() mcl_potions.regenerate(player, true)
if player:get_hp() < 20 then for i=1,math.floor(duration/factor) do
player:set_hp(player:get_hp() + 1) minetest.after(i*factor, function()
end if player:get_hp() < 20 then
end ) player:set_hp(player:get_hp() + 1)
end end
for i=1,math.floor(duration) do end )
minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end) end
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end)
end
minetest.after(duration, function() mcl_potions.regenerate(player, false) end)
end end
end end