diff options
author | orwell96 <orwell@bleipb.de> | 2017-10-19 13:37:46 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2017-10-19 13:40:19 +0200 |
commit | a06627f23b052207d3fc23d786c525f2cd26096c (patch) | |
tree | f8365faa71abbd2e531a54124d459deac06de4ab /macro.lua | |
parent | a755607f7d9a84daff679f706f10a5b90743aa5a (diff) |
Add sign macro functionality
Allow to replace certain keywords on signs by defining a single string globally
Diffstat (limited to 'macro.lua')
-rw-r--r-- | macro.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/macro.lua b/macro.lua new file mode 100644 index 0000000..1a6bfa3 --- /dev/null +++ b/macro.lua @@ -0,0 +1,48 @@ +-- signs_lib text macros +-- by orwell96 + +local mstore=minetest.get_mod_storage() + +local macros = minetest.deserialize(mstore:get_string("macros")) or {} + +local function save_macros() + mstore:set_string("macros", minetest.serialize(macros)) +end + +minetest.register_privilege("signs_macro", { description = "May edit sign macros", give_to_singleplayer = true, default = false }) + +minetest.register_chatcommand("signs_macro", { + params = "list | set <macro> <string> | clear <macro>", + description = "List or edit sign macros", + privs = {signs_macros}, + func = function(name, param) + if param=="list" then + local c=0 + for k,v in pairs(macros) do + minetest.chat_send_player(name, "@"..k.." -> "..v) + c=c+1 + end + return true, "Listed "..c.." sign macros." + end + local macro, strg = string.match(param, "^set%s@?([^@%s]+)%s?(.*)$") + if macro and strg then + macros[macro]=strg + save_macros() + return true, "Set macro '@"..macro.."'." + end + macro = string.match(param, "^clear%s@?(%S+)$") + if macro then + macros[macro]=nil + save_macros() + return true, "Cleared macro '@"..macro.."'." + end + return false, "Incorrect usage! Syntax: list | set <macro> <string> | clear <macro>" + end + }) +-- replace_macros(text) +return function(text) + for k, v in pairs(macros) do + text=string.gsub(text, "@"..k, v) + end + return text +end |