mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-25 02:42:25 +01:00
Allowed infinite effect duration
This commit is contained in:
parent
75e5ca8d49
commit
9b501bfa7e
@ -9,8 +9,8 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
|
||||
minetest.register_chatcommand("effect",{
|
||||
params = S("<effect>|heal|list|clear|remove <duration|heal-amount|effect> [<level>] [<factor>] [NOPART]"),
|
||||
description = S("Add a status effect to yourself. Arguments: <effect>: 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>: duration in seconds. (<heal-amount>: amount of healing when the effect is \"heal\", passing a negative value subtracts health. <effect>: name of a status effect to be removed when using \"remove\" as the previous parameter.) <level>: 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. <factor>: 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("<effect>|heal|list|clear|remove <duration|heal-amount|effect>|INF [<level>] [<factor>] [NOPART]"),
|
||||
description = S("Add a status effect to yourself. Arguments: <effect>: 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>: duration in seconds. Passing \"INF\" as duration makes the effect infinite. (<heal-amount>: amount of healing when the effect is \"heal\", passing a negative value subtracts health. <effect>: name of a status effect to be removed when using \"remove\" as the previous parameter.) <level>: 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. <factor>: 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])
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user