From 2022c6260dbfcda8c029e69a076c89d8db41d11a Mon Sep 17 00:00:00 2001 From: luk3yx Date: Thu, 13 Feb 2020 18:16:21 +1300 Subject: [PATCH] Add /clrmrkr. --- init.lua | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index d85c7ee..40bd269 100644 --- a/init.lua +++ b/init.lua @@ -66,11 +66,11 @@ function advmarkers.set_hud_pos(player, pos, title) if not title then title = pos.x .. ', ' .. pos.y .. ', ' .. pos.z end - if hud[player] then - player:hud_change(hud[player], 'name', title) - player:hud_change(hud[player], 'world_pos', pos) + if hud[name] then + player:hud_change(hud[name], 'name', title) + player:hud_change(hud[name], 'world_pos', pos) else - hud[player] = player:hud_add({ + hud[name] = player:hud_add({ hud_elem_type = 'waypoint', name = title, text = 'm', @@ -78,7 +78,8 @@ function advmarkers.set_hud_pos(player, pos, title) world_pos = pos }) end - minetest.chat_send_player(name, 'Waypoint set to ' .. title) + minetest.chat_send_player(name, 'Waypoint set to ' .. + minetest.colorize('#bf360c', title)) return true end @@ -542,11 +543,11 @@ end -- Clean up variables if a player leaves minetest.register_on_leaveplayer(function(player) - local name = get_player(player, 0) - hud[name] = nil - formspec_list[name] = nil - selected_name[name] = nil - advmarkers.last_coords[name] = nil + local name = player:get_player_name() + hud[name] = nil + formspec_list[name] = nil + selected_name[name] = nil + advmarkers.last_coords[name] = nil end) -- Add '/mrkrthere' @@ -558,6 +559,23 @@ minetest.register_chatcommand('mrkrthere', { end }) +minetest.register_chatcommand('clrmrkr', { + params = '', + description = 'Hides the displayed waypoint.', + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not hud[name] or not player then + return false, 'No waypoint is currently being displayed!' .. dump(hud) + end + player:hud_remove(hud[name]) + hud[name] = nil + return true, 'Hidden the currently displayed waypoint.' + end, +}) + +register_chatcommand_alias('clrmrkr', 'clear_marker', 'clrwp', + 'clear_waypoint') + -- SSCSM support if minetest.global_exists('sscsm') and sscsm.register then sscsm.register({