forked from VoxeLibre/VoxeLibre
Keep poisons from killing the player and prevent compounding poison effects.
This commit is contained in:
parent
bd9fd780eb
commit
a5e3b259fa
|
@ -1,13 +1,19 @@
|
||||||
local invisibility = {}
|
local invisibility = {}
|
||||||
|
local poisoned = {}
|
||||||
|
|
||||||
-- reset player invisibility if they go offline
|
-- reset player invisibility/poison if they go offline
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if invisibility[name] then
|
if invisibility[name] then
|
||||||
invisibility[name] = nil
|
invisibility[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if poisoned[name] then
|
||||||
|
poisoned[name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mcl_potions.invisible(player, toggle)
|
function mcl_potions.invisible(player, toggle)
|
||||||
|
@ -26,6 +32,13 @@ function mcl_potions.invisible(player, toggle)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mcl_potions.poison(player, toggle)
|
||||||
|
|
||||||
|
if not player then return false end
|
||||||
|
poisoned[player:get_player_name()] = toggle
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function mcl_potions._use_potion(item, pos, color)
|
function mcl_potions._use_potion(item, pos, color)
|
||||||
local d = 0.1
|
local d = 0.1
|
||||||
item:replace("mcl_potions:glass_bottle")
|
item:replace("mcl_potions:glass_bottle")
|
||||||
|
@ -59,10 +72,11 @@ end
|
||||||
function mcl_potions.healing_func(player, hp)
|
function mcl_potions.healing_func(player, hp)
|
||||||
|
|
||||||
if is_zombie[player:get_entity_name()] then hp = -hp end
|
if is_zombie[player:get_entity_name()] then hp = -hp end
|
||||||
|
|
||||||
if hp > 0 then
|
if hp > 0 then
|
||||||
player:set_hp(math.min(player:get_hp() + hp, player:get_properties().hp_max))
|
player:set_hp(math.min(player:get_hp() + hp, player:get_properties().hp_max))
|
||||||
else
|
else
|
||||||
player:set_hp(player:get_hp() + hp)
|
player:set_hp(math.max(player:get_hp() + hp, 1))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -86,8 +100,17 @@ function mcl_potions.weakness_func(player, factor, duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_potions.poison_func(player, factor, duration)
|
function mcl_potions.poison_func(player, factor, duration)
|
||||||
|
|
||||||
|
if not poisoned[player:get_player_name()] then
|
||||||
|
mcl_potions.poison(player, true)
|
||||||
for i=1,math.floor(duration/factor) do
|
for i=1,math.floor(duration/factor) do
|
||||||
minetest.after(i*factor, function() player:set_hp(player:get_hp() - 1) end)
|
minetest.after(i*factor, function()
|
||||||
|
if poisoned[player:get_player_name()] then
|
||||||
|
player:set_hp(math.max(player:get_hp() - 1,1))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
minetest.after(duration, function() mcl_potions.poison(player, false) end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue