From e4dfa685864e9fb495d3bd614cb9b3279ece67fe Mon Sep 17 00:00:00 2001 From: Kevin Mok Date: Sat, 27 Jul 2019 07:18:10 -0400 Subject: [PATCH] Switch to client-side mod to get parameters Add todo. --- init.lua | 43 +++++++++++++++++++++++++++++++------------ todo.md | 5 +++++ 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 todo.md diff --git a/init.lua b/init.lua index 0367b40..d026149 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,10 @@ --- https://github.com/Uberi/Minetest-WorldEdit/blob/master/worldedit_shortcommands/init.lua -function alias(short, orig) - if not minetest.chatcommands[orig] then - minetest.log("error", "custom_aliases: original command " .. orig .. " does not exist") - return true - end - if minetest.chatcommands[short] then - minetest.log("error", "custom_aliases: alias " .. short .. " already exists") - return true - end - minetest.register_chatcommand(short, minetest.chatcommands[orig]) - return false +aliases = {} + +function alias(short, orig, param) + aliases[short] = { + orig = orig, + param = param or "" + } end alias("gim", "giveme") @@ -18,3 +13,27 @@ alias("grm", "grantme") -- alias("h", "home") alias("sd", "shutdown") alias("t", "teleport") +alias("t0", "teleport", "0 0 0") + +minetest.register_on_sending_chat_message(function(message) + if message:sub(1,1) ~= "/" then + return + end + + local cmd, param = string.match(message, "^/([^ ]+) *(.*)") + if not cmd then + minetest.display_chat_message("-!- Empty command") + return true + end + param = param or "" + + if (not minetest.registered_chatcommands[cmd]) and (aliases[cmd]) then + if aliases[cmd].param ~= "" then + param = aliases[cmd].param + end + -- minetest.display_chat_message("Param = " .. param) + minetest.display_chat_message("alias for: /" .. aliases[cmd].orig .. " " .. param) + minetest.run_server_chatcommand(aliases[cmd].orig, param) + return true + end +end) diff --git a/todo.md b/todo.md new file mode 100644 index 0000000..f12e98a --- /dev/null +++ b/todo.md @@ -0,0 +1,5 @@ +- csm_restriction_flags instructions +- in-game alias modifications +- name teleport locations +- toggle showing full command after running + - setting?