2018-04-01 05:11:07 +02:00
|
|
|
--
|
|
|
|
-- Minetest player cloaking mod
|
|
|
|
--
|
|
|
|
-- © 2018 by luk3yx
|
|
|
|
--
|
|
|
|
|
|
|
|
cloaking = {}
|
|
|
|
|
2018-04-01 05:51:30 +02:00
|
|
|
-- Expose the real get_connected_players and get_player_by_name for mods that
|
|
|
|
-- can use them.
|
|
|
|
cloaking.get_connected_players = minetest.get_connected_players
|
|
|
|
cloaking.get_player_by_name = minetest.get_player_by_name
|
|
|
|
|
2018-04-01 05:11:07 +02:00
|
|
|
local cloaked_players = {}
|
|
|
|
|
2018-04-01 06:06:23 +02:00
|
|
|
-- Override built-in functions
|
2018-04-01 05:11:07 +02:00
|
|
|
minetest.get_connected_players = function()
|
|
|
|
local a = {}
|
2018-04-01 05:51:30 +02:00
|
|
|
for _, player in ipairs(cloaking.get_connected_players()) do
|
2018-04-01 05:11:07 +02:00
|
|
|
if not cloaked_players[player:get_player_name()] then
|
|
|
|
table.insert(a, player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return a
|
|
|
|
end
|
|
|
|
|
2018-04-01 05:51:30 +02:00
|
|
|
minetest.get_player_by_name = function(player)
|
|
|
|
if cloaked_players[player] then
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return cloaking.get_player_by_name(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-01 06:06:23 +02:00
|
|
|
-- Override chatcommands
|
|
|
|
minetest.register_chatcommand("status", {
|
|
|
|
description = "Print server status",
|
|
|
|
func = function(name, param)
|
|
|
|
local status = minetest.get_server_status()
|
|
|
|
status = status:sub(1, status:find('{', 1, true))
|
|
|
|
local players = {}
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
|
|
|
table.insert(players, player:get_player_name())
|
|
|
|
end
|
|
|
|
players = table.concat(players, ', ')
|
|
|
|
status = status .. players .. '}'
|
|
|
|
return true, status
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
-- The cloak and uncloak functions
|
2018-04-01 05:11:07 +02:00
|
|
|
cloaking.cloak_player = function(player)
|
|
|
|
if type(player) == "string" then
|
2018-04-01 05:51:30 +02:00
|
|
|
player = cloaking.get_player_by_name(player)
|
2018-04-01 05:11:07 +02:00
|
|
|
end
|
|
|
|
victim = player:get_player_name()
|
|
|
|
|
|
|
|
player:set_properties({visual_size = {x = 0, y = 0}, collisionbox = {0,0,0,0,0,0}})
|
|
|
|
p:set_nametag_attributes({text = " "})
|
|
|
|
|
|
|
|
cloaked_players[victim] = true
|
|
|
|
|
|
|
|
minetest.chat_send_all("*** " .. victim .. " left the game")
|
|
|
|
if irc then
|
|
|
|
irc.say("*** " .. victim .. " left the game")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
cloaking.uncloak_player = function(player)
|
|
|
|
if type(player) == "string" then
|
2018-04-01 05:51:30 +02:00
|
|
|
player = cloaking.get_player_by_name(player)
|
2018-04-01 05:11:07 +02:00
|
|
|
end
|
|
|
|
victim = player:get_player_name()
|
|
|
|
|
|
|
|
player:set_properties({visual_size = {x = 1, y = 1}, collisionbox = {-0.25,-0.85,-0.25,0.25,0.85,0.25}})
|
|
|
|
p:set_nametag_attributes({text = victim})
|
|
|
|
|
|
|
|
cloaked_players[victim] = false
|
|
|
|
|
|
|
|
minetest.chat_send_all("*** " .. victim .. " joined the game")
|
|
|
|
if irc then
|
|
|
|
irc.say("*** " .. victim .. " joined the game")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-01 06:06:23 +02:00
|
|
|
-- Auto-uncloak on chat message
|
2018-04-01 05:40:31 +02:00
|
|
|
minetest.register_on_chat_message(function(name, message)
|
|
|
|
if cloaked_players[name] then
|
|
|
|
cloaking.uncloak_player(name)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2018-04-01 06:06:23 +02:00
|
|
|
-- The /cloak and /uncloak commands
|
2018-04-01 05:11:07 +02:00
|
|
|
minetest.register_chatcommand("cloak", {
|
|
|
|
params = "[victim]",
|
|
|
|
description = "Cloak a player so they are not visible.",
|
|
|
|
privs = {privs = true},
|
|
|
|
func = function(player, victim)
|
|
|
|
if not victim or victim == '' then
|
|
|
|
victim = player
|
|
|
|
end
|
|
|
|
|
2018-04-01 05:51:30 +02:00
|
|
|
p = cloaking.get_player_by_name(victim)
|
2018-04-01 05:11:07 +02:00
|
|
|
if not p then
|
|
|
|
return false, "Could not find a player with the name '" .. victim .. "'!"
|
|
|
|
end
|
|
|
|
|
|
|
|
if cloaked_players[victim] then
|
|
|
|
return false, victim .. " is already cloaked!"
|
|
|
|
end
|
|
|
|
|
|
|
|
cloaking.cloak_player(p)
|
|
|
|
return true, "Cloaked!"
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("uncloak", {
|
|
|
|
params = "[victim]",
|
|
|
|
description = "Uncloak a player so they are visible.",
|
|
|
|
func = function(player, victim)
|
|
|
|
if not victim or victim == '' then
|
|
|
|
victim = player
|
2018-04-01 05:40:31 +02:00
|
|
|
elseif not minetest.get_player_privs(player).privs then
|
|
|
|
return false, "You don't have permission to uncloak someone else."
|
2018-04-01 05:11:07 +02:00
|
|
|
end
|
|
|
|
|
2018-04-01 05:51:30 +02:00
|
|
|
p = cloaking.get_player_by_name(victim)
|
2018-04-01 05:11:07 +02:00
|
|
|
if not p then
|
|
|
|
return false, "Could not find a player with the name '" .. victim .. "'!"
|
|
|
|
end
|
|
|
|
|
|
|
|
if not cloaked_players[victim] then
|
|
|
|
return false, victim .. " is not cloaked!"
|
|
|
|
end
|
|
|
|
|
|
|
|
cloaking.uncloak_player(p)
|
|
|
|
return true, "Uncloaked!"
|
|
|
|
end
|
|
|
|
})
|