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() local function decrease_effect_timer()
for p, eList in pairs(alchemy.active_effects) do for p, eList in pairs(alchemy.active_effects) do
local player = minetest.get_player_by_name(p) local player = minetest.get_player_by_name(p)
if player then
for e, t in pairs(eList) do for e, t in pairs(eList) do
alchemy.active_effects[p][e].time = t.time - 1 alchemy.active_effects[p][e].time = t.time - 1
if t.time <= 0 then if t.time <= 0 then
if t.on_end then if t.on_end then
t.on_end(t.target) t.on_end(player)
end end
if player then
alchemy.hud.remove_effect(player, t.number, t) alchemy.hud.remove_effect(player, t.number, t)
end
alchemy.active_effects[p][e] = nil alchemy.active_effects[p][e] = nil
else else
if player then
-- Update the HUD -- Update the HUD
alchemy.hud.update_effect(player, t.number, t) alchemy.hud.update_effect(player, t.number, t)
-- Run on_tick function -- Run on_tick function
@ -73,6 +71,16 @@ local function register_timed_effect(e, def)
end end
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_effect = register_effect
alchemy.register_timed_effect = register_timed_effect alchemy.register_timed_effect = register_timed_effect
@ -148,12 +156,9 @@ register_timed_effect("jump_boost", {
on_start = function(player, pos) on_start = function(player, pos)
set_player_physics_multiplier(player, {jump = 2}, 20, "potions jump boost") set_player_physics_multiplier(player, {jump = 2}, 20, "potions jump boost")
end, end,
on_end = function(n) on_end = function(player)
local player = minetest.get_player_by_name(n)
if player then
remove_player_physics_multiplier(player, "potions jump boost") remove_player_physics_multiplier(player, "potions jump boost")
end end
end
}) })
-- Speed brew -- Speed brew
@ -163,12 +168,9 @@ register_timed_effect("speed_boost", {
on_start = function(player, pos) on_start = function(player, pos)
set_player_physics_multiplier(player, {speed = 2}, 20, "potions speed boost") set_player_physics_multiplier(player, {speed = 2}, 20, "potions speed boost")
end, end,
on_end = function(n) on_end = function(player)
local player = minetest.get_player_by_name(n)
if player then
remove_player_physics_multiplier(player, "potions speed boost") remove_player_physics_multiplier(player, "potions speed boost")
end end
end
}) })
-- Invisibility potion -- Invisibility potion
@ -178,12 +180,9 @@ register_timed_effect("invisibility_brew", {
on_start = function(player, pos) on_start = function(player, pos)
player:set_properties({visual_size = {x = 0, y = 0}}) player:set_properties({visual_size = {x = 0, y = 0}})
end, end,
on_end = function(n) on_end = function(player)
local player = minetest.get_player_by_name(n)
if player then
player:set_properties({visual_size = {x = 1, y = 1}}) player:set_properties({visual_size = {x = 1, y = 1}})
end end
end
}) })
-- Water-breathing potion -- Water-breathing potion