Allow detection of cloaking and uncloaking in leaveplayer and joinplayer callbacks (#10)
This commit is contained in:
parent
80fad7a2db
commit
88efcda38d
15
core.lua
15
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
|
||||
|
|
Loading…
Reference in New Issue