From 006e740e7bf9122e1adc8c4d8722c3170b6b4db6 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sun, 12 Sep 2021 13:38:38 +0200 Subject: [PATCH] Add a chat command to execute a chat command multiple times --- init.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/init.lua b/init.lua index ad8e2ba..f1d3bbf 100644 --- a/init.lua +++ b/init.lua @@ -36,6 +36,26 @@ minetest.register_chatcommand("run_as", { end, }) +minetest.register_chatcommand("repeat", { + params = " /", + description = "Run a chatcommand multiple times", + func = function(name, param) + local repetitions, msg = param:match"^([0-9]+) *(/.*)" + if not repetitions then + return false, "Invalid arguments (see /help run_as)." + end + repetitions = tonumber(repetitions) + if repetitions > 5 + and not minetest.check_player_privs(name, "server") then + return false, + "More than 5 repetitions require the server privilege." + end + for _ = 1, repetitions do + execute_chatcommand(name, msg) + end + end, +}) + minetest.register_chatcommand("grantme", { params = "|all", description = "Give privilege to yourself",