2015-12-08 07:28:41 -08:00
|
|
|
local original_pos = {}
|
|
|
|
|
|
|
|
minetest.register_privilege("watch", "Player can watch other players")
|
|
|
|
|
2015-12-22 07:49:07 -08:00
|
|
|
local function unwatching(name)
|
2015-12-25 05:35:06 -08:00
|
|
|
local watcher = minetest.get_player_by_name(name)
|
2015-12-22 07:49:07 -08:00
|
|
|
local privs = minetest.get_player_privs(name)
|
|
|
|
|
|
|
|
if watcher and default.player_attached[name] == true then
|
|
|
|
watcher:set_detach()
|
|
|
|
default.player_attached[name] = false
|
2015-12-25 05:35:06 -08:00
|
|
|
watcher:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
2015-12-22 07:49:07 -08:00
|
|
|
watcher:set_nametag_attributes({color = {a=255, r=255, g=255, b=255}})
|
|
|
|
|
|
|
|
watcher:hud_set_flags({
|
|
|
|
healthbar = true,
|
2015-12-25 05:35:06 -08:00
|
|
|
minimap = true,
|
|
|
|
breathbar = true,
|
|
|
|
hotbar = true,
|
|
|
|
wielditem = true,
|
|
|
|
crosshair = true
|
2015-12-22 07:49:07 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
watcher:set_properties({
|
|
|
|
visual_size = {x=1, y=1},
|
|
|
|
makes_footstep_sound = true,
|
|
|
|
collisionbox = {-0.3, -1, -0.3, 0.3, 1, 0.3}
|
|
|
|
})
|
|
|
|
|
|
|
|
if not privs.interact and privs.watch == true then
|
|
|
|
privs.interact = true
|
|
|
|
minetest.set_player_privs(name, privs)
|
|
|
|
end
|
|
|
|
|
2016-08-05 10:51:05 -07:00
|
|
|
local pos = original_pos[watcher]
|
|
|
|
if pos then
|
|
|
|
-- setpos seems to be very unreliable
|
|
|
|
-- this workaround helps though
|
2015-12-22 07:49:07 -08:00
|
|
|
minetest.after(0.1, function()
|
2016-08-05 10:51:05 -07:00
|
|
|
watcher:setpos(pos)
|
2015-12-22 07:49:07 -08:00
|
|
|
end)
|
2016-08-05 10:51:05 -07:00
|
|
|
original_pos[watcher] = nil
|
2015-12-22 07:49:07 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-08 07:28:41 -08:00
|
|
|
minetest.register_chatcommand("watch", {
|
|
|
|
params = "<to_name>",
|
|
|
|
description = "watch a given player",
|
|
|
|
privs = {watch=true},
|
|
|
|
func = function(name, param)
|
2015-12-25 05:35:06 -08:00
|
|
|
local watcher = minetest.get_player_by_name(name)
|
2016-01-02 08:20:50 -08:00
|
|
|
local target = minetest.get_player_by_name(param)
|
2015-12-08 09:39:06 -08:00
|
|
|
local privs = minetest.get_player_privs(name)
|
2015-12-08 07:28:41 -08:00
|
|
|
|
2015-12-22 07:49:07 -08:00
|
|
|
if target and watcher ~= target then
|
|
|
|
if default.player_attached[name] == true then
|
|
|
|
unwatching(param)
|
|
|
|
else
|
|
|
|
original_pos[watcher] = watcher:getpos()
|
|
|
|
end
|
2017-03-08 21:20:27 -08:00
|
|
|
|
2015-12-08 07:28:41 -08:00
|
|
|
default.player_attached[name] = true
|
2015-12-25 05:35:06 -08:00
|
|
|
watcher:set_attach(target, "", {x=0, y=-5, z=-20}, {x=0, y=0, z=0})
|
|
|
|
watcher:set_eye_offset({x=0, y=-5, z=-20}, {x=0, y=0, z=0})
|
2015-12-08 07:36:45 -08:00
|
|
|
watcher:set_nametag_attributes({color = {a=0}})
|
2015-12-08 07:28:41 -08:00
|
|
|
|
|
|
|
watcher:hud_set_flags({
|
2015-12-08 13:02:19 -08:00
|
|
|
healthbar = false,
|
2015-12-25 05:35:06 -08:00
|
|
|
minimap = false,
|
|
|
|
breathbar = false,
|
|
|
|
hotbar = false,
|
|
|
|
wielditem = false,
|
|
|
|
crosshair = false
|
2015-12-08 07:28:41 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
watcher:set_properties({
|
|
|
|
visual_size = {x=0, y=0},
|
|
|
|
makes_footstep_sound = false,
|
2015-12-25 05:35:06 -08:00
|
|
|
collisionbox = {0}
|
2015-12-08 07:28:41 -08:00
|
|
|
})
|
|
|
|
|
2015-12-08 09:39:06 -08:00
|
|
|
privs.interact = nil
|
|
|
|
minetest.set_player_privs(name, privs)
|
|
|
|
|
2015-12-10 02:28:13 -08:00
|
|
|
return true, "Watching '"..param.."' at "..minetest.pos_to_string(vector.round(target:getpos()))
|
2015-12-08 07:28:41 -08:00
|
|
|
end
|
|
|
|
|
2015-12-22 07:49:07 -08:00
|
|
|
return false, "Invalid parameter ('"..param.."')."
|
2015-12-08 07:28:41 -08:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2015-12-08 13:02:19 -08:00
|
|
|
minetest.register_chatcommand("unwatch", {
|
|
|
|
description = "unwatch a player",
|
|
|
|
privs = {watch=true},
|
2017-03-08 21:20:27 -08:00
|
|
|
func = function(name, param)
|
2015-12-08 13:02:19 -08:00
|
|
|
unwatching(name)
|
2015-12-08 07:28:41 -08:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2015-12-08 09:39:06 -08:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2015-12-08 13:02:19 -08:00
|
|
|
unwatching(name)
|
2015-12-08 09:39:06 -08:00
|
|
|
end)
|