-
Notifications
You must be signed in to change notification settings - Fork 3
/
shadow.lua
42 lines (39 loc) · 1.34 KB
/
shadow.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
--
-- Minetest player cloaking mod
--
-- Copyright © 2021 by luk3yx
--
minetest.register_chatcommand('shadow', {
privs = {cloaking = true, teleport = true},
description = 'Attaches you to a player. If `victim` is not specified, ' ..
'this command will detach you instead.',
params = '[victim]',
func = function(name, param)
if not cloaking.is_cloaked(name) then
return false, 'You must be cloaked to use /shadow!'
elseif name == param then
return false, 'You cannot shadow yourself!'
end
local player = cloaking.get_player_by_name(name)
if param == '' then
player:set_detach()
return true, 'You are free to move normally.'
end
local victim = cloaking.get_player_by_name(param)
if not victim then
return false, ('Invalid player %q.'):format(param)
end
player:set_attach(victim, '', {x=0, y=0, z=0}, {x=0, y=0, z=0})
return true, ('You are now shadowing %q.'):format(param)
end
})
-- Detach on uncloak
minetest.register_on_joinplayer(function(player)
if not minetest.check_player_privs(player, "cloaking", "teleport") then
return
end
local parent = player:get_attach()
if minetest.is_player(parent) and parent:is_player() then
player:set_detach()
end
end)