Clean up the effect test command a little

This commit is contained in:
Wuzzy 2020-08-08 10:14:37 +02:00
parent a472c30163
commit aaa13878c1

View file

@ -1,3 +1,5 @@
local S = minetest.get_translator("mcl_potions")
local is_invisible = {} local is_invisible = {}
local is_poisoned = {} local is_poisoned = {}
local is_regenerating = {} local is_regenerating = {}
@ -902,28 +904,33 @@ get_chat_function["leaping"] = mcl_potions.leaping_func
get_chat_function["swiftness"] = mcl_potions.swiftness_func get_chat_function["swiftness"] = mcl_potions.swiftness_func
get_chat_function["heal"] = mcl_potions.healing_func get_chat_function["heal"] = mcl_potions.healing_func
minetest.register_chatcommand("potion",{ minetest.register_chatcommand("effect",{
params = "<params>", params = S("<effect> <factor> <duration>"),
description = "Set player potion effects -- arguments <effect (e.g. poison or night_vision)> <factor (1 = 100%)> <duration (sec)>", description = S("Add a status effect to yourself. Arguments: <effect>: name of potion effect, e.g. poison. <factor>: effect strength multiplier (1 = 100%). <duration>: duration in seconds"),
privs = {server = true}, privs = {server = true},
func = function(name, params) func = function(name, params)
P = {} local P = {}
i = 0 local i = 0
for str in string.gmatch(params, "([^ ]+)") do for str in string.gmatch(params, "([^ ]+)") do
i = i + 1 i = i + 1
P[i] = str P[i] = str
end end
if not P[3] then if not P[1] then
P[3] = P[2] return false, S("Missing effect parameter!")
elseif not P[2] then
return false, S("Missing factor parameter!")
elseif not P[3] then
return false, S("Missing duration parameter!")
end end
if get_chat_function[P[1]] then if get_chat_function[P[1]] then
get_chat_function[P[1]](minetest.get_player_by_name(name), tonumber(P[2]), tonumber(P[3])) get_chat_function[P[1]](minetest.get_player_by_name(name), tonumber(P[2]), tonumber(P[3]))
return true
else else
minetest.chat_send_player(name, P[1].." is not an available potion effect. Use /help potion as needed.") return false, S("@1 is not an available potion effect.", P[1])
end end
end , end,
}) })