mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-25 20:11:06 +01:00
Allowed infinite effect duration
This commit is contained in:
parent
75e5ca8d49
commit
9b501bfa7e
2 changed files with 28 additions and 11 deletions
|
@ -9,8 +9,8 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("effect",{
|
minetest.register_chatcommand("effect",{
|
||||||
params = S("<effect>|heal|list|clear|remove <duration|heal-amount|effect> [<level>] [<factor>] [NOPART]"),
|
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. (<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."),
|
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},
|
privs = {server = true},
|
||||||
func = function(name, params)
|
func = function(name, params)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ minetest.register_chatcommand("effect",{
|
||||||
else
|
else
|
||||||
return false, S("@1 is not an available status effect.", P[2])
|
return false, S("@1 is not an available status effect.", P[2])
|
||||||
end
|
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!")
|
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
|
elseif P[3] and not tonumber(P[3]) and P[3] ~= "F" and P[3] ~= "NOPART" then
|
||||||
return false, S("Invalid level parameter!")
|
return false, S("Invalid level parameter!")
|
||||||
|
@ -72,6 +72,8 @@ minetest.register_chatcommand("effect",{
|
||||||
P[4] = "NOPART"
|
P[4] = "NOPART"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inf = P[2] == "INF"
|
||||||
|
|
||||||
local nopart = false
|
local nopart = false
|
||||||
if P[3] == "F" then
|
if P[3] == "F" then
|
||||||
nopart = P[5] == "NOPART"
|
nopart = P[5] == "NOPART"
|
||||||
|
@ -82,7 +84,7 @@ minetest.register_chatcommand("effect",{
|
||||||
local def = mcl_potions.registered_effects[P[1]]
|
local def = mcl_potions.registered_effects[P[1]]
|
||||||
if def then
|
if def then
|
||||||
if P[3] == "F" 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 given then
|
||||||
if def.uses_factor 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])
|
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)
|
return false, S("Giving effect @1 to player @2 failed.", def.description, name)
|
||||||
end
|
end
|
||||||
else
|
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 given then
|
||||||
if def.uses_factor 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])
|
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
|
else
|
||||||
player:hud_change(label, "text", "")
|
player:hud_change(label, "text", "")
|
||||||
end
|
end
|
||||||
|
if vals.dur == math.huge then
|
||||||
|
player:hud_change(timestamp, "text", "∞")
|
||||||
|
else
|
||||||
local dur = math.round(vals.dur-vals.timer)
|
local dur = math.round(vals.dur-vals.timer)
|
||||||
player:hud_change(timestamp, "text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60)))
|
player:hud_change(timestamp, "text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60)))
|
||||||
|
end
|
||||||
EF[effect_name][player].hud_index = i
|
EF[effect_name][player].hud_index = i
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
@ -1309,7 +1313,7 @@ end
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
for name, effect in pairs(registered_effects) do
|
for name, effect in pairs(registered_effects) do
|
||||||
for object, vals in pairs(EF[name]) 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 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
|
if effect.on_step then effect.on_step(dtime, object, vals.factor, vals.dur) end
|
||||||
|
@ -1331,12 +1335,17 @@ minetest.register_globalstep(function(dtime)
|
||||||
potions_set_hud(object)
|
potions_set_hud(object)
|
||||||
end
|
end
|
||||||
elseif object:is_player() then
|
elseif object:is_player() then
|
||||||
|
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)
|
local dur = math.round(vals.dur-vals.timer)
|
||||||
object:hud_change(icon_ids[object:get_player_name()][vals.hud_index].timestamp,
|
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)))
|
"text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
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
|
if edef.timer_uses_factor then vals.step = factor
|
||||||
else vals.step = edef.hit_timer_step end
|
else vals.step = edef.hit_timer_step end
|
||||||
end
|
end
|
||||||
|
if duration == "INF" then
|
||||||
|
vals.dur = math.huge
|
||||||
|
end
|
||||||
EF[name][object] = vals
|
EF[name][object] = vals
|
||||||
if edef.on_start then edef.on_start(object, factor) end
|
if edef.on_start then edef.on_start(object, factor) end
|
||||||
else
|
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.timer_uses_factor then present.step = factor end
|
||||||
if edef.on_start then edef.on_start(object, factor) end
|
if edef.on_start then edef.on_start(object, factor) end
|
||||||
end
|
end
|
||||||
|
if duration == "INF" then
|
||||||
|
present.dur = math.huge
|
||||||
|
end
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue