From 30e9ac02fb3282366a67e853c986fef24d2cfcd9 Mon Sep 17 00:00:00 2001 From: Xenon <36995016+xenonca@users.noreply.github.com> Date: Wed, 10 Mar 2021 05:53:11 +0100 Subject: [PATCH] Add /mr command (#824) * Add /mr command Add option to remove your placed marker * Change marker message --- mods/ctf/ctf_classes/melee.lua | 4 +-- mods/ctf/ctf_marker/init.lua | 49 +++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/mods/ctf/ctf_classes/melee.lua b/mods/ctf/ctf_classes/melee.lua index 1395bdd..9302904 100644 --- a/mods/ctf/ctf_classes/melee.lua +++ b/mods/ctf/ctf_classes/melee.lua @@ -89,7 +89,7 @@ minetest.register_tool("ctf_classes:sword_bronze", { if #enemies > 0 then ctf_marker.remove_marker(pteam) - ctf_marker.add_marker(pname, pteam, pos, ("[Enemies Found!: <%s>]"):format(table.concat(enemies, ", "))) + ctf_marker.add_marker(pname, pteam, pos, (" found enemies: <%s>]"):format(table.concat(enemies, ", "))) end return @@ -105,7 +105,7 @@ minetest.register_tool("ctf_classes:sword_bronze", { sword_special_timer[pname] = 20 sword_special_timer_func(pname, 20) - minetest.registered_chatcommands["m"].func(pname, "Marked with "..pname.."'s sword") + minetest.registered_chatcommands["m"].func(pname, "placed with sword") end, on_secondary_use = function(itemstack, user, pointed_thing) if pointed_thing then diff --git a/mods/ctf/ctf_marker/init.lua b/mods/ctf/ctf_marker/init.lua index ca2600a..9c9d348 100644 --- a/mods/ctf/ctf_marker/init.lua +++ b/mods/ctf/ctf_marker/init.lua @@ -47,7 +47,7 @@ function ctf_marker.add_marker(name, tname, pos, str) if tplayer then teams[tname].players[pname] = tplayer:hud_add({ hud_elem_type = "waypoint", - name = str, + name = "[" .. name .. "'s marker" .. str, number = tonumber(ctf.flag_colors[team.data.color]), world_pos = pos }) @@ -99,7 +99,7 @@ minetest.register_chatcommand("m", { local tname = ctf.player(name).team -- Handle waypoint string - local str = (param and param:trim() ~= "") and param or name .. "'s marker" + local str = (param and param:trim() ~= "") and ": " .. param or "" if pointed.type == "object" then local concat local obj = pointed.ref @@ -126,7 +126,7 @@ minetest.register_chatcommand("m", { end str = concat and str .. " <" .. concat .. ">" end - str = "[" .. str .. "]" + str = str .. "]" -- Remove existing marker if it exists ctf_marker.remove_marker(tname) @@ -134,3 +134,46 @@ minetest.register_chatcommand("m", { ctf_marker.add_marker(name, tname, minetest.get_pointed_thing_position(pointed), str) end }) + + +local function mr_command(name) + local tname = ctf.player(name).team + local player = minetest.get_player_by_name(name) + local mmsg = "" + local args = "" + + local function hud_check() + if teams[tname].players[name] then + mmsg = player:hud_get(teams[tname].players[name]).name + args = mmsg:split("'") + end + end + + if pcall(hud_check) then + if args[1] == "[" .. name then + ctf_marker.remove_marker(tname) + local team = ctf.team(tname) + for pname, _ in pairs(team.players) do + minetest.chat_send_player(pname, msg("* " .. name .. " removed their marker!")) + end + elseif args[1] == "" or nil then + minetest.chat_send_player(name, msg("No marker to remove")) + else + minetest.chat_send_player(name, msg("Not your marker!")) + end + else + minetest.chat_send_player(name, msg("No marker to remove")) + end +end + +minetest.register_chatcommand("m_remove", { + description = "Remove your own marker (/mr)", + privs = {interact = true}, + func = mr_command +}) + +minetest.register_chatcommand("mr", { + description = "Remove your own marker", + privs = {interact = true}, + func = mr_command +})