Fixed alchemy bug

This commit is contained in:
Billy S 2019-03-02 14:26:08 -05:00
parent 1bd1088636
commit 16534fbd1b

View File

@ -4,18 +4,16 @@ local time_multiplier = 1.3
local function decrease_effect_timer()
for p, eList in pairs(alchemy.active_effects) do
local player = minetest.get_player_by_name(p)
if player then
for e, t in pairs(eList) do
alchemy.active_effects[p][e].time = t.time - 1
if t.time <= 0 then
if t.on_end then
t.on_end(t.target)
t.on_end(player)
end
if player then
alchemy.hud.remove_effect(player, t.number, t)
end
alchemy.active_effects[p][e] = nil
else
if player then
-- Update the HUD
alchemy.hud.update_effect(player, t.number, t)
-- Run on_tick function
@ -73,6 +71,16 @@ local function register_timed_effect(e, def)
end
end
-- When the player rejoins, re-add their HUDs
minetest.register_on_joinplayer(function(player)
local pName = player:get_player_name()
if alchemy.active_effects[n] == nil then return end
for e, eTable in pairs(alchemy.active_effects[n]) do
local eNum = alchemy.hud.add_effect(player, eTable)
alchemy.active_effects[n][e].number = eNum
end
end)
alchemy.register_effect = register_effect
alchemy.register_timed_effect = register_timed_effect
@ -148,12 +156,9 @@ register_timed_effect("jump_boost", {
on_start = function(player, pos)
set_player_physics_multiplier(player, {jump = 2}, 20, "potions jump boost")
end,
on_end = function(n)
local player = minetest.get_player_by_name(n)
if player then
on_end = function(player)
remove_player_physics_multiplier(player, "potions jump boost")
end
end
})
-- Speed brew
@ -163,12 +168,9 @@ register_timed_effect("speed_boost", {
on_start = function(player, pos)
set_player_physics_multiplier(player, {speed = 2}, 20, "potions speed boost")
end,
on_end = function(n)
local player = minetest.get_player_by_name(n)
if player then
on_end = function(player)
remove_player_physics_multiplier(player, "potions speed boost")
end
end
})
-- Invisibility potion
@ -178,12 +180,9 @@ register_timed_effect("invisibility_brew", {
on_start = function(player, pos)
player:set_properties({visual_size = {x = 0, y = 0}})
end,
on_end = function(n)
local player = minetest.get_player_by_name(n)
if player then
on_end = function(player)
player:set_properties({visual_size = {x = 1, y = 1}})
end
end
})
-- Water-breathing potion