From 477bc52fe4cab055b973b00f0d0c645cb01db432 Mon Sep 17 00:00:00 2001 From: Niklp Date: Wed, 9 Oct 2024 21:10:08 +0200 Subject: [PATCH] Add `/map` command Co-authored-by: debagos --- archtec/locale/template.txt | 4 +++- archtec/scripts/news.lua | 2 +- archtec/scripts/random_things.lua | 30 +++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/archtec/locale/template.txt b/archtec/locale/template.txt index 3434989..f6051c0 100644 --- a/archtec/locale/template.txt +++ b/archtec/locale/template.txt @@ -92,7 +92,7 @@ Mailbox for Rent= [music_list] @1= No news available= Continue= -Ctrl + Click the link to open your browser:= +Ctrl + Click the link to open your browser= You can't place more '@1' in this area!= You can't place more '@1' in this area! (Too many entities)= NO= @@ -156,6 +156,8 @@ You can't thank an offline player!= You used '/thankyou' within the last hour! Try again later.= @1 said thank you to @2.= @1 requested a server shutdown in @2 seconds.= +[map] You must be online to use this command!= +[map] You are here: @1 (@2)= [report] Report successfully created. GitHub URL: @1= Report issue/Send feature request= Max. number of characters: @1= diff --git a/archtec/scripts/news.lua b/archtec/scripts/news.lua index 617cc8b..cd682a2 100644 --- a/archtec/scripts/news.lua +++ b/archtec/scripts/news.lua @@ -41,7 +41,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if url ~= nil then local name = player:get_player_name() minetest.close_formspec(name, "archtec:news") - minetest.chat_send_player(name, minetest.colorize("#FF8800", S("Ctrl + Click the link to open your browser:")) .. " " .. url) + minetest.chat_send_player(name, minetest.colorize("#FF8800", S("Ctrl + Click the link to open your browser") .. ":") .. " " .. url) end end diff --git a/archtec/scripts/random_things.lua b/archtec/scripts/random_things.lua index a3969cc..f54903a 100644 --- a/archtec/scripts/random_things.lua +++ b/archtec/scripts/random_things.lua @@ -1,4 +1,5 @@ local S = archtec.S +local C = minetest.colorize -- Remove building category if minetest.get_modpath("unified_inventory") then @@ -128,4 +129,31 @@ archtec.register_chatcommand_alias("so", "set_owner") archtec.register_chatcommand_alias("ao", "add_owner") archtec.register_chatcommand_alias("sa", "select_area") archtec.register_chatcommand_alias("p1", "area_pos1") -archtec.register_chatcommand_alias("p2", "area_pos2") \ No newline at end of file +archtec.register_chatcommand_alias("p2", "area_pos2") + +-- /map command +local url = archtec.links.mapserver .. "#!/map/0/12/" -- layer/zoomlevel +local help_str = C("#FF8800", S("Ctrl + Click the link to open your browser")) + +minetest.register_chatcommand("map", { + description = "Gives you an URL to the Mapserver, pointing at your current position.", + privs = {interact = true}, + func = function(name) + minetest.log("action", "[/thankyou] executed by '" .. name .. "'") + local player = minetest.get_player_by_name(name) + if player == nil then + minetest.chat_send_player(name, C("#FF0000", S("[map] You must be online to use this command!"))) + return + end + + local pos = player:get_pos() + if pos == nil then + minetest.chat_send_player(name, C("#FF0000", S("[map] You must be online to use this command!"))) + return + else + local x = math.floor(pos.x + 0.5) + local z = math.floor(pos.z + 0.5) + minetest.chat_send_player(name, S("[map] You are here: @1 (@2)", url .. tostring(x) .. "/" .. tostring(z), help_str)) + end + end +})