diff --git a/mods/ITEMS/mcl_potions/commands.lua b/mods/ITEMS/mcl_potions/commands.lua index c977b8c1c..4b4aa0ba7 100644 --- a/mods/ITEMS/mcl_potions/commands.lua +++ b/mods/ITEMS/mcl_potions/commands.lua @@ -9,8 +9,8 @@ local S = minetest.get_translator(minetest.get_current_modname()) minetest.register_chatcommand("effect",{ - params = S("|heal|list|clear|remove [] [] [NOPART]"), - description = S("Add a status effect to yourself. Arguments: : name of status effect. Passing \"list\" as effect name lists available effects. Passing \"heal\" as effect name heals (or harms) by amount designed by the next parameter. Passing \"clear\" as effect name removes all effects. Passing \"remove\" as effect name removes the effect named by the next parameter. : duration in seconds. (: amount of healing when the effect is \"heal\", passing a negative value subtracts health. : name of a status effect to be removed when using \"remove\" as the previous parameter.) : effect power determinant, bigger level results in more powerful effect for effects that depend on the level (no changes for other effects), defaults to 1, pass F to use low-level factor instead. : effect strength modifier, can mean different things depending on the effect, no changes for effects that do not depend on level/factor. NOPART at the end means no particles will be shown for this effect."), + params = S("|heal|list|clear|remove |INF [] [] [NOPART]"), + description = S("Add a status effect to yourself. Arguments: : name of status effect. Passing \"list\" as effect name lists available effects. Passing \"heal\" as effect name heals (or harms) by amount designed by the next parameter. Passing \"clear\" as effect name removes all effects. Passing \"remove\" as effect name removes the effect named by the next parameter. : duration in seconds. Passing \"INF\" as duration makes the effect infinite. (: amount of healing when the effect is \"heal\", passing a negative value subtracts health. : name of a status effect to be removed when using \"remove\" as the previous parameter.) : effect power determinant, bigger level results in more powerful effect for effects that depend on the level (no changes for other effects), defaults to 1, pass F to use low-level factor instead. : effect strength modifier, can mean different things depending on the effect, no changes for effects that do not depend on level/factor. NOPART at the end means no particles will be shown for this effect."), privs = {server = true}, func = function(name, params) @@ -56,7 +56,7 @@ minetest.register_chatcommand("effect",{ else return false, S("@1 is not an available status effect.", P[2]) end - elseif not tonumber(P[2]) then + elseif not tonumber(P[2]) and P[2] ~= "INF" then return false, S("Missing or invalid duration parameter!") elseif P[3] and not tonumber(P[3]) and P[3] ~= "F" and P[3] ~= "NOPART" then return false, S("Invalid level parameter!") @@ -72,6 +72,8 @@ minetest.register_chatcommand("effect",{ P[4] = "NOPART" end + local inf = P[2] == "INF" + local nopart = false if P[3] == "F" then nopart = P[5] == "NOPART" @@ -82,7 +84,7 @@ minetest.register_chatcommand("effect",{ local def = mcl_potions.registered_effects[P[1]] if def then if P[3] == "F" then - local given = mcl_potions.give_effect(P[1], minetest.get_player_by_name(name), tonumber(P[4]), tonumber(P[2]), nopart) + local given = mcl_potions.give_effect(P[1], minetest.get_player_by_name(name), tonumber(P[4]), inf and "INF" or tonumber(P[2]), nopart) if given then if def.uses_factor then return true, S("@1 effect given to player @2 for @3 seconds with factor of @4.", def.description, name, P[2], P[4]) @@ -93,7 +95,7 @@ minetest.register_chatcommand("effect",{ return false, S("Giving effect @1 to player @2 failed.", def.description, name) end else - local given = mcl_potions.give_effect_by_level(P[1], minetest.get_player_by_name(name), tonumber(P[3]), tonumber(P[2]), nopart) + local given = mcl_potions.give_effect_by_level(P[1], minetest.get_player_by_name(name), tonumber(P[3]), inf and "INF" or tonumber(P[2]), nopart) if given then if def.uses_factor then return true, S("@1 effect on level @2 given to player @3 for @4 seconds.", def.description, P[3], name, P[2]) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index f63ca6e03..d36b8db62 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -1272,8 +1272,12 @@ local function potions_set_icons(player) else player:hud_change(label, "text", "") end - local dur = math.round(vals.dur-vals.timer) - player:hud_change(timestamp, "text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))) + if vals.dur == math.huge then + player:hud_change(timestamp, "text", "∞") + else + local dur = math.round(vals.dur-vals.timer) + player:hud_change(timestamp, "text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))) + end EF[effect_name][player].hud_index = i i = i + 1 end @@ -1309,7 +1313,7 @@ end minetest.register_globalstep(function(dtime) for name, effect in pairs(registered_effects) do for object, vals in pairs(EF[name]) do - EF[name][object].timer = vals.timer + dtime + if vals.dur ~= math.huge then EF[name][object].timer = vals.timer + dtime end if object:get_pos() and not vals.no_particles then mcl_potions._add_spawner(object, effect.particle_color) end if effect.on_step then effect.on_step(dtime, object, vals.factor, vals.dur) end @@ -1331,9 +1335,14 @@ minetest.register_globalstep(function(dtime) potions_set_hud(object) end elseif object:is_player() then - local dur = math.round(vals.dur-vals.timer) - object:hud_change(icon_ids[object:get_player_name()][vals.hud_index].timestamp, - "text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))) + if vals.dur == math.huge then + object:hud_change(icon_ids[object:get_player_name()][vals.hud_index].timestamp, + "text", "∞") + else + local dur = math.round(vals.dur-vals.timer) + object:hud_change(icon_ids[object:get_player_name()][vals.hud_index].timestamp, + "text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))) + end end end end @@ -1727,6 +1736,9 @@ function mcl_potions.give_effect(name, object, factor, duration, no_particles) if edef.timer_uses_factor then vals.step = factor else vals.step = edef.hit_timer_step end end + if duration == "INF" then + vals.dur = math.huge + end EF[name][object] = vals if edef.on_start then edef.on_start(object, factor) end else @@ -1742,6 +1754,9 @@ function mcl_potions.give_effect(name, object, factor, duration, no_particles) if edef.timer_uses_factor then present.step = factor end if edef.on_start then edef.on_start(object, factor) end end + if duration == "INF" then + present.dur = math.huge + end else return false end