Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow detection of cloaking and uncloaking in leaveplayer and joinplayer callbacks #10

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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