Command batching feature

This commit is contained in:
Kevin Mok 2019-07-27 18:26:02 -04:00
parent e4dfa68586
commit a2700378c9
Signed by: Kevin-Mok
GPG Key ID: AEA75288DC135CF5
2 changed files with 32 additions and 16 deletions

View File

@ -1,19 +1,22 @@
aliases = {}
function alias(short, orig, param)
aliases[short] = {
orig = orig,
param = param or ""
}
function alias(short, cmd_table)
aliases[short] = cmd_table
end
alias("gim", "giveme")
alias("grm", "grantme")
-- needs to be in minetest game?
-- alias("h", "home")
alias("sd", "shutdown")
alias("t", "teleport")
alias("t0", "teleport", "0 0 0")
aliases["clc"] = { { "fp", "s1 -2 1 2" }, { "fp", "s2 2 1 -2" }, { "cl" } }
aliases["day"] = { { "time", "6000" } }
aliases["gim"] = { { "giveme" } }
aliases["grm"] = { { "grantme" } }
aliases["grma"] = { { "grantme", "all" } }
aliases["sd"] = { { "shutdown" } }
aliases["t"] = { { "teleport" } }
aliases["tr"] = { { "pulverize" } }
aliases["t0"] = { { "teleport", "0 0 0" }, { "teleport", "1 1 1" } }
-- TODO: move WorldEdit aliases here --
minetest.register_on_sending_chat_message(function(message)
if message:sub(1,1) ~= "/" then
@ -27,13 +30,18 @@ minetest.register_on_sending_chat_message(function(message)
end
param = param or ""
-- run each cmd pair
if (not minetest.registered_chatcommands[cmd]) and (aliases[cmd]) then
if aliases[cmd].param ~= "" then
param = aliases[cmd].param
for i, cmd_pair in ipairs(aliases[cmd]) do
-- only keep passed in param if first cmd and no given param
if table.getn(cmd_pair) > 1 then
param = cmd_pair[2]
elseif i > 1 then
param = ""
end
minetest.display_chat_message("alias for: /" .. cmd_pair[1] .. " " .. param)
minetest.run_server_chatcommand(cmd_pair[1], 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)

View File

@ -1,5 +1,13 @@
- csm_restriction_flags instructions
- in-game alias modifications
- name teleport locations
- get current pos.
- new chat cmd
- toggle showing full command after running
- setting?
- store/read from JSON table?
- series of commands
- record?
- rename to aliases
- Server Command Aliases
- tests?