2021-05-29 14:12:33 +00:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2020-08-10 08:40:10 +00:00
-- ░█████╗░██╗░░██╗░█████╗░████████╗ ░█████╗░░█████╗░███╗░░░███╗███╗░░░███╗░█████╗░███╗░░██╗██████╗░░██████╗
-- ██╔══██╗██║░░██║██╔══██╗╚══██╔══╝ ██╔══██╗██╔══██╗████╗░████║████╗░████║██╔══██╗████╗░██║██╔══██╗██╔════╝
-- ██║░░╚═╝███████║███████║░░░██║░░░ ██║░░╚═╝██║░░██║██╔████╔██║██╔████╔██║███████║██╔██╗██║██║░░██║╚█████╗░
-- ██║░░██╗██╔══██║██╔══██║░░░██║░░░ ██║░░██╗██║░░██║██║╚██╔╝██║██║╚██╔╝██║██╔══██║██║╚████║██║░░██║░╚═══██╗
-- ╚█████╔╝██║░░██║██║░░██║░░░██║░░░ ╚█████╔╝╚█████╔╝██║░╚═╝░██║██║░╚═╝░██║██║░░██║██║░╚███║██████╔╝██████╔╝
-- ░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░ ░╚════╝░░╚════╝░╚═╝░░░░░╚═╝╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═════╝░╚═════╝░
minetest.register_chatcommand ( " effect " , {
2024-04-14 02:50:24 +00:00
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. " ) ,
2020-08-10 08:40:10 +00:00
privs = { server = true } ,
func = function ( name , params )
local P = { }
local i = 0
for str in string.gmatch ( params , " ([^ ]+) " ) do
i = i + 1
P [ i ] = str
end
if not P [ 1 ] then
return false , S ( " Missing effect parameter! " )
2023-10-09 23:07:26 +00:00
elseif P [ 1 ] == " list " then
local effects = " heal "
2024-01-10 20:57:15 +00:00
for effect , _ in pairs ( mcl_potions.registered_effects ) do
effects = effects .. " , " .. effect
2023-10-09 23:07:26 +00:00
end
return true , effects
2023-10-12 21:51:14 +00:00
elseif P [ 1 ] == " heal " then
local hp = tonumber ( P [ 2 ] )
if not hp or hp == 0 then
return false , S ( " Missing or invalid heal amount parameter! " )
else
mcl_potions.healing_func ( minetest.get_player_by_name ( name ) , hp )
if hp > 0 then
if hp < 1 then hp = 1 end
return true , S ( " Player @1 healed by @2 HP. " , name , hp )
else
if hp > - 1 then hp = - 1 end
return true , S ( " Player @1 harmed by @2 HP. " , name , hp )
end
end
2024-04-14 02:27:09 +00:00
elseif P [ 1 ] == " clear " then
Improved API mob support
* various API functions now work with mobs properly
* the following effects don't work with mobs at all:
water breathing, dolphin's grace, leaping, swiftness,
slowness, slow falling, night vision, darkness, frost,
health boost, absorption, fire resistance, resistance,
luck, bad luck, blindness, nausea, hunger, saturation,
haste, fatigue, conduit power
* the following effects should work with mobs:
invisibility, regeneration, poison, withering,
strength, weakness, levitation, glowing
* the following effects have no effect on mobs
(but can be applied with the API):
bad omen, hero of the village
2024-04-14 05:45:39 +00:00
mcl_potions._reset_effects ( minetest.get_player_by_name ( name ) )
2024-04-14 02:27:09 +00:00
return true , S ( " Effects cleared for player @1 " , name )
elseif P [ 1 ] == " remove " then
if not P [ 2 ] then
return false , S ( " Missing effect parameter! " )
end
if mcl_potions.registered_effects [ P [ 2 ] ] then
mcl_potions.clear_effect ( minetest.get_player_by_name ( name ) , P [ 2 ] )
return true , S ( " Removed effect @1 from player @2 " , P [ 2 ] , name )
else
return false , S ( " @1 is not an available status effect. " , P [ 2 ] )
end
2024-04-14 02:50:24 +00:00
elseif not tonumber ( P [ 2 ] ) and P [ 2 ] ~= " INF " then
2020-08-10 08:40:10 +00:00
return false , S ( " Missing or invalid duration parameter! " )
2024-04-14 02:04:04 +00:00
elseif P [ 3 ] and not tonumber ( P [ 3 ] ) and P [ 3 ] ~= " F " and P [ 3 ] ~= " NOPART " then
2023-10-09 23:07:26 +00:00
return false , S ( " Invalid level parameter! " )
elseif P [ 3 ] and P [ 3 ] == " F " and not P [ 4 ] then
return false , S ( " Missing or invalid factor parameter when level is F! " )
2020-08-10 08:40:10 +00:00
end
2023-10-09 23:07:26 +00:00
-- Default level = 1
2020-08-10 08:40:10 +00:00
if not P [ 3 ] then
2023-10-09 23:07:26 +00:00
P [ 3 ] = 1
2024-04-14 02:04:04 +00:00
elseif P [ 3 ] == " NOPART " then
P [ 3 ] = 1
P [ 4 ] = " NOPART "
end
2024-04-14 02:50:24 +00:00
local inf = P [ 2 ] == " INF "
2024-04-14 02:04:04 +00:00
local nopart = false
if P [ 3 ] == " F " then
nopart = P [ 5 ] == " NOPART "
else
nopart = P [ 4 ] == " NOPART "
2020-08-10 08:40:10 +00:00
end
2023-10-27 03:02:43 +00:00
local def = mcl_potions.registered_effects [ P [ 1 ] ]
if def then
2023-10-09 23:07:26 +00:00
if P [ 3 ] == " F " then
2024-04-14 02:50:24 +00:00
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 )
2023-10-09 23:07:26 +00:00
if given then
2024-01-10 20:57:15 +00:00
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 ] )
else
return true , S ( " @1 effect given to player @2 for @3 seconds. " , def.description , name , P [ 2 ] )
end
2023-10-09 23:07:26 +00:00
else
2023-10-27 03:02:43 +00:00
return false , S ( " Giving effect @1 to player @2 failed. " , def.description , name )
2023-10-09 23:07:26 +00:00
end
else
2024-04-14 02:50:24 +00:00
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 )
2023-10-09 23:07:26 +00:00
if given then
2024-01-10 20:57:15 +00:00
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 ] )
else
return true , S ( " @1 effect given to player @2 for @3 seconds. " , def.description , name , P [ 2 ] )
end
2023-10-09 23:07:26 +00:00
else
2023-10-27 03:02:43 +00:00
return false , S ( " Giving effect @1 to player @2 failed. " , def.description , name )
2023-10-09 23:07:26 +00:00
end
end
2020-08-10 08:40:10 +00:00
else
2020-08-10 08:44:57 +00:00
return false , S ( " @1 is not an available status effect. " , P [ 1 ] )
2020-08-10 08:40:10 +00:00
end
end ,
} )
2023-10-09 23:07:26 +00:00