From 88efcda38d66ea5fce1f2852632b8b46abd9b5ae Mon Sep 17 00:00:00 2001 From: Oversword Date: Mon, 22 Jul 2024 21:23:55 +0100 Subject: [PATCH] Allow detection of cloaking and uncloaking in leaveplayer and joinplayer callbacks (#10) --- core.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core.lua b/core.lua index 35b8adf..486cddd 100644 --- a/core.lua +++ b/core.lua @@ -14,6 +14,8 @@ cloaking.get_objects_in_area = minetest.get_objects_in_area cloaking.get_server_status = minetest.get_server_status local cloaked_players = {} +local cloaking_players = {} +local uncloaking_players = {} local chatcommands_modified = false -- Override built-in functions @@ -261,11 +263,13 @@ function cloaking.cloak(player_or_name) t = areas.hud[victim] end + cloaking_players[victim] = true for _, f in ipairs(minetest.registered_on_leaveplayers) do if f ~= delayed_uncloak then f(player, false, 'cloaking') end end + cloaking_players[victim] = nil cloaked_players[victim] = true @@ -299,9 +303,11 @@ function cloaking.uncloak(player_or_name) minetest.chat_send_all("*** " .. victim .. " joined the game.") end + uncloaking_players[victim] = true for _, f in ipairs(minetest.registered_on_joinplayers) do f(player) end + uncloaking_players[victim] = nil minetest.log('verbose', victim .. ' was uncloaked.') end @@ -382,6 +388,15 @@ function cloaking.is_cloaked(player) return cloaked_players[player] and true or false end +function cloaking.is_cloaking(player) + if type(player) ~= "string" then player = player:get_player_name() end + return cloaking_players[player] and true or false +end +function cloaking.is_uncloaking(player) + if type(player) ~= "string" then player = player:get_player_name() end + return uncloaking_players[player] and true or false +end + -- Prevent cloaked players dying minetest.register_on_player_hpchange(function(player, hp_change) if player and hp_change < 0 then