1
0
Fork 0

Allowed giving effect without particles

...both with API and the /effect command
This commit is contained in:
the-real-herowl 2024-04-14 04:04:04 +02:00
parent 7c2d74e983
commit dcbc9d2398
2 changed files with 22 additions and 11 deletions

View File

@ -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 <duration|heal-amount> [<level>] [<factor>]"), params = S("<effect>|heal|list <duration|heal-amount> [<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. <duration>: duration in seconds. (<heal-amount>: amount of healing when the effect is \"heal\", passing a negative value subtracts health.) <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."), 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. <duration>: duration in seconds. (<heal-amount>: amount of healing when the effect is \"heal\", passing a negative value subtracts health.) <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)
@ -45,7 +45,7 @@ minetest.register_chatcommand("effect",{
end end
elseif not tonumber(P[2]) then elseif not tonumber(P[2]) 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" 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!")
elseif P[3] and P[3] == "F" and not P[4] then elseif P[3] and P[3] == "F" and not P[4] then
return false, S("Missing or invalid factor parameter when level is F!") return false, S("Missing or invalid factor parameter when level is F!")
@ -54,12 +54,22 @@ minetest.register_chatcommand("effect",{
-- Default level = 1 -- Default level = 1
if not P[3] then if not P[3] then
P[3] = 1 P[3] = 1
elseif P[3] == "NOPART" then
P[3] = 1
P[4] = "NOPART"
end
local nopart = false
if P[3] == "F" then
nopart = P[5] == "NOPART"
else
nopart = P[4] == "NOPART"
end end
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])) local given = mcl_potions.give_effect(P[1], minetest.get_player_by_name(name), tonumber(P[4]), 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])
@ -70,7 +80,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])) local given = mcl_potions.give_effect_by_level(P[1], minetest.get_player_by_name(name), tonumber(P[3]), 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])

View File

@ -1311,7 +1311,7 @@ minetest.register_globalstep(function(dtime)
for object, vals in pairs(EF[name]) do for object, vals in pairs(EF[name]) do
EF[name][object].timer = vals.timer + dtime EF[name][object].timer = vals.timer + dtime
if object:get_pos() 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
if effect.on_hit_timer then if effect.on_hit_timer then
EF[name][object].hit_timer = (vals.hit_timer or 0) + dtime EF[name][object].hit_timer = (vals.hit_timer or 0) + dtime
@ -1702,11 +1702,11 @@ local function target_valid(object, name)
and registered_effects[name].res_condition(object)) then return true end and registered_effects[name].res_condition(object)) then return true end
end end
function mcl_potions.give_effect(name, object, factor, duration) function mcl_potions.give_effect(name, object, factor, duration, no_particles)
local edef = registered_effects[name] local edef = registered_effects[name]
if not edef or not target_valid(object, name) then return false end if not edef or not target_valid(object, name) then return false end
if not EF[name][object] then if not EF[name][object] then
local vals = {dur = duration, timer = 0,} local vals = {dur = duration, timer = 0, no_particles = no_particles}
if edef.uses_factor then vals.factor = factor end if edef.uses_factor then vals.factor = factor end
if edef.on_hit_timer then if edef.on_hit_timer then
if edef.timer_uses_factor then vals.step = factor if edef.timer_uses_factor then vals.step = factor
@ -1716,6 +1716,7 @@ function mcl_potions.give_effect(name, object, factor, duration)
if edef.on_start then edef.on_start(object, factor) end if edef.on_start then edef.on_start(object, factor) end
else else
local present = EF[name][object] local present = EF[name][object]
present.no_particles = no_particles
if not edef.uses_factor or (edef.uses_factor and if not edef.uses_factor or (edef.uses_factor and
(not edef.inv_factor and factor >= present.factor (not edef.inv_factor and factor >= present.factor
or edef.inv_factor and factor <= present.factor)) then or edef.inv_factor and factor <= present.factor)) then
@ -1736,13 +1737,13 @@ function mcl_potions.give_effect(name, object, factor, duration)
return true return true
end end
function mcl_potions.give_effect_by_level(name, object, level, duration) function mcl_potions.give_effect_by_level(name, object, level, duration, no_particles)
if level == 0 then return false end if level == 0 then return false end
if not registered_effects[name].uses_factor then if not registered_effects[name].uses_factor then
return mcl_potions.give_effect(name, object, 0, duration) return mcl_potions.give_effect(name, object, 0, duration, no_particles)
end end
local factor = registered_effects[name].level_to_factor(level) local factor = registered_effects[name].level_to_factor(level)
return mcl_potions.give_effect(name, object, factor, duration) return mcl_potions.give_effect(name, object, factor, duration, no_particles)
end end
function mcl_potions.healing_func(object, hp) function mcl_potions.healing_func(object, hp)