Skip to content

Commit

Permalink
Allow detection of cloaking and uncloaking in leaveplayer and joinpla…
Browse files Browse the repository at this point in the history
…yer callbacks (#10)
  • Loading branch information
oversword authored Jul 22, 2024
1 parent 80fad7a commit 88efcda
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88efcda

Please sign in to comment.