From 9077feb1a990a35e8e14c23d0c50becaf0c3d380 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Thu, 16 Jan 2025 21:21:32 +0100 Subject: [PATCH] addons: added effect send_coordinates (useful in combination with a waypoint_compass but can be used manually as well) --- addons/effect_send_coordinates.lua | 45 ++++++++++++++++++++++++++++++ addons/load_addons.lua | 3 ++ 2 files changed, 48 insertions(+) create mode 100644 addons/effect_send_coordinates.lua diff --git a/addons/effect_send_coordinates.lua b/addons/effect_send_coordinates.lua new file mode 100644 index 0000000..491b57b --- /dev/null +++ b/addons/effect_send_coordinates.lua @@ -0,0 +1,45 @@ +-- hand out a preconfigured waypoint compass to the player +yl_speak_up.custom_functions_r_[ "send_coordinates" ] = { + description = "Send a chat message to the player with coordinates.", + param1_text = "X coordinate:", + param1_desc = "The target x coordinate.", + param2_text = "Y coordinate:", + param2_desc = "The target y coordinate.", + param3_text = "Z coordinate:", + param3_desc = "The target z coordinate.", + param4_text = "Name of target location:", + param4_desc = "This is how the target location is called, i.e. \"Hidden treasure chest\".", + -- the color cannot be set this way +-- param5_text = "Color code in Hex:", +-- param5_desc = "Give the color for the compass here. Example: \"FFD700\".\n".. +-- "Needs to be 6 characters long, with each character ranging\n".. +-- "from 0-9 or beeing A, B, C, D, E or F.\n".. +-- "Or just write something like yellow, orange etc.", + code = function(player, n_id, r) + local pname = player:get_player_name() + local coords = core.string_to_pos((r.r_param1 or "0")..",".. + (r.r_param2 or "0")..",".. + (r.r_param3 or "0")) + local town = (r.r_param4 or "- some place somewhere -") + if(not(coords)) then + minetest.chat_send_player(pname, "Sorry. There was an internal error with the ".. + "coordinates. Please inform whoever is responsible for this NPC.") + + return false + end + if(not(pname) or not(yl_speak_up.speak_to[pname])) then + return false + end + local dialog = yl_speak_up.speak_to[pname].dialog + minetest.chat_send_player(pname, + (dialog.n_npc or "- ? -")..": \"".. + tostring(town).."\" can be found at "..core.pos_to_string(coords, 0)..".") + if(minetest.get_modpath("waypoint_compass")) then + minetest.chat_send_player(pname, "If you have a waypoint compass, right-click ".. + "while wielding it. Select \"copy:\" to copy the location above into ".. + "your compass.") + end + -- the function was successful (effects only return true or false) + return true + end, +} diff --git a/addons/load_addons.lua b/addons/load_addons.lua index 68879aa..2fd9bc4 100644 --- a/addons/load_addons.lua +++ b/addons/load_addons.lua @@ -15,3 +15,6 @@ if(minetest.global_exists("mail") dofile(path_addons .. "action_send_mail.lua") dofile(path_addons .. "effect_send_mail.lua") end + +-- makes mostly sense if the waypoint_compass mod is installed +dofile(path_addons.."effect_send_coordinates.lua")