2018-04-01 08:31:55 +02:00
|
|
|
--
|
|
|
|
-- Minetest cloaking mod: chatcommands
|
|
|
|
--
|
2019-02-10 01:49:56 +01:00
|
|
|
-- © 2019 by luk3yx
|
2018-04-01 08:31:55 +02:00
|
|
|
--
|
|
|
|
|
2018-10-09 00:45:22 +02:00
|
|
|
minetest.register_privilege('cloaking',
|
|
|
|
'Allows players to cloak and uncloak any in-game player.')
|
|
|
|
|
2018-04-01 08:31:55 +02:00
|
|
|
minetest.register_chatcommand("cloak", {
|
|
|
|
params = "[victim]",
|
|
|
|
description = "Cloak a player so they are not visible.",
|
2018-10-09 00:45:22 +02:00
|
|
|
privs = {cloaking = true},
|
|
|
|
_allow_while_cloaked = true,
|
2018-04-01 08:31:55 +02:00
|
|
|
func = function(player, victim)
|
|
|
|
if not victim or victim == '' then
|
|
|
|
victim = player
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2018-07-25 21:29:19 +02:00
|
|
|
local p = cloaking.get_player_by_name(victim)
|
2018-04-01 08:31:55 +02:00
|
|
|
if not p then
|
|
|
|
return false, "Could not find a player with the name '" .. victim .. "'!"
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2018-04-01 08:31:55 +02:00
|
|
|
if cloaking.is_cloaked(victim) then
|
|
|
|
return false, victim .. " is already cloaked!"
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2019-02-10 01:49:56 +01:00
|
|
|
minetest.log('action', player .. ' cloaks ' .. victim .. '.')
|
2018-04-01 08:31:55 +02:00
|
|
|
cloaking.cloak(p)
|
|
|
|
return true, "Cloaked!"
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("uncloak", {
|
|
|
|
params = "[victim]",
|
|
|
|
description = "Uncloak a player so they are visible.",
|
2018-10-09 00:45:22 +02:00
|
|
|
_allow_while_cloaked = true,
|
2018-04-01 08:31:55 +02:00
|
|
|
func = function(player, victim)
|
|
|
|
if not victim or victim == '' then
|
|
|
|
victim = player
|
2018-10-09 00:45:22 +02:00
|
|
|
elseif not minetest.get_player_privs(player).cloaking then
|
2018-04-01 08:31:55 +02:00
|
|
|
return false, "You don't have permission to uncloak someone else."
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2019-02-10 01:49:56 +01:00
|
|
|
|
2018-04-01 08:31:55 +02:00
|
|
|
if victim == '*' then
|
2019-02-10 01:49:56 +01:00
|
|
|
minetest.log('action', player .. ' uncloaks everyone.')
|
2018-04-01 08:31:55 +02:00
|
|
|
for _, player in ipairs(cloaking.get_cloaked_players()) do
|
|
|
|
cloaking.uncloak(player)
|
|
|
|
end
|
|
|
|
return true, "Uncloaked everyone!"
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2019-02-10 01:49:56 +01:00
|
|
|
local p = cloaking.get_player_by_name(victim)
|
2018-04-01 08:31:55 +02:00
|
|
|
if not p then
|
|
|
|
return false, "Could not find a player with the name '" .. victim .. "'!"
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2018-04-01 08:31:55 +02:00
|
|
|
if not cloaking.is_cloaked(victim) then
|
|
|
|
return false, victim .. " is not cloaked!"
|
|
|
|
end
|
2018-09-14 06:30:17 +02:00
|
|
|
|
2019-02-10 01:49:56 +01:00
|
|
|
minetest.log('action', player .. ' uncloaks ' .. victim .. '.')
|
2018-04-01 08:31:55 +02:00
|
|
|
cloaking.uncloak(p)
|
|
|
|
return true, "Uncloaked!"
|
|
|
|
end
|
|
|
|
})
|
2019-02-10 01:49:56 +01:00
|
|
|
|
|
|
|
-- Allow /teleport to be used on cloaked players if you have the "cloaking"
|
|
|
|
-- privilege.
|
|
|
|
local tp = minetest.registered_chatcommands['teleport'].func
|
|
|
|
minetest.override_chatcommand('teleport', {
|
|
|
|
func = function(name, param)
|
|
|
|
if minetest.check_player_privs(name, 'cloaking') then
|
|
|
|
local g = minetest.get_player_by_name
|
|
|
|
minetest.get_player_by_name = cloaking.get_player_by_name
|
|
|
|
|
|
|
|
local err, msg = tp(name, param)
|
|
|
|
|
|
|
|
minetest.get_player_by_name = g
|
|
|
|
return err, msg
|
|
|
|
else
|
|
|
|
return tp(name, param)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|